diff --git a/src/error.rs b/src/error.rs index 0e4abe5b..e2d0e363 100644 --- a/src/error.rs +++ b/src/error.rs @@ -124,15 +124,15 @@ impl DbErrorNew for DbError { fn new_connect(fields: Vec<(u8, String)>) -> result::Result { match DbError::new_raw(fields) { - Ok(err) => Err(ConnectError::DbError(Box::new(err))), - Err(()) => Err(ConnectError::IoError(::bad_response())), + Ok(err) => Err(ConnectError::Db(Box::new(err))), + Err(()) => Err(ConnectError::Io(::bad_response())), } } fn new(fields: Vec<(u8, String)>) -> Result { match DbError::new_raw(fields) { - Ok(err) => Err(Error::DbError(Box::new(err))), - Err(()) => Err(Error::IoError(::bad_response())), + Ok(err) => Err(Error::Db(Box::new(err))), + Err(()) => Err(Error::Io(::bad_response())), } } } @@ -180,7 +180,7 @@ pub enum ConnectError { /// The `ConnectParams` was missing a user. MissingUser, /// An error from the Postgres server itself. - DbError(Box), + Db(Box), /// A password was required but not provided in the `ConnectParams`. MissingPassword, /// The Postgres server requested an authentication method not supported @@ -189,9 +189,9 @@ pub enum ConnectError { /// The Postgres server does not support SSL encryption. NoSslSupport, /// An error initializing the SSL session. - SslError(Box), + Ssl(Box), /// An error communicating with the server. - IoError(io::Error), + Io(io::Error), } impl fmt::Display for ConnectError { @@ -199,9 +199,9 @@ impl fmt::Display for ConnectError { try!(fmt.write_str(error::Error::description(self))); match *self { ConnectError::BadConnectParams(ref msg) => write!(fmt, ": {}", msg), - ConnectError::DbError(ref err) => write!(fmt, ": {}", err), - ConnectError::SslError(ref err) => write!(fmt, ": {}", err), - ConnectError::IoError(ref err) => write!(fmt, ": {}", err), + ConnectError::Db(ref err) => write!(fmt, ": {}", err), + ConnectError::Ssl(ref err) => write!(fmt, ": {}", err), + ConnectError::Io(ref err) => write!(fmt, ": {}", err), _ => Ok(()), } } @@ -212,7 +212,7 @@ impl error::Error for ConnectError { match *self { ConnectError::BadConnectParams(_) => "Error creating `ConnectParams`", ConnectError::MissingUser => "User missing in `ConnectParams`", - ConnectError::DbError(_) => "Error reported by Postgres", + ConnectError::Db(_) => "Error reported by Postgres", ConnectError::MissingPassword => { "The server requested a password but none was provided" } @@ -220,17 +220,17 @@ impl error::Error for ConnectError { "The server requested an unsupported authentication method" } ConnectError::NoSslSupport => "The server does not support SSL", - ConnectError::SslError(_) => "Error initiating SSL session", - ConnectError::IoError(_) => "Error communicating with the server", + ConnectError::Ssl(_) => "Error initiating SSL session", + ConnectError::Io(_) => "Error communicating with the server", } } fn cause(&self) -> Option<&error::Error> { match *self { ConnectError::BadConnectParams(ref err) => Some(&**err), - ConnectError::DbError(ref err) => Some(&**err), - ConnectError::SslError(ref err) => Some(&**err), - ConnectError::IoError(ref err) => Some(err), + ConnectError::Db(ref err) => Some(&**err), + ConnectError::Ssl(ref err) => Some(&**err), + ConnectError::Io(ref err) => Some(err), _ => None, } } @@ -238,19 +238,19 @@ impl error::Error for ConnectError { impl From for ConnectError { fn from(err: io::Error) -> ConnectError { - ConnectError::IoError(err) + ConnectError::Io(err) } } impl From for ConnectError { fn from(err: DbError) -> ConnectError { - ConnectError::DbError(Box::new(err)) + ConnectError::Db(Box::new(err)) } } impl From for ConnectError { fn from(err: byteorder::Error) -> ConnectError { - ConnectError::IoError(From::from(err)) + ConnectError::Io(From::from(err)) } } @@ -272,9 +272,9 @@ pub enum ErrorPosition { #[derive(Debug)] pub enum Error { /// An error reported by the Postgres server. - DbError(Box), + Db(Box), /// An error communicating with the Postgres server. - IoError(io::Error), + Io(io::Error), /// An attempt was made to convert between incompatible Rust and Postgres /// types. WrongType(Type), @@ -286,8 +286,8 @@ impl fmt::Display for Error { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { try!(fmt.write_str(error::Error::description(self))); match *self { - Error::DbError(ref err) => write!(fmt, ": {}", err), - Error::IoError(ref err) => write!(fmt, ": {}", err), + Error::Db(ref err) => write!(fmt, ": {}", err), + Error::Io(ref err) => write!(fmt, ": {}", err), Error::WrongType(ref ty) => write!(fmt, ": saw type {:?}", ty), Error::Conversion(ref err) => write!(fmt, ": {}", err), } @@ -297,8 +297,8 @@ impl fmt::Display for Error { impl error::Error for Error { fn description(&self) -> &str { match *self { - Error::DbError(_) => "Error reported by Postgres", - Error::IoError(_) => "Error communicating with the server", + Error::Db(_) => "Error reported by Postgres", + Error::Io(_) => "Error communicating with the server", Error::WrongType(_) => "Unexpected type", Error::Conversion(_) => "Error converting between Postgres and Rust types", } @@ -306,8 +306,8 @@ impl error::Error for Error { fn cause(&self) -> Option<&error::Error> { match *self { - Error::DbError(ref err) => Some(&**err), - Error::IoError(ref err) => Some(err), + Error::Db(ref err) => Some(&**err), + Error::Io(ref err) => Some(err), Error::Conversion(ref err) => Some(&**err), _ => None, } @@ -316,19 +316,19 @@ impl error::Error for Error { impl From for Error { fn from(err: DbError) -> Error { - Error::DbError(Box::new(err)) + Error::Db(Box::new(err)) } } impl From for Error { fn from(err: io::Error) -> Error { - Error::IoError(err) + Error::Io(err) } } impl From for Error { fn from(err: byteorder::Error) -> Error { - Error::IoError(From::from(err)) + Error::Io(From::from(err)) } } diff --git a/src/lib.rs b/src/lib.rs index 2dc38660..8d993f93 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -346,7 +346,7 @@ impl IsolationLevel { } else if raw.eq_ignore_ascii_case("SERIALIZABLE") { Ok(IsolationLevel::Serializable) } else { - Err(Error::IoError(bad_response())) + Err(Error::Io(bad_response())) } } } @@ -444,7 +444,7 @@ impl InnerConnection { } ReadyForQuery { .. } => break, ErrorResponse { fields } => return DbError::new_connect(fields), - _ => return Err(ConnectError::IoError(bad_response())), + _ => return Err(ConnectError::Io(bad_response())), } } @@ -464,10 +464,10 @@ impl InnerConnection { t.typnamespace = n.oid \ WHERE t.oid = $1") { Ok(..) => return Ok(()), - Err(Error::IoError(e)) => return Err(ConnectError::IoError(e)), + Err(Error::Io(e)) => return Err(ConnectError::Io(e)), // Range types weren't added until Postgres 9.2, so pg_range may not exist - Err(Error::DbError(ref e)) if e.code == SqlState::UndefinedTable => {} - Err(Error::DbError(e)) => return Err(ConnectError::DbError(e)), + Err(Error::Db(ref e)) if e.code == SqlState::UndefinedTable => {} + Err(Error::Db(e)) => return Err(ConnectError::Db(e)), _ => unreachable!(), } @@ -478,8 +478,8 @@ impl InnerConnection { ON t.typnamespace = n.oid \ WHERE t.oid = $1") { Ok(..) => Ok(()), - Err(Error::IoError(e)) => Err(ConnectError::IoError(e)), - Err(Error::DbError(e)) => Err(ConnectError::DbError(e)), + Err(Error::Io(e)) => Err(ConnectError::Io(e)), + Err(Error::Db(e)) => Err(ConnectError::Db(e)), _ => unreachable!(), } } @@ -567,13 +567,13 @@ impl InnerConnection { AuthenticationGSS | AuthenticationSSPI => return Err(ConnectError::UnsupportedAuthentication), ErrorResponse { fields } => return DbError::new_connect(fields), - _ => return Err(ConnectError::IoError(bad_response())), + _ => return Err(ConnectError::Io(bad_response())), } match try!(self.read_message()) { AuthenticationOk => Ok(()), ErrorResponse { fields } => return DbError::new_connect(fields), - _ => return Err(ConnectError::IoError(bad_response())), + _ => return Err(ConnectError::Io(bad_response())), } } @@ -1336,13 +1336,13 @@ fn read_rows(conn: &mut InnerConnection, buf: &mut VecDeque>> _ => {} } } - return Err(Error::IoError(std_io::Error::new(std_io::ErrorKind::InvalidInput, + return Err(Error::Io(std_io::Error::new(std_io::ErrorKind::InvalidInput, "COPY queries cannot be directly \ executed"))); } _ => { conn.desynchronized = true; - return Err(Error::IoError(bad_response())); + return Err(Error::Io(bad_response())); } } } diff --git a/src/macros.rs b/src/macros.rs index 2a2b5275..d0e0e536 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -13,7 +13,7 @@ macro_rules! try_desync { macro_rules! check_desync { ($e:expr) => ({ if $e.is_desynchronized() { - return Err(::error::Error::IoError(::desynchronized())); + return Err(::error::Error::Io(::desynchronized())); } }) } @@ -22,6 +22,6 @@ macro_rules! bad_response { ($s:expr) => ({ debug!("Bad response at {}:{}", file!(), line!()); $s.desynchronized = true; - return Err(::error::Error::IoError(::bad_response())); + return Err(::error::Error::Io(::bad_response())); }) } diff --git a/src/notification.rs b/src/notification.rs index 610ea9f9..bb07742e 100644 --- a/src/notification.rs +++ b/src/notification.rs @@ -115,7 +115,7 @@ impl<'a> Iterator for BlockingIter<'a> { } if conn.is_desynchronized() { - return Some(Err(Error::IoError(desynchronized()))); + return Some(Err(Error::Io(desynchronized()))); } match conn.read_message_with_notification() { @@ -126,7 +126,7 @@ impl<'a> Iterator for BlockingIter<'a> { payload: payload, })) } - Err(err) => Some(Err(Error::IoError(err))), + Err(err) => Some(Err(Error::Io(err))), _ => unreachable!(), } } @@ -150,7 +150,7 @@ impl<'a> Iterator for TimeoutIter<'a> { } if conn.is_desynchronized() { - return Some(Err(Error::IoError(desynchronized()))); + return Some(Err(Error::Io(desynchronized()))); } match conn.read_message_with_notification_timeout(self.timeout) { @@ -162,7 +162,7 @@ impl<'a> Iterator for TimeoutIter<'a> { })) } Ok(None) => None, - Err(err) => Some(Err(Error::IoError(err))), + Err(err) => Some(Err(Error::Io(err))), _ => unreachable!(), } } diff --git a/src/priv_io.rs b/src/priv_io.rs index 1e7f066b..34558bbb 100644 --- a/src/priv_io.rs +++ b/src/priv_io.rs @@ -180,6 +180,6 @@ pub fn initialize_stream(params: &ConnectParams, match negotiator.negotiate_ssl(host, socket) { Ok(stream) => Ok(stream), - Err(err) => Err(ConnectError::SslError(err)), + Err(err) => Err(ConnectError::Ssl(err)), } } diff --git a/src/stmt.rs b/src/stmt.rs index 40a41148..c51cdb9d 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -121,7 +121,7 @@ impl<'conn> Statement<'conn> { } _ => { conn.desynchronized = true; - Err(Error::IoError(bad_response())) + Err(Error::Io(bad_response())) } } } @@ -212,7 +212,7 @@ impl<'conn> Statement<'conn> { } _ => { conn.desynchronized = true; - return Err(Error::IoError(bad_response())); + return Err(Error::Io(bad_response())); } } } @@ -321,7 +321,7 @@ impl<'conn> Statement<'conn> { loop { match try!(conn.read_message()) { ReadyForQuery { .. } => { - return Err(Error::IoError(io::Error::new(io::ErrorKind::InvalidInput, + return Err(Error::Io(io::Error::new(io::ErrorKind::InvalidInput, "called `copy_in` on a \ non-`COPY FROM STDIN` \ statement"))); @@ -354,11 +354,11 @@ impl<'conn> Statement<'conn> { } _ => { info.conn.desynchronized = true; - return Err(Error::IoError(bad_response())); + return Err(Error::Io(bad_response())); } } try!(info.conn.wait_for_ready()); - return Err(Error::IoError(err)); + return Err(Error::Io(err)); } } } @@ -373,7 +373,7 @@ impl<'conn> Statement<'conn> { } _ => { info.conn.desynchronized = true; - return Err(Error::IoError(bad_response())); + return Err(Error::Io(bad_response())); } }; @@ -417,11 +417,11 @@ impl<'conn> Statement<'conn> { } _ => { conn.desynchronized = true; - return Err(Error::IoError(bad_response())); + return Err(Error::Io(bad_response())); } } try!(conn.wait_for_ready()); - return Err(Error::IoError(io::Error::new(io::ErrorKind::InvalidInput, + return Err(Error::Io(io::Error::new(io::ErrorKind::InvalidInput, "called `copy_out` on a non-`COPY TO \ STDOUT` statement"))); } @@ -433,7 +433,7 @@ impl<'conn> Statement<'conn> { loop { match try!(conn.read_message()) { ReadyForQuery { .. } => { - return Err(Error::IoError(io::Error::new(io::ErrorKind::InvalidInput, + return Err(Error::Io(io::Error::new(io::ErrorKind::InvalidInput, "called `copy_out` on a \ non-`COPY TO STDOUT` \ statement"))); @@ -461,7 +461,7 @@ impl<'conn> Statement<'conn> { Err(e) => { loop { match try!(info.conn.read_message()) { - ReadyForQuery { .. } => return Err(Error::IoError(e)), + ReadyForQuery { .. } => return Err(Error::Io(e)), _ => {} } } @@ -485,7 +485,7 @@ impl<'conn> Statement<'conn> { _ => { loop { match try!(info.conn.read_message()) { - ReadyForQuery { .. } => return Err(Error::IoError(bad_response())), + ReadyForQuery { .. } => return Err(Error::Io(bad_response())), _ => {} } } diff --git a/tests/test.rs b/tests/test.rs index 1415de17..6bf68aaf 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -56,7 +56,7 @@ fn test_prepare_err() { let conn = or_panic!(Connection::connect("postgres://postgres@localhost", SslMode::None)); let stmt = conn.prepare("invalid sql database"); match stmt { - Err(Error::DbError(ref e)) if e.code == SyntaxError && e.position == Some(Normal(1)) => {} + Err(Error::Db(ref e)) if e.code == SyntaxError && e.position == Some(Normal(1)) => {} Err(e) => panic!("Unexpected result {:?}", e), _ => panic!("Unexpected result"), } @@ -65,7 +65,7 @@ fn test_prepare_err() { #[test] fn test_unknown_database() { match Connection::connect("postgres://postgres@localhost/asdf", SslMode::None) { - Err(ConnectError::DbError(ref e)) if e.code == InvalidCatalogName => {} + Err(ConnectError::Db(ref e)) if e.code == InvalidCatalogName => {} Err(resp) => panic!("Unexpected result {:?}", resp), _ => panic!("Unexpected result"), } @@ -339,7 +339,7 @@ fn test_batch_execute_error() { let stmt = conn.prepare("SELECT * FROM foo ORDER BY id"); match stmt { - Err(Error::DbError(ref e)) if e.code == UndefinedTable => {} + Err(Error::Db(ref e)) if e.code == UndefinedTable => {} Err(e) => panic!("unexpected error {:?}", e), _ => panic!("unexpected success"), } @@ -382,7 +382,7 @@ FROM (SELECT gs.i ORDER BY gs.i LIMIT 2) ss")); match stmt.query(&[]) { - Err(Error::DbError(ref e)) if e.code == CardinalityViolation => {} + Err(Error::Db(ref e)) if e.code == CardinalityViolation => {} Err(err) => panic!("Unexpected error {:?}", err), Ok(_) => panic!("Expected failure"), }; @@ -648,7 +648,7 @@ fn test_cancel_query() { }); match conn.execute("SELECT pg_sleep(10)", &[]) { - Err(Error::DbError(ref e)) if e.code == QueryCanceled => {} + Err(Error::Db(ref e)) if e.code == QueryCanceled => {} Err(res) => panic!("Unexpected result {:?}", res), _ => panic!("Unexpected result"), } @@ -708,7 +708,7 @@ fn test_plaintext_pass_no_pass() { fn test_plaintext_pass_wrong_pass() { let ret = Connection::connect("postgres://pass_user:asdf@localhost/postgres", SslMode::None); match ret { - Err(ConnectError::DbError(ref e)) if e.code == InvalidPassword => {} + Err(ConnectError::Db(ref e)) if e.code == InvalidPassword => {} Err(err) => panic!("Unexpected error {:?}", err), _ => panic!("Expected error") } @@ -733,7 +733,7 @@ fn test_md5_pass_no_pass() { fn test_md5_pass_wrong_pass() { let ret = Connection::connect("postgres://md5_user:asdf@localhost/postgres", SslMode::None); match ret { - Err(ConnectError::DbError(ref e)) if e.code == InvalidPassword => {} + Err(ConnectError::Db(ref e)) if e.code == InvalidPassword => {} Err(err) => panic!("Unexpected error {:?}", err), _ => panic!("Expected error") } @@ -745,12 +745,12 @@ fn test_execute_copy_from_err() { or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[])); let stmt = or_panic!(conn.prepare("COPY foo (id) FROM STDIN")); match stmt.execute(&[]) { - Err(Error::DbError(ref err)) if err.message.contains("COPY") => {} + Err(Error::Db(ref err)) if err.message.contains("COPY") => {} Err(err) => panic!("Unexpected error {:?}", err), _ => panic!("Expected error"), } match stmt.query(&[]) { - Err(Error::DbError(ref err)) if err.message.contains("COPY") => {} + Err(Error::Db(ref err)) if err.message.contains("COPY") => {} Err(err) => panic!("Unexpected error {:?}", err), _ => panic!("Expected error"), }; @@ -761,7 +761,7 @@ fn test_batch_execute_copy_from_err() { let conn = or_panic!(Connection::connect("postgres://postgres@localhost", SslMode::None)); or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[])); match conn.batch_execute("COPY foo (id) FROM STDIN") { - Err(Error::DbError(ref err)) if err.message.contains("COPY") => {} + Err(Error::Db(ref err)) if err.message.contains("COPY") => {} Err(err) => panic!("Unexpected error {:?}", err), _ => panic!("Expected error"), } @@ -781,7 +781,7 @@ fn test_copy_io_error() { or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[])); let stmt = or_panic!(conn.prepare("COPY foo (id) FROM STDIN")); match stmt.copy_in(&[], &mut ErrorReader) { - Err(Error::IoError(ref e)) if e.kind() == io::ErrorKind::AddrNotAvailable => {} + Err(Error::Io(ref e)) if e.kind() == io::ErrorKind::AddrNotAvailable => {} Err(err) => panic!("Unexpected error {:?}", err), _ => panic!("Expected error"), } @@ -810,7 +810,7 @@ fn test_query_copy_out_err() { let stmt = or_panic!(conn.prepare("COPY foo (id) TO STDOUT")); match stmt.query(&[]) { Ok(_) => panic!("unexpected success"), - Err(Error::IoError(ref e)) if e.to_string().contains("COPY") => {} + Err(Error::Io(ref e)) if e.to_string().contains("COPY") => {} Err(e) => panic!("unexpected error {:?}", e), }; } @@ -839,7 +839,7 @@ fn test_copy_out_error() { let mut buf = vec![]; match stmt.copy_out(&[], &mut buf) { Ok(_) => panic!("unexpected success"), - Err(Error::DbError(..)) => {} + Err(Error::Db(..)) => {} Err(e) => panic!("unexpected error {}", e), } }