@@ -16,21 +16,21 @@ macro_rules! make_errors(
16
16
/// SQLSTATE error codes
17
17
#[ deriving( PartialEq , Eq , Clone , Show ) ]
18
18
#[ allow( missing_docs) ]
19
- pub enum PostgresSqlState {
19
+ pub enum SqlState {
20
20
$( $error, ) +
21
- UnknownSqlState ( String )
21
+ Unknown ( String )
22
22
}
23
23
24
- static STATE_MAP : phf:: Map <& ' static str , PostgresSqlState > = phf_map!(
25
- $( $code => $error) ,+
24
+ static STATE_MAP : phf:: Map <& ' static str , SqlState > = phf_map!(
25
+ $( $code => SqlState :: $error) ,+
26
26
) ;
27
27
28
- impl PostgresSqlState {
28
+ impl SqlState {
29
29
#[ doc( hidden) ]
30
- pub fn from_code( s: & str ) -> PostgresSqlState {
30
+ pub fn from_code( s: & str ) -> SqlState {
31
31
match STATE_MAP . find_equiv( s) {
32
32
Some ( state) => state. clone( ) ,
33
- None => UnknownSqlState ( s. into_string( ) )
33
+ None => SqlState :: Unknown ( s. into_string( ) )
34
34
}
35
35
}
36
36
}
@@ -358,15 +358,15 @@ make_errors!(
358
358
359
359
/// Reasons a new Postgres connection could fail
360
360
#[ deriving( Clone , PartialEq , Eq ) ]
361
- pub enum PostgresConnectError {
361
+ pub enum ConnectError {
362
362
/// The provided URL could not be parsed
363
363
InvalidUrl ( String ) ,
364
364
/// The URL was missing a user
365
365
MissingUser ,
366
366
/// There was an error opening a socket to the server
367
367
SocketError ( io:: IoError ) ,
368
368
/// An error from the Postgres server itself
369
- PgConnectDbError ( PostgresDbError ) ,
369
+ PgConnectDbError ( DbError ) ,
370
370
/// A password was required but not provided in the URL
371
371
MissingPassword ,
372
372
/// The Postgres server requested an authentication method not supported
@@ -382,7 +382,7 @@ pub enum PostgresConnectError {
382
382
PgConnectBadResponse ,
383
383
}
384
384
385
- impl fmt:: Show for PostgresConnectError {
385
+ impl fmt:: Show for ConnectError {
386
386
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
387
387
match * self {
388
388
InvalidUrl ( ref err) => write ! ( fmt, "Invalid URL: {}" , err) ,
@@ -408,11 +408,11 @@ impl fmt::Show for PostgresConnectError {
408
408
409
409
/// Represents the position of an error in a query
410
410
#[ deriving( Clone , PartialEq , Eq ) ]
411
- pub enum PostgresErrorPosition {
411
+ pub enum ErrorPosition {
412
412
/// A position in the original query
413
- Position ( uint ) ,
413
+ Normal ( uint ) ,
414
414
/// A position in an internally generated query
415
- InternalPosition {
415
+ Internal {
416
416
/// The byte position
417
417
pub position : uint ,
418
418
/// A query generated by the Postgres server
@@ -422,13 +422,13 @@ pub enum PostgresErrorPosition {
422
422
423
423
/// Encapsulates a Postgres error or notice.
424
424
#[ deriving( Clone , PartialEq , Eq ) ]
425
- pub struct PostgresDbError {
425
+ pub struct DbError {
426
426
/// The field contents are ERROR, FATAL, or PANIC (in an error message),
427
427
/// or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a
428
428
/// localized translation of one of these.
429
429
pub severity : String ,
430
430
/// The SQLSTATE code for the error.
431
- pub code : PostgresSqlState ,
431
+ pub code : SqlState ,
432
432
/// The primary human-readable error message. This should be accurate but
433
433
/// terse (typically one line).
434
434
pub message : String ,
@@ -441,7 +441,7 @@ pub struct PostgresDbError {
441
441
pub hint : Option < String > ,
442
442
/// An optional error cursor position into either the original query string
443
443
/// or an internally generated query.
444
- pub position : Option < PostgresErrorPosition > ,
444
+ pub position : Option < ErrorPosition > ,
445
445
/// An indication of the context in which the error occurred. Presently
446
446
/// this includes a call stack traceback of active procedural language
447
447
/// functions and internally-generated queries. The trace is one entry per
@@ -476,20 +476,20 @@ pub struct PostgresDbError {
476
476
pub routine : String
477
477
}
478
478
479
- impl PostgresDbError {
479
+ impl DbError {
480
480
#[ doc( hidden) ]
481
- pub fn new_raw ( fields : Vec < ( u8 , String ) > ) -> result:: Result < PostgresDbError , ( ) > {
481
+ pub fn new_raw ( fields : Vec < ( u8 , String ) > ) -> result:: Result < DbError , ( ) > {
482
482
let mut map: HashMap < _ , _ > = fields. into_iter ( ) . collect ( ) ;
483
- Ok ( PostgresDbError {
483
+ Ok ( DbError {
484
484
severity : try!( map. pop ( & b'S' ) . ok_or ( ( ) ) ) ,
485
- code : PostgresSqlState :: from_code ( try!( map. pop ( & b'C' ) . ok_or ( ( ) ) ) [ ] ) ,
485
+ code : SqlState :: from_code ( try!( map. pop ( & b'C' ) . ok_or ( ( ) ) ) [ ] ) ,
486
486
message : try!( map. pop ( & b'M' ) . ok_or ( ( ) ) ) ,
487
487
detail : map. pop ( & b'D' ) ,
488
488
hint : map. pop ( & b'H' ) ,
489
489
position : match map. pop ( & b'P' ) {
490
- Some ( pos) => Some ( Position ( try!( from_str ( pos[ ] ) . ok_or ( ( ) ) ) ) ) ,
490
+ Some ( pos) => Some ( ErrorPosition :: Normal ( try!( from_str ( pos[ ] ) . ok_or ( ( ) ) ) ) ) ,
491
491
None => match map. pop ( & b'p' ) {
492
- Some ( pos) => Some ( InternalPosition {
492
+ Some ( pos) => Some ( ErrorPosition :: Internal {
493
493
position : try!( from_str ( pos[ ] ) . ok_or ( ( ) ) ) ,
494
494
query : try!( map. pop ( & b'q' ) . ok_or ( ( ) ) )
495
495
} ) ,
@@ -509,33 +509,33 @@ impl PostgresDbError {
509
509
}
510
510
511
511
#[ doc( hidden) ]
512
- pub fn new_connect < T > ( fields : Vec < ( u8 , String ) > ) -> result:: Result < T , PostgresConnectError > {
513
- match PostgresDbError :: new_raw ( fields) {
512
+ pub fn new_connect < T > ( fields : Vec < ( u8 , String ) > ) -> result:: Result < T , ConnectError > {
513
+ match DbError :: new_raw ( fields) {
514
514
Ok ( err) => Err ( PgConnectDbError ( err) ) ,
515
515
Err ( ( ) ) => Err ( PgConnectBadResponse ) ,
516
516
}
517
517
}
518
518
519
519
#[ doc( hidden) ]
520
520
pub fn new < T > ( fields : Vec < ( u8 , String ) > ) -> Result < T > {
521
- match PostgresDbError :: new_raw ( fields) {
521
+ match DbError :: new_raw ( fields) {
522
522
Ok ( err) => Err ( PgDbError ( err) ) ,
523
523
Err ( ( ) ) => Err ( PgBadData ) ,
524
524
}
525
525
}
526
526
}
527
527
528
- impl fmt:: Show for PostgresDbError {
528
+ impl fmt:: Show for DbError {
529
529
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
530
530
write ! ( fmt, "{}: {}" , self . severity, self . message)
531
531
}
532
532
}
533
533
534
534
/// An error encountered when communicating with the Postgres server
535
535
#[ deriving( Clone , PartialEq , Eq ) ]
536
- pub enum PostgresError {
536
+ pub enum Error {
537
537
/// An error reported by the Postgres server
538
- PgDbError ( PostgresDbError ) ,
538
+ PgDbError ( DbError ) ,
539
539
/// An error communicating with the Postgres server
540
540
PgStreamError ( io:: IoError ) ,
541
541
/// The communication channel with the Postgres server has desynchronized
@@ -566,7 +566,7 @@ pub enum PostgresError {
566
566
PgBadData ,
567
567
}
568
568
569
- impl fmt:: Show for PostgresError {
569
+ impl fmt:: Show for Error {
570
570
fn fmt ( & self , fmt : & mut fmt:: Formatter ) -> fmt:: Result {
571
571
match * self {
572
572
PgDbError ( ref err) => err. fmt ( fmt) ,
0 commit comments