There's a good argument to be made against wrapping errors at api-boundaries in some cases. IMO, that's something that's definitely case-by-case as there are situations where bubbling up the underlying error is 100% the right thing to do.
e.g.
io/fs.FS implementations are constrained to returning the
io/fs.PathError type by the interface documentation in some cases. However, there are specific underlying sentinel values that should be bubbled up and accessible.
IMO, within a package (or somewhat intentionally nebulously: "between API boundaries"), it's generally a good idea to use error wrapping so outer layers can make the actual wrapping, unwrapping, switching decisions.
By using error-wrapping, you're free to break functions up and add context as it bubbles up, without losing the ability to switch on the original error. (or at least use errors.Is or errors.As)
It's switching on errno values and wrapping specific sentinel errors with context for the errno values I knew I could see, with specific diagnostics for those errors.
Worth noting: stack traces rarely have argument values, and don't generally have other context information, e.g. EMFILE handling specifically checks the rlimit to get the fd limit value to include in the error message. Stack traces are nice for the programmer if they've opened the right version of the code, but useless for everyone else. Errors with context are orders of magnitude more useful if written correctly. (one of the reasons I don't like exceptions is that most of the time you just get the stack trace and original error, which is only barely useful for debugging if you have the most trivial bugs)
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/fa907dec-1dc7-4909-9743-4d91eb146481n%40googlegroups.com.