celestiaorg / celestia-node

Celestia Data Availability Nodes
Apache License 2.0
933 stars 928 forks source link

feat(api): Introduce Error Codes for Node RPC #3529

Open walldiss opened 5 months ago

walldiss commented 5 months ago

Implementation ideas

The JSON-RPC specification mandates the return of an error object with specific codes for failed requests (see JSON-RPC Error Specification). Our current node API implementation only provides data or a generic error message, omitting these specific error codes. As we continue to develop a comprehensive canonical API that will address this in the future, we can start improving our existing API by introducing error codes for common error scenarios. Initially, we don’t need a full set of refined error codes; we can implement a basic set and expand and refine these codes gradually based on user feedback and system requirements.

To streamline this process, we should establish an infrastructure to wrap all errors in a generic "Internal error" code, which can later be detailed into more specific codes as we refine our error handling strategy. This initial step will help standardize our error responses and make them more predictable for API users.

Implementation ideas

Node may utilise go-jsonrpc existing functionality for error codes, by providing global map of error codes to server and client via WithErrors option: https://github.com/filecoin-project/go-jsonrpc/blob/e75dcdc8133848b9b60335d5779e3af1ac3cb447/options.go#L88 It will allow go clients to use golang native errors.Is call to identify which error is returned. Other language clients would need to parse error code from response json object and map it to proper error value.

Some basic error codes that were requested include:

Adding error codes will enhance error traceability and debugging, making our API more robust and user-friendly in the interim period before the canonical API rollout.

liamsi commented 1 month ago

related comment: https://github.com/celestiaorg/celestia-node/issues/3335#issuecomment-2079748320