You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 1, 2021. It is now read-only.
What do you think of errors' contexts like net/context or simple map[string]interface{} stored with the original error?
It would be really handy; example:
var ErrNotFound = error.New("Page not found!")
...
return errors.Wrap(ErrNotFound,pageTitle).WithContext(`http`,404)
this way the imaginary http handler won't need to know about ErrNotFound; it would just grab the value from the context. It could be even better:
var ErrNotFound = errors.Wrap(error.New("Page not found!"),"").WithContext(`http`,404)
...
return errors.Wrap(ErrNotFound,pageTitle)
however, this approach would lose stack data; it would require the stored stack's reset.
The context or map can be initiated on demand (when adding first value), so it wouldn't create some significant overhead if context is not used.