Skip to content

Forward error code #3383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged

Forward error code #3383

merged 3 commits into from
Apr 16, 2025

Conversation

wli-pro
Copy link
Contributor

@wli-pro wli-pro commented Apr 14, 2025

Context

Labels

Please apply following PR-related labels when appropriate:

  • C0-breaking: if your change could break the existing client, e.g. API change, critical logic change
  • C1-noteworthy: if your change is non-breaking, but is still worth noticing for the client, e.g. reference code improvement

How (Optional)

Testing Evidences

Please attach any relevant evidences if applicable

let internal_error: ErrorObject = ErrorCode::InternalError.into();
let params = params.parse::<AddWalletParams>()?;
let params = params.parse::<AddWalletParams>().map_err(|_| {
log::error!("Failed to parse params");
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't make sense to log reason here (e) ?


pub fn from_error_code(error_code: ErrorCode) -> Self {
let (code, message) = match error_code {
ErrorCode::ParseError => (-32700, "Parse error"),
Copy link
Member

Choose a reason for hiding this comment

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

These messages are all in english while the ones returned from pumpx backend will be i18 , is that correct ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Here is jsonrpsee internal error code. It's fine.

Copy link
Collaborator

@Kailai-Wang Kailai-Wang left a comment

Choose a reason for hiding this comment

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

I actually like this refactoring 👍

Would fields of all ..ResponseData need to be in Option? As in error case they would be empty.

@BillyWooo
Copy link
Collaborator

I actually like this refactoring 👍

Would fields of all ..ResponseData need to be in Option? As in error case they would be empty.

Yes. They all should be Option.
@wli-pro can you update all of them? and also resolve the conflicts. Besides, there is one more new RPC pumpx_getOmniAccount added.

{
if response.code != 10000 {
log::error!("{} failed: code={}, message={}", name, response.code, response.message);
return Err(PumpxRpcError::from_code_and_message(response.code as i32, response.message));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it mean if we detect errors from pump-api response, we'll use their code and msg as our response and return it to F/E?

Could that be problematic for F/E to tell if the error actually comes from worker or backend? Especially when the error code happens to coincide.

Would this makes more sense? Like

{
  "code": -32055, // just as example
  "message": "Pumpx API error",
  "error": {
    "backend_response": { // the raw backend response
       "code": -12345,
       "message": ...,
       "data": {}
     }
  }
}

So here -32055 means we return because backend returns error - so we propagate it

Self { code, message }
}

pub fn from_error_code(error_code: ErrorCode) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about to have:

pub fn from_error_code(error_code: ErrorCode) -> Self {
Self { code: error_code.code(), message: error_code.message().to_string() }
}

@wli-pro
Copy link
Contributor Author

wli-pro commented Apr 15, 2025

I actually like this refactoring 👍
Would fields of all ..ResponseData need to be in Option? As in error case they would be empty.

Yes. They all should be Option. @wli-pro can you update all of them? and also resolve the conflicts. Besides, there is one more new RPC pumpx_getOmniAccount added.

As all ResponseData should be Option, I think there is no need to make any changes, as the response of jsonrpc already has a different response structure for success and error.

Success response example like below

{
	"jsonrpc": "2.0",
	"id": 1,
    "result": {
       "backend_response": {}
     }
}

Error response example like below

{
	"jsonrpc": "2.0",
	"id": 1,
	"error": {
		"code": -32700,
		"message": "Parse error"
	}
}

@wli-pro wli-pro force-pushed the forward-error-code branch 2 times, most recently from 3b8b651 to 19a50df Compare April 16, 2025 03:54
@wli-pro wli-pro requested a review from BillyWooo April 16, 2025 04:26
BillyWooo and others added 3 commits April 16, 2025 19:19
…ract duplicated code into new function, add more logs
…return backend_response, add some error info to log
@wli-pro wli-pro force-pushed the forward-error-code branch from 19a50df to 57bd447 Compare April 16, 2025 09:19
@wli-pro wli-pro enabled auto-merge (squash) April 16, 2025 09:19
@wli-pro wli-pro merged commit d2fb595 into dev Apr 16, 2025
21 checks passed
@wli-pro wli-pro deleted the forward-error-code branch April 16, 2025 09:47
silva-fj pushed a commit that referenced this pull request Apr 16, 2025
* first prototype

* feat: add struct PumpxRpcError for error processing in pumpx rpc, extract duplicated code into new function, add more logs

* fix: update data of ApiResponse to Optional, update PumpxRpcError to return backend_response, add some error info to log

---------

Co-authored-by: BillyWooo <yang@trustcomputing.de>
Co-authored-by: wli-pro <wli-pro>
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.

4 participants