forked from flavray/avro-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes flavray#115 This is still a WIP branch, with lots of TODOs and some things about thiserror I still can't wrap my head around. However, the heavy-lifting is done, the failure crate has been removed from the list of dependencies and compilation, tests, benchmarks and linting are all green. The two biggest things I have yet to figure out are: 1. How to deal with the errors manually defined in ser.rs and de.rs: they are publicly available and as soon as I touch anything I hit cryptic serde errors 2. How to make errors like TryFromIntError part of more abstract ones like ParseSchemaError, which could have a source error or just a String description.
- Loading branch information
Showing
14 changed files
with
414 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use crate::de; | ||
use crate::ser; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
/// Error type returned from the library | ||
pub enum AvroError { | ||
/// Represents all cases of `std::io::Error` | ||
#[error(transparent)] | ||
IOError(#[from] std::io::Error), | ||
|
||
/// Describes errors happened while decoding Avro data (except for `std::io::Error`) | ||
#[error("Decoding error: {0}")] | ||
DecodeError(String), | ||
|
||
/// Describes errors happened while parsing Avro schemas | ||
#[error("Failed to parse schema: {0}")] | ||
ParseSchemaError(String), | ||
|
||
/// Describes errors happened while performing schema resolution on Avro data. | ||
#[error("Schema resolution error: {0}")] | ||
SchemaResolutionError(String), | ||
|
||
/// Describes errors happened while validating Avro data. | ||
#[error("Validation error: {0}")] | ||
ValidationError(String), | ||
|
||
// TODO: figure out how to move the implementation of this error here | ||
/// Describes errors that could be encountered while serializing data | ||
#[error(transparent)] | ||
SerError(#[from] ser::Error), | ||
|
||
// TODO: figure out how to move the implementation of this error here | ||
/// Describes errors that could be encountered while serializing data | ||
#[error(transparent)] | ||
DeError(#[from] de::Error), | ||
|
||
// TODO: merge with SerError somehow? | ||
// /// Represents all cases of `serde::ser::Error` | ||
//#[error(transparent)] | ||
//SerdeSerError(#[from] serde::ser::Error), | ||
/// Describes errors happened trying to allocate too many bytes | ||
#[error("Unable to allocate {desired} bytes (maximum allowed: {maximum})")] | ||
MemoryAllocationError { desired: usize, maximum: usize }, | ||
|
||
/// Represents all cases of `uuid::Error` | ||
#[error(transparent)] | ||
UuidError(#[from] uuid::Error), | ||
|
||
/// Describe a specific error happening with decimal representation | ||
#[error("Number of bytes requested for decimal sign extension {requested} is less than the number of bytes needed to decode {needed}")] | ||
SignExtendError { requested: usize, needed: usize }, | ||
|
||
// TODO: Should this be wrapped by ParseSchemaError somehow? | ||
/// Represents all cases of `std::num::TryFromIntError` | ||
#[error(transparent)] | ||
TryFromIntError(#[from] std::num::TryFromIntError), | ||
|
||
// TODO: Should this be wrapped by ParseSchemaError somehow? | ||
/// Represents all cases of `serde_json::Error` | ||
#[error(transparent)] | ||
JSONError(#[from] serde_json::Error), | ||
|
||
// TODO: Should this be wrapped by SchemaResolutionError somehow? | ||
/// Represents all cases of `std::string::FromUtf8Error` | ||
#[error(transparent)] | ||
FromUtf8Error(#[from] std::string::FromUtf8Error), | ||
|
||
/// Represents errors coming from Snappy encoding and decoding | ||
#[cfg(feature = "snappy")] | ||
#[error(transparent)] | ||
SnappyError(#[from] snap::Error), | ||
} |
Oops, something went wrong.