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

Error kind is private #571

Closed
m-lima opened this issue Feb 10, 2020 · 6 comments
Closed

Error kind is private #571

m-lima opened this issue Feb 10, 2020 · 6 comments

Comments

@m-lima
Copy link

m-lima commented Feb 10, 2020

On tokio-postgres::error, Kind is a private enum as well as a private field inside ErrorInner.
There is no way of asserting the error except for parsing the string that comes out of the Display implementation for Error

For example:
In both line 455: pub(crate) fn column(column: String)
and line 479: pub(crate) fn row_count()
the errors are created with no cause, only kind. And the only way to extract that information and discern between the two is by comparing the output of the Display implementation.

Am I missing something or not seeing a way to assess the error kind and take action accordingly?

@sfackler
Copy link
Owner

Could you be more specific about what actions you want to take in response to errors?

@m-lima
Copy link
Author

m-lima commented Feb 10, 2020

The application is a warp server. When I do query_one and no items are found I get an error back (Kind::RowCount) signaling that no entries were found.
I cannot, however, differentiate this error easily (without parsing the String representation) and giving a sensible response to the client (in this case I wish to return a 404 Not Found)

@sfackler
Copy link
Owner

I'd just use query_opt instead and avoid having to deal with figuring out which kind of error it is in the first place.

@m-lima
Copy link
Author

m-lima commented Feb 10, 2020

Thank you

@hn-sl
Copy link

hn-sl commented Feb 9, 2021

I hope this issue reopened. This is not just about query_opt method. There are many cases when application need to take different action on different kind of errors. For example, application could terminate process when error is caused by syntax error but ignore error from closed connection, but currently there is no easy way to differentiate errors when cause is None.

@Ramambahara
Copy link

I found myself in the same situation as @hn-sl: we want to differentiate programming errors and connectivity/availability errors:

I.e. I want the program to terminate if it is a programming error (wrong parameter type in a prepared query,query_one or query_opt returned multiple rows, etc). I want to log and continue if it is a connectivity/availability error.

Having access to the kind of en error, or at least having 'is_error_in_query' would help with that.

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

4 participants