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

Can you add LastPublic(), LastCode() API? #34

Open
OneSeven opened this issue Nov 22, 2024 · 3 comments
Open

Can you add LastPublic(), LastCode() API? #34

OneSeven opened this issue Nov 22, 2024 · 3 comments

Comments

@OneSeven
Copy link

I noticed that when calling Public(), Code(), the deepest public/code value will be obtained, but the business often overwrites the bottom layer information, and the top layer information is needed in the final output.

When I handle errors, I usually recursively obtain stack information. The current API does not allow me to obtain error information at each layer.

@samber
Copy link
Owner

samber commented Nov 22, 2024

I consider the most nested error to be the most accurate, and higher levels have less information about the error context.

Can you write a short example where the overwrite takes precedence ?

I wonder if a more general approach would be to add a method func (o *oops.Oops) Layers() []*oops.Oops.

@OneSeven
Copy link
Author

I consider the most nested error to be the most accurate, and higher levels have less information about the error context.

Can you write a short example where the overwrite takes precedence ?

I wonder if a more general approach would be to add a method func (o *oops.Oops) Layers() []*oops.Oops.

In the following short example, I only want to throw a code or msg that can be opened to the outside world to hide the internal error, because I will record detailed information in the final unified error handling.
For wrapf() and output Error(), I also hope to add a new API to only get the outermost error message, because I usually recursively get all levels of errors at the end to record or distribute them

func api(){
  return oops.Code("public code").Public("public msg").Wrap(service()) 
}

func service()err{
  return oops.Code("1").Errorf("e")
}

@OneSeven
Copy link
Author

I think in an ideal state, each layer of error is only responsible for processing its own information, so through Unwrap(), you can handle errors at each layer at will while retaining the stack information

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

No branches or pull requests

2 participants