-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: spec: goto error handler with @err #72153
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
Comments
Sorry, its probably because I am not as proficient with compilers. Would anyone downvoting be willing to share what are the main issues with the proposal? |
The TL;DR would be: its I dont see how this would make anything anyhow better. New Keywords, new magic decorators, more indirection and less linear functions, changes meaning of existing keywords depending on context, nothing that makes it more clear what is going on, no compiler level optimisations this would enable. It looks like its wants to be magic, but all it does is smell. I am a forever No one has managed to propose a type of error handling that would be so significantly better that it would be worth throwing this beautiful and predictable pattern away. |
Ok thank you for taking the time to explain.
- Akshay
…On Fri, Mar 7, 2025 at 10:28 AM BieHDC ***@***.***> wrote:
Would anyone downvoting be willing to share what are the main issues with
the proposal?
The TL;DR would be: its goto with extra steps and noise.
I dont see how this would make anything anyhow better. New Keywords, new
magic decorators, more indirection and less linear functions, changes
meaning of existing keywords depending on context, nothing that makes it
more clear what is going on, no compiler level optimisations this would
enable. It looks like its wants to be magic, but all it does is smell.
It does the opposite of what i love about Go.
I am a forever if err != niler, because it is always clear whats going on
whenever you see this, even for someone who has just started learning. You
can collapse the scope block in any basic IDE making it very easy to follow
along even longer and more complex functions because it provides an easy
way to hide "error handling noise".
No one has managed to propose a type of error handling that would be so
significantly better that it would be worth throwing this beautiful and
predictable pattern away.
Please stop trying to make everything magic. Just write the basic for
loop, just use a map and just if err != nil it.
—
Reply to this email directly, view it on GitHub
<#72153 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA2J3UROZTIDVABRAOYUS32THQLFAVCNFSM6AAAAABYQQLM3WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMBXGEZDCMJXGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
[image: BieHDC]*BieHDC* left a comment (golang/go#72153)
<#72153 (comment)>
Would anyone downvoting be willing to share what are the main issues with
the proposal?
The TL;DR would be: its goto with extra steps and noise.
I dont see how this would make anything anyhow better. New Keywords, new
magic decorators, more indirection and less linear functions, changes
meaning of existing keywords depending on context, nothing that makes it
more clear what is going on, no compiler level optimisations this would
enable. It looks like its wants to be magic, but all it does is smell.
It does the opposite of what i love about Go.
I am a forever if err != niler, because it is always clear whats going on
whenever you see this, even for someone who has just started learning. You
can collapse the scope block in any basic IDE making it very easy to follow
along even longer and more complex functions because it provides an easy
way to hide "error handling noise".
No one has managed to propose a type of error handling that would be so
significantly better that it would be worth throwing this beautiful and
predictable pattern away.
Please stop trying to make everything magic. Just write the basic for
loop, just use a map and just if err != nil it.
—
Reply to this email directly, view it on GitHub
<#72153 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA2J3UROZTIDVABRAOYUS32THQLFAVCNFSM6AAAAABYQQLM3WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMBXGEZDCMJXGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Go Programming Experience
Intermediate
Other Languages Experience
Swift, C, C++, JS, Kotlin, Python, Java
Related Idea
Has this idea, or one like it, been proposed before?
Yes. Similar issues are:
How this issue is different:
This proposal is backwards compatible, allows handling errors before returning, reduces boilerplate, is clear where each error is handled and the scope of variables available during error handling, provides an explicit declaration that execution continue after error handling if needed, and is easy to read and understand.
Does this affect error handling?
Yes
Related proposals and how this differs:
#43777 - similar to try/catch so unclear if a function returns an error while reading the code. Specific error types has to be known for proper handling from multiple functions. The scope of which handler "catches" what error is not clear.
#56126 - forces return from function without actually handling error. No custom error handling allowed. The magic handleErr function is unclear in what it does. Syntax looks very incompatible with current go syntax.
#62378 - forces return without handling error. Syntax is unclear (hard to read) as well.
#70151 - proposes executing any function returning an error within an error context. Thus, all functions returning errors must be wrapped in 'ctx.Do(...)' call making syntax hard to accept. Also, does not allow continuing after an error occurs and only first error in a series of steps (function calls) can be handled and maybe function must return after that.
Is this about generics?
No
Proposal
Goals of this error handling proposal in order of importance:
Synopsis:
I am proposing a new statment block called
eswitch
that handles errors that are returned in the same scope. Errors indicate that they want to be handled by aneswitch
block by preceding the error variable name by an@
sign. If an error occurs, control jumps to the respective case statement in the eswitch block. From there, function can return or control can continue after the line where the error occurred. See theeswitch
example below.Code example (contains several scenarios):
Is this change backward compatible?
Yes. See above example.
The text was updated successfully, but these errors were encountered: