@@ -466,60 +466,24 @@ pub enum ErrorPosition {
466466 }
467467}
468468
469- /// Encapsulates a Postgres error or notice.
469+ /// A Postgres error or notice.
470470#[ derive( Clone , PartialEq , Eq , Debug ) ]
471471pub struct DbError {
472- /// The field contents are ERROR, FATAL, or PANIC (in an error message),
473- /// or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a
474- /// localized translation of one of these.
475- pub severity : String ,
476- /// The SQLSTATE code for the error.
477- pub code : SqlState ,
478- /// The primary human-readable error message. This should be accurate but
479- /// terse (typically one line).
480- pub message : String ,
481- /// An optional secondary error message carrying more detail about the
482- /// problem. Might run to multiple lines.
483- pub detail : Option < String > ,
484- /// An optional suggestion what to do about the problem. This is intended
485- /// to differ from Detail in that it offers advice (potentially
486- /// inappropriate) rather than hard facts. Might run to multiple lines.
487- pub hint : Option < String > ,
488- /// An optional error cursor position into either the original query string
489- /// or an internally generated query.
490- pub position : Option < ErrorPosition > ,
491- /// An indication of the context in which the error occurred. Presently
492- /// this includes a call stack traceback of active procedural language
493- /// functions and internally-generated queries. The trace is one entry per
494- /// line, most recent first.
495- pub where_ : Option < String > ,
496- /// If the error was associated with a specific database object, the name
497- /// of the schema containing that object, if any. (PostgreSQL 9.3+)
498- pub schema : Option < String > ,
499- /// If the error was associated with a specific table, the name of the
500- /// table. (Refer to the schema name field for the name of the table's
501- /// schema.) (PostgreSQL 9.3+)
502- pub table : Option < String > ,
503- /// If the error was associated with a specific table column, the name of
504- /// the column. (Refer to the schema and table name fields to identify the
505- /// table.) (PostgreSQL 9.3+)
506- pub column : Option < String > ,
507- /// If the error was associated with a specific data type, the name of the
508- /// data type. (Refer to the schema name field for the name of the data
509- /// type's schema.) (PostgreSQL 9.3+)
510- pub datatype : Option < String > ,
511- /// If the error was associated with a specific constraint, the name of the
512- /// constraint. Refer to fields listed above for the associated table or
513- /// domain. (For this purpose, indexes are treated as constraints, even if
514- /// they weren't created with constraint syntax.) (PostgreSQL 9.3+)
515- pub constraint : Option < String > ,
516- /// The file name of the source-code location where the error was reported.
517- pub file : String ,
518- /// The line number of the source-code location where the error was
519- /// reported.
520- pub line : usize ,
521- /// The name of the source-code routine reporting the error.
522- pub routine : String
472+ severity : String ,
473+ code : SqlState ,
474+ message : String ,
475+ detail : Option < String > ,
476+ hint : Option < String > ,
477+ position : Option < ErrorPosition > ,
478+ where_ : Option < String > ,
479+ schema : Option < String > ,
480+ table : Option < String > ,
481+ column : Option < String > ,
482+ datatype : Option < String > ,
483+ constraint : Option < String > ,
484+ file : String ,
485+ line : u32 ,
486+ routine : String
523487}
524488
525489impl DbError {
@@ -569,6 +533,102 @@ impl DbError {
569533 Err ( ( ) ) => Err ( Error :: BadData ) ,
570534 }
571535 }
536+
537+ /// The field contents are ERROR, FATAL, or PANIC (in an error message),
538+ /// or WARNING, NOTICE, DEBUG, INFO, or LOG (in a notice message), or a
539+ /// localized translation of one of these.
540+ pub fn severity ( & self ) -> & str {
541+ & self . severity
542+ }
543+
544+ /// The SQLSTATE code for the error.
545+ pub fn code ( & self ) -> & SqlState {
546+ & self . code
547+ }
548+
549+ /// The primary human-readable error message. This should be accurate but
550+ /// terse (typically one line).
551+ pub fn message ( & self ) -> & str {
552+ & self . message
553+ }
554+
555+ /// An optional secondary error message carrying more detail about the
556+ /// problem. Might run to multiple lines.
557+ pub fn detail ( & self ) -> Option < & str > {
558+ self . detail . as_ref ( ) . map ( |s| & * * s)
559+ }
560+
561+ /// An optional suggestion what to do about the problem. This is intended
562+ /// to differ from Detail in that it offers advice (potentially
563+ /// inappropriate) rather than hard facts. Might run to multiple lines.
564+ pub fn hint ( & self ) -> Option < & str > {
565+ self . hint . as_ref ( ) . map ( |s| & * * s)
566+ }
567+
568+ /// An optional error cursor position into either the original query string
569+ /// or an internally generated query.
570+ pub fn position ( & self ) -> Option < & ErrorPosition > {
571+ self . position . as_ref ( )
572+ }
573+
574+ /// An indication of the context in which the error occurred. Presently
575+ /// this includes a call stack traceback of active procedural language
576+ /// functions and internally-generated queries. The trace is one entry per
577+ /// line, most recent first.
578+ pub fn where_ ( & self ) -> Option < & str > {
579+ self . where_ . as_ref ( ) . map ( |s| & * * s)
580+ }
581+
582+ /// If the error was associated with a specific database object, the name
583+ /// of the schema containing that object, if any. (PostgreSQL 9.3+)
584+ pub fn schema ( & self ) -> Option < & str > {
585+ self . schema . as_ref ( ) . map ( |s| & * * s)
586+ }
587+
588+ /// If the error was associated with a specific table, the name of the
589+ /// table. (Refer to the schema name field for the name of the table's
590+ /// schema.) (PostgreSQL 9.3+)
591+ pub fn table ( & self ) -> Option < & str > {
592+ self . table . as_ref ( ) . map ( |s| & * * s)
593+ }
594+
595+ /// If the error was associated with a specific table column, the name of
596+ /// the column. (Refer to the schema and table name fields to identify the
597+ /// table.) (PostgreSQL 9.3+)
598+ pub fn column ( & self ) -> Option < & str > {
599+ self . column . as_ref ( ) . map ( |s| & * * s)
600+ }
601+
602+ /// If the error was associated with a specific data type, the name of the
603+ /// data type. (Refer to the schema name field for the name of the data
604+ /// type's schema.) (PostgreSQL 9.3+)
605+ pub fn datatype ( & self ) -> Option < & str > {
606+ self . datatype . as_ref ( ) . map ( |s| & * * s)
607+ }
608+
609+ /// If the error was associated with a specific constraint, the name of the
610+ /// constraint. Refer to fields listed above for the associated table or
611+ /// domain. (For this purpose, indexes are treated as constraints, even if
612+ /// they weren't created with constraint syntax.) (PostgreSQL 9.3+)
613+ pub fn constraint ( & self ) -> Option < & str > {
614+ self . constraint . as_ref ( ) . map ( |s| & * * s)
615+ }
616+
617+ /// The file name of the source-code location where the error was reported.
618+ pub fn file ( & self ) -> & str {
619+ & self . file
620+ }
621+
622+ /// The line number of the source-code location where the error was
623+ /// reported.
624+ pub fn line ( & self ) -> u32 {
625+ self . line
626+ }
627+
628+ /// The name of the source-code routine reporting the error.
629+ pub fn routine ( & self ) -> & str {
630+ & self . routine
631+ }
572632}
573633
574634impl fmt:: Display for DbError {
0 commit comments