Add ability to convert context errors to generic errors
This commit is contained in:
parent
643344151b
commit
f02e12c63a
2 changed files with 16 additions and 3 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::error::Error;
|
||||
use crate::err::Error;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
|
||||
|
@ -8,8 +8,6 @@ pub enum Reason {
|
|||
Canceled,
|
||||
}
|
||||
|
||||
impl Error for Reason {}
|
||||
|
||||
impl fmt::Display for Reason {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {
|
||||
|
@ -19,6 +17,15 @@ impl fmt::Display for Reason {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Reason> for Error {
|
||||
fn from(reason: Reason) -> Error {
|
||||
match reason {
|
||||
Reason::Timedout => Error::TimeoutError,
|
||||
Reason::Canceled => Error::CancelledError,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Reason> for io::Error {
|
||||
fn from(reason: Reason) -> Self {
|
||||
let kind = match reason {
|
||||
|
|
|
@ -15,6 +15,12 @@ pub enum Error {
|
|||
#[error("Specify some SQL code to execute")]
|
||||
EmptyError,
|
||||
|
||||
#[error("The query failed to complete in time")]
|
||||
TimeoutError,
|
||||
|
||||
#[error("The query was cancelled before completion")]
|
||||
CancelledError,
|
||||
|
||||
#[error("Parse error at position {pos} when parsing '{sql}'")]
|
||||
ParseError {
|
||||
pos: usize,
|
||||
|
|
Loading…
Reference in a new issue