Skip to content

cln-plugin: use -32603 for handler errors and guarantee integer error.code - #9762

Open
daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-fix-rpc-error-code
Open

daywalker90 wants to merge 1 commit into
ElementsProject:masterfrom
daywalker90:cln-plugin-fix-rpc-error-code

Conversation

@daywalker90

Copy link
Copy Markdown
Collaborator

parse_error defaulted to -32700 (JSON-RPC 2.0 Parse error) for all handler errors and panics instead of -32603 (Internal error), and RpcError had code: Option<i32>, allowing JSON-formatted errors with a missing or null code (e.g. a forwarded cln_rpc::RpcError with code: None) to serialize "code": null, which violates JSON-RPC 2.0 and is rejected by lightningd on setconfig.

Change RpcError.code to i32, keep -32700 in JsonCodec for actual JSON parse failures, use -32603 (JSONRPC_INTERNAL_ERROR) as the default in parse_error, and deserialize via a local RawRpcError with code: Option<i32> so JSON error payloads without a code still avoid over-escaping while defaulting to -32603.

Update parse_error_includes_full_anyhow_chain and add unit tests for explicit codes and missing/null codes.

Changelog-Changed: cln-plugin: use JSON-RPC error code -32603 (Internal error) instead of -32700 (Parse error) for plugin handler errors, and never emit "code": null.

…ror.code`

`parse_error` defaulted to `-32700` (JSON-RPC 2.0 *Parse error*) for all
handler errors and panics instead of `-32603` (*Internal error*), and
`RpcError` had `code: Option<i32>`, allowing JSON-formatted errors with
a missing or `null` `code` (e.g. a forwarded `cln_rpc::RpcError` with
`code: None`) to serialize `"code": null`, which violates JSON-RPC 2.0
and is rejected by `lightningd` on `setconfig`.

Change `RpcError.code` to `i32`, keep `-32700` in `JsonCodec` for actual
JSON parse failures, use `-32603` (`JSONRPC_INTERNAL_ERROR`) as the
default in `parse_error`, and deserialize via a local `RawRpcError` with
`code: Option<i32>` so JSON error payloads without a code still avoid
over-escaping while defaulting to `-32603`.

Update `parse_error_includes_full_anyhow_chain` and add unit tests for
explicit codes and missing/`null` codes.

Changelog-Changed: cln-plugin: use JSON-RPC error code `-32603` (Internal error) instead of `-32700` (Parse error) for plugin handler errors, and never emit `"code": null`.
@daywalker90
daywalker90 requested a review from cdecker as a code owner November 24, 2026 15:48

This branch has not been deployed

No deployments
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.

1 participant