News for hackers. Stuff that matters.
Re:Upcoming Features in Go 1.18 by lalaithion on Tuesday November 09, 2021 @12:29PM (#29164567)
I don't actually mind writing the above and adding context, but let's brainstorm some syntax that does the same thing without being verbose. How about something like:

    $variable1 := try $function_call_which_returns_two_values except $variable2: $expression_which_has_error_type
which is automatically desugared to

    $variable1, $variable2 := $function_call_which_returns_two_values
    if $variable2 != nil {
       return ($zero_values_for_other_return_types, )* $expression_which_has_error_type
    }
Re:Upcoming Features in Go 1.18 by mseepgood on Tuesday November 09, 2021 @12:49PM (#29164855)
> let's brainstorm some syntax

Don't forget to check if someone else already had the same idea: https://seankhliao.com/blog/12020-11-23-go-error-handling-pr...

Re:Upcoming Features in Go 1.18 by morelisp on Tuesday November 09, 2021 @12:31PM (#29164592)
Re:Upcoming Features in Go 1.18 by lalaithion on Tuesday November 09, 2021 @12:44PM (#29164782)
The try syntax proposed there and in other places returns the error unwrapped, which is a no-go for me. I wrap every error that I return from every function.
Re:Upcoming Features in Go 1.18 by encoderer on Tuesday November 09, 2021 @01:42PM (#29165593)
Oh can I see how you do it?
Re:Upcoming Features in Go 1.18 by camkego on Wednesday November 10, 2021 @05:03AM (#29172995)
Please share articles/blog posts! I would guess there are newer articles about best practices for Go error handling, other than the great articles by Dave Cheney. https://dave.cheney.net/2016/04/27/dont-just-check-errors-ha...