Skip to content

Commit 97fb1b1

Browse files
committed
Add support for crate-external errors
1 parent 14e11bd commit 97fb1b1

File tree

1 file changed

+10
-0
lines changed
  • tokio-postgres/src/error

1 file changed

+10
-0
lines changed

tokio-postgres/src/error/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ enum Kind {
355355
#[cfg(feature = "runtime")]
356356
Connect,
357357
Timeout,
358+
External,
358359
}
359360

360361
struct ErrorInner {
@@ -394,6 +395,7 @@ impl fmt::Display for Error {
394395
#[cfg(feature = "runtime")]
395396
Kind::Connect => fmt.write_str("error connecting to server")?,
396397
Kind::Timeout => fmt.write_str("timeout waiting for server")?,
398+
Kind::External => fmt.write_str("error in external crate")?,
397399
};
398400
if let Some(ref cause) = self.0.cause {
399401
write!(fmt, ": {}", cause)?;
@@ -437,6 +439,14 @@ impl Error {
437439
Error(Box::new(ErrorInner { kind, cause }))
438440
}
439441

442+
/// Creates a new error from another crate, for use in connection wrappers.
443+
pub fn new_external(cause: Box<dyn error::Error + Sync + Send>) -> Error {
444+
Error(Box::new(ErrorInner {
445+
kind: Kind::External,
446+
cause: Some(cause),
447+
}))
448+
}
449+
440450
pub(crate) fn closed() -> Error {
441451
Error::new(Kind::Closed, None)
442452
}

0 commit comments

Comments
 (0)