-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
errors: discourage cyclic error types #34957
Comments
How is this different from
|
They are functionally the same, but this is caused by some chain of Unwrap calls that forms a cycle. Although I don't think cycles will happen through intentional API design, I worry they may unintentionally happen from recursive error types.
|
My opinion is that |
I agree with Ian. The usual convention in linked-list based APIs, not just in simplicity-forward languages like Go but also in languages like Java that have different priorities, is to write the simple loop and let the user worry about cycles. (Search for In this case, cycles are both rare and indicate a bug. So I don't think it's the standard library's job to find them. |
I agree with Ian and Jonathan. In addition, I don't see any way to accidentally produce a cyclic error. We could add explicit documentation that |
I agree that cycle detection should not be the responsibility of the errors package. On further thought, it makes sense to see how these functions are used in the wild before preemptively documenting its behavior. As such, I will close the issue. |
It is possible to create a cycle of errors such that
errors.Is
anderrors.As
never terminate. A minimal example is shown below: (https://play.golang.org/p/gC4Ws7zV8eo)That said, is it reasonable to explicitly discourage packages from returning errors that can potentially form an Unwrap cycle, even through a recursive error type? Do I import a package on good faith after an extensive audit that it won't introduce a cycle, or should
errors.Is
anderrors.As
perform cycle detection?The text was updated successfully, but these errors were encountered: