urlyy commented on code in PR #2765:
URL: https://github.com/apache/fory/pull/2765#discussion_r2428609159
##########
rust/fory-core/src/error.rs:
##########
@@ -15,38 +15,102 @@
// specific language governing permissions and limitations
// under the License.
+use std::borrow::Cow;
+
use thiserror::Error;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum Error {
- #[error("Fory on Rust not support Ref type")]
- Ref,
+ // not use this, just as a example.
+ // You can create new error enums for specific cases in the future.
+ #[error("Type mismatch: type_a = {0}, type_b = {1}")]
+ TypeMismatch(u32, u32),
+ // don't use this directly, use Error::from() instead
#[error(transparent)]
- Other(#[from] anyhow::Error),
+ Wrapped(#[from] anyhow::Error),
Review Comment:
> it looks a little strange that an Error type named as `Wrapped`
I just want to use `anyhow` to transform Error. And this is actually strange
and maybe low-perf. I will remove this , just add `From` when need to transform
other Error to fory-Error. Here is a demo:
```rust
use thiserror::Error;
use std::io;
#[derive(Error, Debug)]
enum MyError {
#[error("IO error: {0}")]
Io(#[from] io::Error),
#[error("Other error: {0}")]
Msg(String),
}
fn read_file() -> Result<String, MyError> {
let content = std::fs::read_to_string("foo.txt")?;
Ok(content)
}
```
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]