Skip to content

Commit cff1189

Browse files
committed
Include column ID in error
Closes #514
1 parent 1884b85 commit cff1189

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

tokio-postgres/src/error/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ enum Kind {
336336
Tls,
337337
ToSql(usize),
338338
FromSql(usize),
339-
Column,
339+
Column(String),
340340
CopyInStream,
341341
Closed,
342342
Db,
@@ -369,13 +369,13 @@ impl fmt::Debug for Error {
369369

370370
impl fmt::Display for Error {
371371
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
372-
match self.0.kind {
372+
match &self.0.kind {
373373
Kind::Io => fmt.write_str("error communicating with the server")?,
374374
Kind::UnexpectedMessage => fmt.write_str("unexpected message from server")?,
375375
Kind::Tls => fmt.write_str("error performing TLS handshake")?,
376376
Kind::ToSql(idx) => write!(fmt, "error serializing parameter {}", idx)?,
377377
Kind::FromSql(idx) => write!(fmt, "error deserializing column {}", idx)?,
378-
Kind::Column => fmt.write_str("invalid column")?,
378+
Kind::Column(column) => write!(fmt, "invalid column `{}`", column)?,
379379
Kind::CopyInStream => fmt.write_str("error from a copy_in stream")?,
380380
Kind::Closed => fmt.write_str("connection closed")?,
381381
Kind::Db => fmt.write_str("db error")?,
@@ -454,8 +454,8 @@ impl Error {
454454
Error::new(Kind::FromSql(idx), Some(e))
455455
}
456456

457-
pub(crate) fn column() -> Error {
458-
Error::new(Kind::Column, None)
457+
pub(crate) fn column(column: String) -> Error {
458+
Error::new(Kind::Column(column), None)
459459
}
460460

461461
pub(crate) fn copy_in_stream<E>(e: E) -> Error

tokio-postgres/src/row.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,20 @@ impl Row {
146146
/// Like `Row::get`, but returns a `Result` rather than panicking.
147147
pub fn try_get<'a, I, T>(&'a self, idx: I) -> Result<T, Error>
148148
where
149-
I: RowIndex,
149+
I: RowIndex + fmt::Display,
150150
T: FromSql<'a>,
151151
{
152152
self.get_inner(&idx)
153153
}
154154

155155
fn get_inner<'a, I, T>(&'a self, idx: &I) -> Result<T, Error>
156156
where
157-
I: RowIndex,
157+
I: RowIndex + fmt::Display,
158158
T: FromSql<'a>,
159159
{
160160
let idx = match idx.__idx(self.columns()) {
161161
Some(idx) => idx,
162-
None => return Err(Error::column()),
162+
None => return Err(Error::column(idx.to_string())),
163163
};
164164

165165
let ty = self.columns()[idx].type_();
@@ -223,18 +223,18 @@ impl SimpleQueryRow {
223223
/// Like `SimpleQueryRow::get`, but returns a `Result` rather than panicking.
224224
pub fn try_get<I>(&self, idx: I) -> Result<Option<&str>, Error>
225225
where
226-
I: RowIndex,
226+
I: RowIndex + fmt::Display,
227227
{
228228
self.get_inner(&idx)
229229
}
230230

231231
fn get_inner<I>(&self, idx: &I) -> Result<Option<&str>, Error>
232232
where
233-
I: RowIndex,
233+
I: RowIndex + fmt::Display,
234234
{
235235
let idx = match idx.__idx(&self.columns) {
236236
Some(idx) => idx,
237-
None => return Err(Error::column()),
237+
None => return Err(Error::column(idx.to_string())),
238238
};
239239

240240
let buf = self.ranges[idx].clone().map(|r| &self.body.buffer()[r]);

0 commit comments

Comments
 (0)