-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalerror-handlingLanguage & library change proposals that are about error handling.Language & library change proposals that are about error handling.v2An incompatible library changeAn incompatible library change
Milestone
Description
Proposal
Add p, q = foo!(a, b, c) notation equivalent to
p, q, err = foo(a, b, c)
if err != nil {
return err
}
to reduce error handling boilerplate code.
This can simplify great amount of code and make it more readable and composable while preserving the full power of idiomatic error handling in Go. For example
func foo(a, b, c int) (*Foo, error) {
p, err := mightFail(a)
if err != nil {
return nil, err
}
q := something(b)
r := somethingElse(c)
return &Foo{p, q, r}, nil
}
becomes
func foo(a, b, c int) (*Foo, error) {
p := mightFail!(a)
q := something(b)
r := somethingElse(c)
return &Foo{p, q, r}, nil
}
or even
func foo(a, b, c int) (*Foo, error) {
return &Foo{mightFail!(a), something(b), somethingElse(c)}, nil
}
stolyaroleh and jrwrencznic, ALTree, tomas-fp, klauspost, luna-duclos and 6 more
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeLanguageChangeSuggested changes to the Go languageSuggested changes to the Go languageProposalerror-handlingLanguage & library change proposals that are about error handling.Language & library change proposals that are about error handling.v2An incompatible library changeAn incompatible library change