11mod datetime;
2+ mod oid;
23mod uuid;
4+ mod value_access;
35
46use thiserror:: Error ;
57
6- use crate :: spec:: ElementType ;
7-
88pub use datetime:: DateTimeErrorKind ;
9+ pub use oid:: ObjectIdErrorKind ;
910pub use uuid:: UuidErrorKind ;
11+ pub use value_access:: ValueAccessErrorKind ;
1012
1113pub type Result < T > = std:: result:: Result < T , Error > ;
1214
@@ -63,6 +65,13 @@ pub enum ErrorKind {
6365 message : String ,
6466 } ,
6567
68+ /// An error related to the [`ObjectId`](crate::oid::ObjectId) type occurred.
69+ #[ error( "An ObjectId-related error occurred: {kind}" ) ]
70+ ObjectId {
71+ /// The kind of error that occurred.
72+ kind : ObjectIdErrorKind ,
73+ } ,
74+
6675 /// Invalid UTF-8 bytes were encountered.
6776 #[ error( "Invalid UTF-8" ) ]
6877 Utf8Encoding ,
@@ -93,31 +102,6 @@ impl From<ErrorKind> for Error {
93102 }
94103}
95104
96- /// The types of errors that can occur when attempting to access a value in a document.
97- #[ derive( Clone , Debug , Error ) ]
98- #[ non_exhaustive]
99- pub enum ValueAccessErrorKind {
100- /// No value for the specified key was present in the document.
101- #[ error( "The key was not present in the document" ) ]
102- NotPresent ,
103-
104- /// The type of the value in the document did not match the requested type.
105- #[ error( "Expected type {expected:?}, got type {actual:?}" ) ]
106- #[ non_exhaustive]
107- UnexpectedType {
108- /// The actual type of the value.
109- actual : ElementType ,
110-
111- /// The expected type of the value.
112- expected : ElementType ,
113- } ,
114-
115- /// An error occurred when attempting to parse the document's BSON bytes.
116- #[ error( "{message}" ) ]
117- #[ non_exhaustive]
118- InvalidBson { message : String } ,
119- }
120-
121105impl Error {
122106 pub ( crate ) fn with_key ( mut self , key : impl Into < String > ) -> Self {
123107 self . key = Some ( key. into ( ) ) ;
@@ -129,27 +113,6 @@ impl Error {
129113 self
130114 }
131115
132- pub ( crate ) fn value_access_not_present ( ) -> Self {
133- ErrorKind :: ValueAccess {
134- kind : ValueAccessErrorKind :: NotPresent ,
135- }
136- . into ( )
137- }
138-
139- pub ( crate ) fn value_access_unexpected_type ( actual : ElementType , expected : ElementType ) -> Self {
140- ErrorKind :: ValueAccess {
141- kind : ValueAccessErrorKind :: UnexpectedType { actual, expected } ,
142- }
143- . into ( )
144- }
145-
146- pub ( crate ) fn value_access_invalid_bson ( message : String ) -> Self {
147- ErrorKind :: ValueAccess {
148- kind : ValueAccessErrorKind :: InvalidBson { message } ,
149- }
150- . into ( )
151- }
152-
153116 pub ( crate ) fn malformed_bytes ( message : impl ToString ) -> Self {
154117 ErrorKind :: MalformedBytes {
155118 message : message. to_string ( ) ,
@@ -163,26 +126,4 @@ impl Error {
163126 }
164127 . into ( )
165128 }
166-
167- #[ cfg( test) ]
168- pub ( crate ) fn is_value_access_not_present ( & self ) -> bool {
169- matches ! (
170- self . kind,
171- ErrorKind :: ValueAccess {
172- kind: ValueAccessErrorKind :: NotPresent ,
173- ..
174- }
175- )
176- }
177-
178- #[ cfg( test) ]
179- pub ( crate ) fn is_value_access_unexpected_type ( & self ) -> bool {
180- matches ! (
181- self . kind,
182- ErrorKind :: ValueAccess {
183- kind: ValueAccessErrorKind :: UnexpectedType { .. } ,
184- ..
185- }
186- )
187- }
188129}
0 commit comments