Skip to content

Conversation

@hxrshxz
Copy link

@hxrshxz hxrshxz commented Dec 20, 2025

Change Description

Enable the RPC middleware API to return "rich" gRPC errors with full error details including gRPC error codes (fixes #6729).

Previously, errors intercepted by the RPC middleware were always serialized as plain error strings. This meant middleware could only see

Steps to Test

  1. Run the rpcperms package tests:
go test -v ./rpcperms/...
  1. Build the project to verify no regressions:
go build ./...

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.

Code Style and Documentation

  • The change is not insubstantial.
  • The change obeys the Code Documentation and Commenting guidelines, and lines wrap at 80.
  • Commits follow the Ideal Git Commit Structure.
  • No new logging statements (change only affects internal error handling).
  • No new lncli commands (RPC middleware API enhancement only).
  • This is a small enhancement; marked with [skip ci] not needed as tests are included.

📝 Please see our Contribution Guidelines for further guidance.

Copilot AI review requested due to automatic review settings December 20, 2025 14:44
@gemini-code-assist
Copy link

Summary of Changes

Hello @hxrshxz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly upgrades the RPC middleware API by enabling it to process and return "rich" gRPC status errors. Previously, the middleware could only handle errors as simple strings, losing valuable context like gRPC error codes. With this enhancement, the system can now serialize and deserialize full google.rpc.Status protobuf messages, providing a more robust and detailed error handling mechanism for intercepted RPC calls.

Highlights

  • Rich gRPC Error Support: The RPC middleware API now supports "rich" gRPC errors, including full error details and gRPC error codes, addressing issue rpc: enable the RPC middleware API to return "rich" errors  #6729.
  • Enhanced Error Serialization: Errors intercepted by the middleware are no longer limited to plain error strings; they can now be serialized as google.rpc.Status protos, preserving detailed error information.
  • Improved Error Handling: This change allows middleware to inspect and modify complete error information, providing a more robust and flexible error handling mechanism within the RPC system.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances the RPC middleware API to support rich gRPC status errors, allowing middleware to inspect and modify errors with full details, including gRPC error codes. Previously, errors were just plain strings. The changes involve differentiating between plain errors and gRPC status errors during serialization for interception, and then correctly parsing them back when a replacement is provided by the middleware. New tests have been added to cover this new functionality. The implementation is solid, but there's a critical issue with a missing import alias that will prevent the code from compiling.

"github.com/btcsuite/btcd/chaincfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"google.golang.org/genproto/googleapis/rpc/status"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The package google.golang.org/genproto/googleapis/rpc/status is imported without an alias, but its types are later referenced with the spb prefix (e.g., spb.Status on line 637), which is not defined. This will cause a compilation error. Please add an alias to the import to resolve this.

Suggested change
"google.golang.org/genproto/googleapis/rpc/status"
spb "google.golang.org/genproto/googleapis/rpc/status"

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the RPC middleware API to support rich gRPC status errors with full error details including gRPC error codes, addressing issue #6729. Previously, errors intercepted by middleware were always serialized as plain strings, losing important error code information.

Key changes:

  • Added support for serializing and deserializing gRPC status errors as google.rpc.Status proto messages
  • Introduced new constants to distinguish between plain error strings and rich gRPC status errors
  • Updated error handling logic to preserve gRPC error codes throughout the middleware pipeline

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
rpcperms/middleware_handler.go Implements the core functionality to serialize/deserialize gRPC status errors, adds constants for error type names, and introduces the parseErrorReplacement function to handle both plain and rich errors
rpcperms/middleware_handler_test.go Adds comprehensive test coverage for the new error handling functionality, including tests for plain errors, gRPC status errors with different codes, and error parsing edge cases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"github.com/btcsuite/btcd/chaincfg"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/macaroons"
"google.golang.org/genproto/googleapis/rpc/status"
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a naming conflict with two imports both named "status". Line 15 imports "google.golang.org/genproto/googleapis/rpc/status" and line 17 imports "google.golang.org/grpc/status", but neither has an alias. This will cause a compilation error. Additionally, line 637 references spb.Status{} but there's no import with the alias "spb". The genproto import should be aliased (e.g., as "spb") to resolve both issues.

Suggested change
"google.golang.org/genproto/googleapis/rpc/status"
spb "google.golang.org/genproto/googleapis/rpc/status"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rpc: enable the RPC middleware API to return "rich" errors

1 participant