Skip to content

Make error::Kind public #1185

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions tokio-postgres/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,20 @@ pub enum ErrorPosition {
},
}

#[derive(Debug, PartialEq)]
enum Kind {
/// Error kind returned by the database.
#[allow(missing_docs)]
#[derive(Debug, PartialEq, Clone)]
pub enum Kind {
Io,
UnexpectedMessage,
Tls,
ToSql(usize),
FromSql(usize),
/// A column was fetched from the row which wasn't returned by the database.
/// This usually indicates the column wasn't included in the query.
Column(String),
/// The number of parameters expected by the query doesn't match the number
/// of parameters passed when executing the prepared statement.
Parameters(usize, usize),
Closed,
Db,
Expand Down Expand Up @@ -438,6 +444,11 @@ impl Error {
self.as_db_error().map(DbError::code)
}

/// Returns the kind of error.
pub fn kind(&self) -> &Kind {
&self.0.kind
}

fn new(kind: Kind, cause: Option<Box<dyn error::Error + Sync + Send>>) -> Error {
Error(Box::new(ErrorInner { kind, cause }))
}
Expand Down
Loading