Make error a predefined variable for later comparision
https://github.com/go-chi/render/blob/3215478343fbc559bd3fc08f7031bb134d6bdad5/decoder.go#L30
If the returned error are defined var, it would be possible to compare and know what exactly happened. The error message from render package cannot be directly to client in most cases, but application developer would like to return some custom error.
var (
ErrContentTypeNotSet = errors.New("render: missing content-type, unable to automatically decode the request content")
)
would be helpful.
https://dave.cheney.net/2016/04/07/constant-errors
@ptman error interface is generic. Just Error() doesn't let me know exact what happened and can we handle it and what specifc msg we need to show to client. Even in link you shared, there are example of where to use vars like iot.EOF or sql.ErrNoRows.
For me, anonymous errors.New("") are useless and I consider it as one that cannot be processed confidently other than printing to log.
cockroachdb/errors repo has a very indepth comparative analysis on different mechanisms.
You misunderstand me. I suggest not using errors.New() but instead using constant errors, like in the article, that satisfy the error interface. Those can be compared.