3 ms·
Some don't like the magic, and some are worried about losing annotated errors. If you can tolerate just a little bit more magic, you can solve the error annota
by infogulch 7y ago
Some don't like the magic, and some are worried about losing annotated errors. If you can tolerate just a little bit more magic, you can solve the error annotation problem:
f := try(os.Open(filename), "opening config file")
Place the context string just after the last, error parameter. That is, make try also also allow the pattern: try( a1, a2, ..., error, string ). Bonus points if the last arg could be a func(error) error, that way you can pass a local closure to wrap the error in a scoped context and also avoid pre-calculating an expensive error string even in the non-error case.
It's just a language feature, you can make up any interface you want. We're already on the magic train, might as well ride it.
- agnivade 7y agoAll of these have already been discussed in the GH issue. It is all being taken into consideration. Check out https://swtch.com/try.html https://swtch.com/try.html for a thematic grouping of the issue.
- infogulch 7y agoThat's a heck of a reference, thanks for sharing! And there it is https://swtch.com/try.html#args https://swtch.com/try.html#args under Alternative: Add arguments to try. Seems I have some reading to do.