martin-g commented on code in PR #230:
URL: https://github.com/apache/avro-rs/pull/230#discussion_r2218256648
##########
avro/src/error.rs:
##########
@@ -21,8 +21,1154 @@ use crate::{
};
use std::{error::Error as _, fmt};
+/// Errors encounterd by Avro.
+///
+/// To inspect the details of the error use [`details`](Self::details) or
[`into_details`](Self::into_details)
+/// to get a [`Details`] which contains more precise error information.
+///
+/// See [`Details`] for all possible errors.
+#[derive(thiserror::Error, Debug)]
+#[repr(transparent)]
+#[error(transparent)]
+pub struct Error {
+ details: Box<Details>,
+}
+
+impl Error {
+ pub fn new(details: Details) -> Self {
+ Self {
+ details: Box::new(details),
+ }
+ }
+
+ pub fn details(&self) -> &Details {
+ &self.details
+ }
+
+ pub fn into_details(self) -> Details {
+ *self.details
+ }
+}
+
+/// Functions for constructing a specific error type.
+#[allow(non_snake_case, reason = "Want to mimic the `Details` variants")]
+impl Error {
+ /// Construct a new [`Error`] with a [`Details::SnappyCrc32`].
+ pub fn SnappyCrc32(expected: u32, actual: u32) -> Self {
Review Comment:
I wonder whether we really need to have these public factory methods.
Usually the library creates the "instance". The user applications
check/match the error.
But even if the user applications need to create an instance they could
replace `Error::Xyz{...}` with `Details::Xyz{...}.into()`, i.e.
`s/Error/Details` and append `.into()`. We could use the same in the library
too.
##########
avro/src/lib.rs:
##########
@@ -896,7 +896,7 @@ pub use codec::{Codec, DeflateSettings};
pub use de::from_value;
pub use decimal::Decimal;
pub use duration::{Days, Duration, Millis, Months};
-pub use error::Error;
+pub use error::{Details, Error};
Review Comment:
It is not very clear that `apache_avro::Details` is about Error's details.
IMO we should either export it as `apache_avro::ErrorDetails` or not export
it at all and the end users should use it as `apache_avro::error::Details`. I
think I like the latter better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]