Skip to content
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
21 changes: 18 additions & 3 deletions tokio-postgres/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,25 @@ pub enum ErrorPosition {
},
}

#[derive(Debug, PartialEq)]
enum Kind {
/// Error kind returned by the database.
#[allow(missing_docs)]
#[derive(Debug, PartialEq, Clone)]
#[non_exhaustive]
pub enum Kind {
Io,
UnexpectedMessage,
Tls,
ToSql(usize),
FromSql(usize),
Comment on lines 347 to 348
Copy link
Member

@paolobarbolini paolobarbolini Sep 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These usizes are very ambiguous. Is this the index of the column? We should document it.

EDIT: or even convert it into something along the lines of:

FromSql {
    column_index: 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),
Parameters(usize, usize),
/// The number of parameters expected by the query doesn't match the number
/// of parameters passed when executing the prepared statement.
Parameters {
expected: usize,
found: usize,
},
Closed,
Db,
Parse,
Expand Down Expand Up @@ -438,6 +448,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