Support the new V error field.
This commit is contained in:
parent
9d53e677ff
commit
a1c5ab55a1
@ -13,6 +13,59 @@ use {Result, DbErrorNew};
|
|||||||
|
|
||||||
mod sqlstate;
|
mod sqlstate;
|
||||||
|
|
||||||
|
/// The severity of a Postgres error or notice.
|
||||||
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
|
pub enum Severity {
|
||||||
|
/// PANIC
|
||||||
|
Panic,
|
||||||
|
/// FATAL
|
||||||
|
Fatal,
|
||||||
|
/// ERROR
|
||||||
|
Error,
|
||||||
|
/// WARNING
|
||||||
|
Warning,
|
||||||
|
/// NOTICE
|
||||||
|
Notice,
|
||||||
|
/// DEBUG
|
||||||
|
Debug,
|
||||||
|
/// INFO
|
||||||
|
Info,
|
||||||
|
/// LOG
|
||||||
|
Log,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for Severity {
|
||||||
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
let s = match *self {
|
||||||
|
Severity::Panic => "PANIC",
|
||||||
|
Severity::Fatal => "FATAL",
|
||||||
|
Severity::Error => "ERROR",
|
||||||
|
Severity::Warning => "WARNING",
|
||||||
|
Severity::Notice => "NOTICE",
|
||||||
|
Severity::Debug => "DEBUG",
|
||||||
|
Severity::Info => "INFO",
|
||||||
|
Severity::Log => "LOG",
|
||||||
|
};
|
||||||
|
fmt.write_str(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Severity {
|
||||||
|
fn from_str(s: &str) -> Option<Severity> {
|
||||||
|
match s {
|
||||||
|
"PANIC" => Some(Severity::Panic),
|
||||||
|
"FATAL" => Some(Severity::Fatal),
|
||||||
|
"ERROR" => Some(Severity::Error),
|
||||||
|
"WARNING" => Some(Severity::Warning),
|
||||||
|
"NOTICE" => Some(Severity::Notice),
|
||||||
|
"DEBUG" => Some(Severity::Debug),
|
||||||
|
"INFO" => Some(Severity::Info),
|
||||||
|
"LOG" => Some(Severity::Log),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A Postgres error or notice.
|
/// A Postgres error or notice.
|
||||||
#[derive(Clone, PartialEq, Eq)]
|
#[derive(Clone, PartialEq, Eq)]
|
||||||
pub struct DbError {
|
pub struct DbError {
|
||||||
@ -21,6 +74,9 @@ pub struct DbError {
|
|||||||
/// localized translation of one of these.
|
/// localized translation of one of these.
|
||||||
pub severity: String,
|
pub severity: String,
|
||||||
|
|
||||||
|
/// A parsed, nonlocalized version of `severity`. (PostgreSQL 9.6+)
|
||||||
|
pub parsed_severity: Option<Severity>,
|
||||||
|
|
||||||
/// The SQLSTATE code for the error.
|
/// The SQLSTATE code for the error.
|
||||||
pub code: SqlState,
|
pub code: SqlState,
|
||||||
|
|
||||||
@ -88,6 +144,7 @@ pub struct DbError {
|
|||||||
impl DbErrorNew for DbError {
|
impl DbErrorNew for DbError {
|
||||||
fn new_raw(fields: &mut ErrorFields) -> io::Result<DbError> {
|
fn new_raw(fields: &mut ErrorFields) -> io::Result<DbError> {
|
||||||
let mut severity = None;
|
let mut severity = None;
|
||||||
|
let mut parsed_severity = None;
|
||||||
let mut code = None;
|
let mut code = None;
|
||||||
let mut message = None;
|
let mut message = None;
|
||||||
let mut detail = None;
|
let mut detail = None;
|
||||||
@ -124,12 +181,14 @@ impl DbErrorNew for DbError {
|
|||||||
b'F' => file = Some(field.value().to_owned()),
|
b'F' => file = Some(field.value().to_owned()),
|
||||||
b'L' => line = Some(try!(field.value().parse::<u32>().map_err(|_| ::bad_response()))),
|
b'L' => line = Some(try!(field.value().parse::<u32>().map_err(|_| ::bad_response()))),
|
||||||
b'R' => routine = Some(field.value().to_owned()),
|
b'R' => routine = Some(field.value().to_owned()),
|
||||||
|
b'V' => parsed_severity = Some(try!(Severity::from_str(field.value()).ok_or_else(::bad_response))),
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(DbError {
|
Ok(DbError {
|
||||||
severity: try!(severity.ok_or_else(|| ::bad_response())),
|
severity: try!(severity.ok_or_else(|| ::bad_response())),
|
||||||
|
parsed_severity: parsed_severity,
|
||||||
code: try!(code.ok_or_else(|| ::bad_response())),
|
code: try!(code.ok_or_else(|| ::bad_response())),
|
||||||
message: try!(message.ok_or_else(|| ::bad_response())),
|
message: try!(message.ok_or_else(|| ::bad_response())),
|
||||||
detail: detail,
|
detail: detail,
|
||||||
|
Loading…
Reference in New Issue
Block a user