4 ms·
Go doesn't have (automatic) backtraces. If you don't wrap errors with a trace or with a custom message you often have no idea where the error came from.
by the_duke 5y ago
Go doesn't have (automatic) backtraces. If you don't wrap errors with a trace or with a custom message you often have no idea where the error came from.
- merely-unlikely 5y agoif err != nil { return mherr.WrapErr(err, "optional context") } I just wrote a custom function that adds the stack trace to the error. I also have it setup as a code snippet in VS Code so all I have to do is type "if err" and hit tab. Yes it looks a bit verbose but it adds approximately zero extra work and makes error handling extremely easy by default. Also, turn on log flags to add line numbers. log.SetFlags(log.Llongfile | log.LstdFlags)