-
Notifications
You must be signed in to change notification settings - Fork 1k
AvroError enum for arrow-avro crate #8759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @nathaniel-d-ef -- I think this makes sense to me, but it is a breaking API change and thus we will have to wait until the next major release in a few months:
FYI @jecsand838 and @mbrobbel
arrow-avro/src/errors.rs
Outdated
| EOF(String), | ||
| /// Arrow error. | ||
| /// Returned when reading into arrow or writing from arrow. | ||
| ArrowError(String), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this instead keep the actual Arrow error rather than converting directly into a string?
| ArrowError(String), | |
| ArrowError(Box<ArrowError>)), |
I realize that is what ParquetError::ArrowError does the same thing -- but I think we might want to change that Parquet error as well
arrow-avro/src/errors.rs
Outdated
| } | ||
| } | ||
|
|
||
| impl From<cell::BorrowMutError> for AvroError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a fairly specific conversion -- maybe it would be simpler to annotate the locations where this happens with map_err(|e| AvroError::From(Box::new(e)) 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, my mistake. This is unnecessary, I removed.
| } | ||
| return out | ||
| .write_all(&src_be[extra..]) | ||
| .map_err(|e| ArrowError::IoError(format!("write decimal fixed: {e}"), e)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change does appear to lose some error context. Would it be better to keep the information that this came from write decimal fixed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good point. I adjusted this to use the General error and pass the contextual info.
|
@nathaniel-d-ef I'll do a deeper review tonight, but if we plan to go this direction, should we also remove the I never got around to wiring that up before public release. But the original intent was to align CC: @alamb |
| impl From<ArrowError> for AvroError { | ||
| fn from(e: ArrowError) -> AvroError { | ||
| AvroError::External(Box::new(e)) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nathaniel-d-ef I'd consider doing something like this:
| impl From<ArrowError> for AvroError { | |
| fn from(e: ArrowError) -> AvroError { | |
| AvroError::External(Box::new(e)) | |
| } | |
| } | |
| pub enum AvroError { | |
| // ... | |
| ArrowError(Box<ArrowError>), | |
| // ... | |
| } | |
| impl From<ArrowError> for AvroError { | |
| fn from(e: ArrowError) -> Self { | |
| AvroError::ArrowError(Box::new(e)) | |
| } | |
| } | |
| impl std::error::Error for AvroError { | |
| fn source(&self) -> Option<&(dyn Error + 'static)> { | |
| match self { | |
| AvroError::External(e) => Some(e.as_ref()), | |
| AvroError::ArrowError(e) => Some(e.as_ref()), | |
| _ => None, | |
| } | |
| } | |
| } |
| impl From<AvroError> for ArrowError { | ||
| fn from(p: AvroError) -> Self { | ||
| Self::AvroError(format!("{p}")) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then down here, you can also do this:
| impl From<AvroError> for ArrowError { | |
| fn from(p: AvroError) -> Self { | |
| Self::AvroError(format!("{p}")) | |
| } | |
| } | |
| impl From<AvroError> for ArrowError { | |
| fn from(e: AvroError) -> Self { | |
| match e { | |
| AvroError::External(inner) => ArrowError::from_external_error(inner), | |
| AvroError::ArrowError(inner) => ArrowError::from_external_error(inner), | |
| other => ArrowError::AvroError(other.to_string()), | |
| } | |
| } | |
| } |
I see what you mean. I don't feel strongly either way. On the whole we're probably unlikely to use all of the variants here, so if it's preferable to roll this back a bit and implement the |
Which issue does this PR close?
Rationale for this change
The arrow-avro crate currently uses
ArrowErrorthroughout. This lacks the level of precision other crates in the project, such as Parquet, have.What changes are included in this PR?
Resultutility on the AvroError allows for Result<T, AvroError> to be written as Result.Are these changes tested?
No new functionality has been introduced, all existing tests are passing.
Are there any user-facing changes?
There shouldn't be - the API signatures remain the same.