Skip to content

chore: replace hardcoded error codes with rpc error constants#376

Open
lwin-kyaw wants to merge 3 commits intomasterfrom
fix/jrpc-errors
Open

chore: replace hardcoded error codes with rpc error constants#376
lwin-kyaw wants to merge 3 commits intomasterfrom
fix/jrpc-errors

Conversation

@lwin-kyaw
Copy link

@lwin-kyaw lwin-kyaw commented Feb 5, 2026

Motivation and Context

Jira Link:

Description

How has this been tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project. (run lint)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code requires a db migration.

Note

Medium Risk
Changes request-validation behavior and error codes/messages in the JSON-RPC engine, which may affect clients that rely on previous error semantics. Added tests reduce regression risk but batch/validation edge cases should be rechecked in downstream integrations.

Overview
Standardizes JSON-RPC error handling by replacing hardcoded -32603 usages with errorCodes.rpc.* constants in createErrorMiddleware and JRPCEngine, and improves fallback error construction by validating/parsing numeric error codes via a new isValidNumber helper.

Tightens request validation semantics: non-object requests, missing/empty method, and empty batch requests now return errorCodes.rpc.invalidRequest with clearer messages (including a defined response for empty batches), and adds vitest coverage for these validation cases.

Written by Cursor Bugbot for commit ee219ea. This will update automatically on new commits. Configure here.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

} catch {
return false;
}
}
Copy link

Choose a reason for hiding this comment

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

Empty string produces NaN error code instead of fallback

Medium Severity

The isValidNumber function uses Number() for validation, which treats empty strings and whitespace-only strings as 0. However, the calling code in constructFallbackError uses parseInt() for the actual conversion, which returns NaN for these same inputs. When code is an empty string, isValidNumber("") returns true (since Number("") is 0), but parseInt("") returns NaN, resulting in NaN being used as the error code instead of the fallback value.

Additional Locations (1)

Fix in Cursor Fix in Web

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