There are a lot of three-liners that begin with “if err != nil”. And often, output errors look too generic, and doesn’t even tell you which line created the error. A log.Fatal will not print stacktrace, but it will at least tell me which file, which line generated the error.
Can I add a package for error handling that will also use Dave Cheney’s lib? I feel that there are only three main cases.
- Receives error from external lib and want to log fatal with stack trace. This should add either zero or one extra line depending on whether the function returns err only. Imagine CHECK(myFunc(…)) or err := my Func; CHECK(err)
- Receives error from external lib and want to propagate. In this case, you want to use one of Dave’s function to stick in the stack trace. With the stack trace, there’s less need to add context and we can cut out several “return fmt.Errorf(“blah blah blah %s”, err)”.
- Creates error from within our library. In this case, our lib will just link to one of Dave’s wrap functions and we can save one import.
Ok, I am ignoring more complicated cases for now.
What do you all think?