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 ,
@@ -108,31 +117,6 @@ impl From<crate::de::Error> for Error {
108117 }
109118}
110119
111- /// The types of errors that can occur when attempting to access a value in a document.
112- #[ derive( Clone , Debug , Error ) ]
113- #[ non_exhaustive]
114- pub enum ValueAccessErrorKind {
115- /// No value for the specified key was present in the document.
116- #[ error( "The key was not present in the document" ) ]
117- NotPresent ,
118-
119- /// The type of the value in the document did not match the requested type.
120- #[ error( "Expected type {expected:?}, got type {actual:?}" ) ]
121- #[ non_exhaustive]
122- UnexpectedType {
123- /// The actual type of the value.
124- actual : ElementType ,
125-
126- /// The expected type of the value.
127- expected : ElementType ,
128- } ,
129-
130- /// An error occurred when attempting to parse the document's BSON bytes.
131- #[ error( "{message}" ) ]
132- #[ non_exhaustive]
133- InvalidBson { message : String } ,
134- }
135-
136120impl Error {
137121 pub ( crate ) fn with_key ( mut self , key : impl Into < String > ) -> Self {
138122 self . key = Some ( key. into ( ) ) ;
@@ -144,27 +128,6 @@ impl Error {
144128 self
145129 }
146130
147- pub ( crate ) fn value_access_not_present ( ) -> Self {
148- ErrorKind :: ValueAccess {
149- kind : ValueAccessErrorKind :: NotPresent ,
150- }
151- . into ( )
152- }
153-
154- pub ( crate ) fn value_access_unexpected_type ( actual : ElementType , expected : ElementType ) -> Self {
155- ErrorKind :: ValueAccess {
156- kind : ValueAccessErrorKind :: UnexpectedType { actual, expected } ,
157- }
158- . into ( )
159- }
160-
161- pub ( crate ) fn value_access_invalid_bson ( message : String ) -> Self {
162- ErrorKind :: ValueAccess {
163- kind : ValueAccessErrorKind :: InvalidBson { message } ,
164- }
165- . into ( )
166- }
167-
168131 pub ( crate ) fn malformed_bytes ( message : impl ToString ) -> Self {
169132 ErrorKind :: MalformedBytes {
170133 message : message. to_string ( ) ,
@@ -178,26 +141,4 @@ impl Error {
178141 }
179142 . into ( )
180143 }
181-
182- #[ cfg( test) ]
183- pub ( crate ) fn is_value_access_not_present ( & self ) -> bool {
184- matches ! (
185- self . kind,
186- ErrorKind :: ValueAccess {
187- kind: ValueAccessErrorKind :: NotPresent ,
188- ..
189- }
190- )
191- }
192-
193- #[ cfg( test) ]
194- pub ( crate ) fn is_value_access_unexpected_type ( & self ) -> bool {
195- matches ! (
196- self . kind,
197- ErrorKind :: ValueAccess {
198- kind: ValueAccessErrorKind :: UnexpectedType { .. } ,
199- ..
200- }
201- )
202- }
203144}
0 commit comments