chore: replace hardcoded error codes with rpc error constants#376
Open
chore: replace hardcoded error codes with rpc error constants#376
Conversation
| } catch { | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Motivation and Context
Jira Link:
Description
How has this been tested?
Screenshots (if appropriate):
Types of changes
Checklist:
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
-32603usages witherrorCodes.rpc.*constants increateErrorMiddlewareandJRPCEngine, and improves fallback error construction by validating/parsing numeric error codes via a newisValidNumberhelper.Tightens request validation semantics: non-object requests, missing/empty
method, and empty batch requests now returnerrorCodes.rpc.invalidRequestwith clearer messages (including a defined response for empty batches), and addsvitestcoverage for these validation cases.Written by Cursor Bugbot for commit ee219ea. This will update automatically on new commits. Configure here.