I have read “Go errors are values” and as pointed out, this is a common complaint.
We could definitely have more error handling logic, e.g., store error in a struct somewhere. But most of the time, a log fatal suffices, I claim. If so, why do we need to keep writing
if err != nil {
log.Fatal(...)
}
I saw x/x.go and it looks more complicated than it should… A log fatal with stack trace is really simple. And a stack trace usually provides enough info… no need to x.Trace(…) everywhere I feel.
Code will look like: (derr for dgraph error, C for check, Cf for Check with printf)
Case 1:
derr.C(err)
derr.Cf(err, "Attr %s", attr)
Case 2:
return derr.W(err)
err is from external lib and we add stack trace inside and pass on.
Case 3:
return derr.E("Something failed %s %d", a, b)
return derr.E("Something failed")
All of the above will add stack trace.