forked from apache/avro
-
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.
Move from failure to thiserror (#135)
* Move from failure to thiserror Closes #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. * Update tests/io.rs Co-authored-by: Joel Höner <joel@zyantific.com> * Renaming errors + apply clippy consistently Rename AvroError to Error Removed redundant Error suffix from variants Introduce AvroResult shorthand alias with crate visibility Align clippy invocation in tests with the one in pre-commits * Stop stressing about generic errors and add a couple more sprecific ones * Centralize Ser and De errors into Error The trick was implementing the ser::Error and de::Error trait for crate::errors::Error and return Error::Ser and Error::De variants in the implementation of the custom() method. * SnappyCdcError as struct for consistency * Update CHANGELOG * Update CHANGELOG, README and add a Migration Guide page Co-authored-by: Joel Höner <joel@zyantific.com>
- Loading branch information
Showing
21 changed files
with
525 additions
and
480 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
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,79 @@ | ||
# Migration Guide | ||
## Unreleased | ||
- A custom `Error` enum has been introduced to replace all existing errors and | ||
the `failure` crate has been replaced by `thiserror`. | ||
|
||
This means that all public functions returning `Result<T, failure::Error>` | ||
will now return `Result<T, avro::Error>` and that you can pattern match on | ||
`Error` variants if you want to gather more information about the error. | ||
|
||
For example, code that used to be like this: | ||
```rust | ||
match decoded { | ||
Ok(msg) => Ok(msg.to_string()), | ||
Err(ref e) => match e.downcast_ref::<SchemaResolutionError>() { | ||
Some(_) => Ok("default".to_string()), | ||
None => Err(format!("Unexpected error: {}", e)), | ||
}, | ||
} | ||
``` | ||
|
||
now becomes: | ||
```rust | ||
match decoded { | ||
Ok(msg) => Ok(msg.to_string()), | ||
Err(Error::SchemaResolution(_)) => Ok("default".to_string()), | ||
Err(ref e) => Err(format!("Unexpected error: {}", e)), | ||
} | ||
``` | ||
|
||
Please note that all instances of: | ||
- `DecodeError` | ||
- `ValidationError` | ||
- `DeError` | ||
- `SerError` | ||
- `ParseSchemaError` | ||
- `SchemaResolutionError` | ||
|
||
must be replaced by `Error`. | ||
|
||
- The `ToAvro` trait has been deprecated in favor of `From<T>` for `Value` implementations. | ||
|
||
Code like the following: | ||
```rust | ||
use crate::types::{Record, ToAvro, Value}; | ||
|
||
let expected: Value = record.avro(); | ||
``` | ||
|
||
should be updated to: | ||
|
||
```rust | ||
use crate::types::{Record, Value}; | ||
|
||
let expected: Value = record.into(); | ||
``` | ||
|
||
Using the `ToAvro` trait will result in a deprecation warning. The trait will | ||
be removed in future versions. | ||
|
||
- The `digest` crate has been updated to version `0.9`. If you were using the | ||
`digest::Digest` trait from version `0.8`, you must update to the one defined | ||
in `0.9`. | ||
|
||
## 0.10.0 | ||
- `Writer::into_inner()` now calls `flush()` and returns a `Result`. | ||
|
||
This means that code like | ||
```rust | ||
writer.append_ser(test)?; | ||
writer.flush()?; | ||
let input = writer.into_inner(); | ||
``` | ||
|
||
can be simplified into | ||
```rust | ||
writer.append_ser(test)?; | ||
let input = writer.into_inner()?; | ||
``` | ||
There is no harm in leaving old calls to `flush()` around. |
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
Oops, something went wrong.