Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make error a predefined variable for later comparision #24

Open
rskumar opened this issue Aug 27, 2019 · 3 comments
Open

Make error a predefined variable for later comparision #24

rskumar opened this issue Aug 27, 2019 · 3 comments

Comments

@rskumar
Copy link

rskumar commented Aug 27, 2019

err = errors.New("render: unable to automatically decode the request content type")

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.

rskumar added a commit to rskumar/render that referenced this issue Aug 27, 2019
@ptman
Copy link

ptman commented Aug 29, 2019

@rskumar
Copy link
Author

rskumar commented Aug 30, 2019

@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.

@ptman
Copy link

ptman commented Aug 30, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants