Open
Conversation
This makes it possible to use panics for flow control without redundant error checking (or the chance to forget to check returned errors), and collaborates with the error type system to all quick and easy filtering of errors.
There's no good reason to, since you can never meaningfully interact with it other than through the already exposed chainable functions, but exporting it makes godoc do a significantly better job on the package.
…object, even when handling non-error types such as int and string.
Author
There was a problem hiding this comment.
This is a super terrible test. I could say I left it in so it could spark some discussion, but really, I just forgot it was here.
I'd love suggestions for how to get coverage or describe this behavior correctly... otherwise it should probably thrown away, because all it does is print stuff that has to be eyeballed, and that's just not a test.
Add OriginalError convenience accessor. Rename data key var to make more sense. Add package level documentation pointing out CatchAll's error wrapping behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello! Spacemonkey errors are awesome! Using them in my projects has resulted in a huge reduction in boilerplate and grouping things into hierarchies has made my errors and handling much cleaner!
This is a package that attempts to take boilerplate reduction a step further, and replace frequent three-liner
if err := whatever(); err != nil { return err }error handling blocks and replace them with... well, zero liners, by using panics instead. To make this feel cozy, thistrypackage makes semantics that feel like try/catch semantics in other languages, and makes it easy to use spacemonkey error type hierarchies to trigger different handling paths. The example test functions in the PR should be pretty good demonstrations of how the syntax works.Panics aren't for everybody (or every situation), I know. This would represent a totally optional way to use spacemonkey errors, and so is isolated off in a sub-package. If a project is happy on the path of error returns, they'll have no reason to ever import the
trypackage. And indeed, return-style errors are still often a good idea in many situations ('specially around concurrent work, where they're effectively required for channel/cross-goroutine reporting, even if the majority of the program is using panics andtrywithin individual goroutines) -- so there's some package docs that attempt to highlight that, and it's purposefully easy to use theCatchAllsystem to flip panics back into return-style errors. Another school of thought has panics as being valid within packages, but impolite to expose across package boundaries (stdlibencodinglibraries are known for doing this internally), andtryshould be totally easy to use like that, too.I've been incubating this in usage in some projects for a while now (as you can see from the commit timestamps...) and it's been working pretty well, so I thought I'd share and see if anyone thinks this is an interesting enough pattern to upstream :D