|
1 |
| -//! Error types. |
2 |
| -
|
3 | 1 | use fallible_iterator::FallibleIterator;
|
4 | 2 | use postgres_protocol::message::backend::ErrorFields;
|
5 | 3 | use std::error;
|
@@ -141,7 +139,7 @@ pub struct DbError {
|
141 | 139 |
|
142 | 140 | impl DbError {
|
143 | 141 | #[doc(hidden)]
|
144 |
| - pub fn new_raw(fields: &mut ErrorFields) -> io::Result<DbError> { |
| 142 | + pub fn new(fields: &mut ErrorFields) -> io::Result<DbError> { |
145 | 143 | let mut severity = None;
|
146 | 144 | let mut parsed_severity = None;
|
147 | 145 | let mut code = None;
|
@@ -245,22 +243,6 @@ impl DbError {
|
245 | 243 | _p: (),
|
246 | 244 | })
|
247 | 245 | }
|
248 |
| - |
249 |
| - #[doc(hidden)] |
250 |
| - pub fn new_connect<T>(fields: &mut ErrorFields) -> Result<T, ConnectError> { |
251 |
| - match DbError::new_raw(fields) { |
252 |
| - Ok(err) => Err(ConnectError::Db(Box::new(err))), |
253 |
| - Err(e) => Err(ConnectError::Io(e)), |
254 |
| - } |
255 |
| - } |
256 |
| - |
257 |
| - #[doc(hidden)] |
258 |
| - pub fn new<T>(fields: &mut ErrorFields) -> Result<T, Error> { |
259 |
| - match DbError::new_raw(fields) { |
260 |
| - Ok(err) => Err(Error::Db(Box::new(err))), |
261 |
| - Err(e) => Err(Error::Io(e)), |
262 |
| - } |
263 |
| - } |
264 | 246 | }
|
265 | 247 |
|
266 | 248 | // manual impl to leave out _p
|
@@ -299,6 +281,20 @@ impl error::Error for DbError {
|
299 | 281 | }
|
300 | 282 | }
|
301 | 283 |
|
| 284 | +/// Represents the position of an error in a query. |
| 285 | +#[derive(Clone, PartialEq, Eq, Debug)] |
| 286 | +pub enum ErrorPosition { |
| 287 | + /// A position in the original query. |
| 288 | + Normal(u32), |
| 289 | + /// A position in an internally generated query. |
| 290 | + Internal { |
| 291 | + /// The byte position. |
| 292 | + position: u32, |
| 293 | + /// A query generated by the Postgres server. |
| 294 | + query: String, |
| 295 | + }, |
| 296 | +} |
| 297 | + |
302 | 298 | /// Reasons a new Postgres connection could fail.
|
303 | 299 | #[derive(Debug)]
|
304 | 300 | pub enum ConnectError {
|
@@ -355,75 +351,3 @@ impl From<DbError> for ConnectError {
|
355 | 351 | ConnectError::Db(Box::new(err))
|
356 | 352 | }
|
357 | 353 | }
|
358 |
| - |
359 |
| -/// Represents the position of an error in a query. |
360 |
| -#[derive(Clone, PartialEq, Eq, Debug)] |
361 |
| -pub enum ErrorPosition { |
362 |
| - /// A position in the original query. |
363 |
| - Normal(u32), |
364 |
| - /// A position in an internally generated query. |
365 |
| - Internal { |
366 |
| - /// The byte position. |
367 |
| - position: u32, |
368 |
| - /// A query generated by the Postgres server. |
369 |
| - query: String, |
370 |
| - }, |
371 |
| -} |
372 |
| - |
373 |
| -/// An error encountered when communicating with the Postgres server. |
374 |
| -#[derive(Debug)] |
375 |
| -pub enum Error { |
376 |
| - /// An error reported by the Postgres server. |
377 |
| - Db(Box<DbError>), |
378 |
| - /// An error communicating with the Postgres server. |
379 |
| - Io(io::Error), |
380 |
| - /// An error converting between Postgres and Rust types. |
381 |
| - Conversion(Box<error::Error + Sync + Send>), |
382 |
| -} |
383 |
| - |
384 |
| -impl fmt::Display for Error { |
385 |
| - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { |
386 |
| - try!(fmt.write_str(error::Error::description(self))); |
387 |
| - match *self { |
388 |
| - Error::Db(ref err) => write!(fmt, ": {}", err), |
389 |
| - Error::Io(ref err) => write!(fmt, ": {}", err), |
390 |
| - Error::Conversion(ref err) => write!(fmt, ": {}", err), |
391 |
| - } |
392 |
| - } |
393 |
| -} |
394 |
| - |
395 |
| -impl error::Error for Error { |
396 |
| - fn description(&self) -> &str { |
397 |
| - match *self { |
398 |
| - Error::Db(_) => "Error reported by Postgres", |
399 |
| - Error::Io(_) => "Error communicating with the server", |
400 |
| - Error::Conversion(_) => "Error converting between Postgres and Rust types", |
401 |
| - } |
402 |
| - } |
403 |
| - |
404 |
| - fn cause(&self) -> Option<&error::Error> { |
405 |
| - match *self { |
406 |
| - Error::Db(ref err) => Some(&**err), |
407 |
| - Error::Io(ref err) => Some(err), |
408 |
| - Error::Conversion(ref err) => Some(&**err), |
409 |
| - } |
410 |
| - } |
411 |
| -} |
412 |
| - |
413 |
| -impl From<DbError> for Error { |
414 |
| - fn from(err: DbError) -> Error { |
415 |
| - Error::Db(Box::new(err)) |
416 |
| - } |
417 |
| -} |
418 |
| - |
419 |
| -impl From<io::Error> for Error { |
420 |
| - fn from(err: io::Error) -> Error { |
421 |
| - Error::Io(err) |
422 |
| - } |
423 |
| -} |
424 |
| - |
425 |
| -impl From<Error> for io::Error { |
426 |
| - fn from(err: Error) -> io::Error { |
427 |
| - io::Error::new(io::ErrorKind::Other, err) |
428 |
| - } |
429 |
| -} |
0 commit comments