Skip to content
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

Proposal: How about allowing ServiceError to wrap error? #3058

Closed
ikawaha opened this issue Apr 30, 2022 · 2 comments
Closed

Proposal: How about allowing ServiceError to wrap error? #3058

ikawaha opened this issue Apr 30, 2022 · 2 comments

Comments

@ikawaha
Copy link
Contributor

ikawaha commented Apr 30, 2022

Motivation

The motivation for this proposal comes from the error handling in the middleware.

I tried to create a middleware that only logs specific errors, but I had to parse the error message to distinguish whether the "internal_server_error" was a DB error or some other unexpected error, and so on.

I am thinking that if the original error is embedded in ServiceError, it would be possible to distinguish the error by error type without having to parse the error message.

TL;DR;

  • A field is added to ServiceError to hold the error and the Unwrap interface is implemented.
  • The generated helper functions (MakeXXXX) wraps the error.
  • The original error is embedded or attached in ServiceError, making it easier to handle errors with errors.Is() and errors.As().

PoC

@ikawaha
Copy link
Contributor Author

ikawaha commented May 2, 2022

Thanks a lot for all the advice.

I have written another PoC to see if I could handle this by adding new helper functions without modifying the core Goa structures. This method does not affect existing user code.

#3061

Please tell me what you think.

@github-actions
Copy link

github-actions bot commented Jul 2, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant