Konubinix' opinionated web of thoughts

Error Handling in Go

Fleeting

Error Handling in Go that Every Beginner should Know

Unfortunately, the standard errors does not come with stack traces. Without stack traces, it is very difficult to debug when you have no idea where the error occurs. The error could pass through 10 function calls before it gets to the code that prints it out

https://hussachai.medium.com/error-handling-in-go-a-quick-opinionated-guide-9199dd7c7f76

I personally like pkg/errors the most since it’s compatible with the standard package

https://hussachai.medium.com/error-handling-in-go-a-quick-opinionated-guide-9199dd7c7f76

you can just change the import statement from “errors” to “github.com/pkg/errors” and call it a day

https://hussachai.medium.com/error-handling-in-go-a-quick-opinionated-guide-9199dd7c7f76

print stack traces instead of a plain error message, you have to use %+v instead of %v in the format pattern

https://hussachai.medium.com/error-handling-in-go-a-quick-opinionated-guide-9199dd7c7f76