-
Notifications
You must be signed in to change notification settings - Fork 1.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
Open
nathaniel-d-ef
wants to merge
11
commits into
apache:main
Choose a base branch
from
elastiflow:avro-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+543
−418
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
147503f
adds AvroError variant to arrow-avro crate
nathaniel-d-ef 29dd74e
Replace `ArrowError` with `AvroError` and adjust error handling throu…
nathaniel-d-ef ab4e4ee
Cleanup, apply suggestions
nathaniel-d-ef 1cc51f1
Remove redundant newline
nathaniel-d-ef 25d97a7
adds IO error variant, applies suggestions
nathaniel-d-ef d8c43b0
Refactor: Replace `ArrowError` with `AvroError` and update error hand…
nathaniel-d-ef a370934
fmt fixes
nathaniel-d-ef 0814991
Refactor: Remove custom return type, change boundary error type, and …
nathaniel-d-ef d9ffeff
Refactor: Update test function return types in arrow-avro reader module
nathaniel-d-ef 5fd287b
chore: fmt fix
nathaniel-d-ef 5db71e5
Merge branch 'main' into avro-error
nathaniel-d-ef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,148 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| //! Common Avro errors and macros. | ||
|
|
||
| use arrow_schema::ArrowError; | ||
| use core::num::TryFromIntError; | ||
| use std::error::Error; | ||
| use std::string::FromUtf8Error; | ||
| use std::{io, str}; | ||
|
|
||
| /// Avro error enumeration | ||
|
|
||
| #[derive(Debug)] | ||
| #[non_exhaustive] | ||
| pub enum AvroError { | ||
| /// General Avro error. | ||
| /// Returned when code violates normal workflow of working with Avro data. | ||
| General(String), | ||
| /// "Not yet implemented" Avro error. | ||
| /// Returned when functionality is not yet available. | ||
| NYI(String), | ||
| /// "End of file" Avro error. | ||
| /// Returned when IO related failures occur, e.g. when there are not enough bytes to | ||
| /// decode. | ||
| EOF(String), | ||
| /// Arrow error. | ||
| /// Returned when reading into arrow or writing from arrow. | ||
| ArrowError(Box<ArrowError>), | ||
| /// Error when the requested index is more than the | ||
| /// number of items expected | ||
| IndexOutOfBound(usize, usize), | ||
| /// Error indicating that an unexpected or bad argument was passed to a function. | ||
| InvalidArgument(String), | ||
| /// Error indicating that a value could not be parsed. | ||
| ParseError(String), | ||
| /// Error indicating that a schema is invalid. | ||
| SchemaError(String), | ||
| /// An external error variant | ||
| External(Box<dyn Error + Send + Sync>), | ||
| /// Error during IO operations | ||
| IoError(String, io::Error), | ||
| /// Returned when a function needs more data to complete properly. The `usize` field indicates | ||
| /// the total number of bytes required, not the number of additional bytes. | ||
| NeedMoreData(usize), | ||
| /// Returned when a function needs more data to complete properly. | ||
| /// The `Range<u64>` indicates the range of bytes that are needed. | ||
| NeedMoreDataRange(std::ops::Range<u64>), | ||
| } | ||
|
|
||
| impl std::fmt::Display for AvroError { | ||
| fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
| match &self { | ||
| AvroError::General(message) => { | ||
| write!(fmt, "Avro error: {message}") | ||
| } | ||
| AvroError::NYI(message) => write!(fmt, "NYI: {message}"), | ||
| AvroError::EOF(message) => write!(fmt, "EOF: {message}"), | ||
| AvroError::ArrowError(message) => write!(fmt, "Arrow: {message}"), | ||
| AvroError::IndexOutOfBound(index, bound) => { | ||
| write!(fmt, "Index {index} out of bound: {bound}") | ||
| } | ||
| AvroError::InvalidArgument(message) => { | ||
| write!(fmt, "Invalid argument: {message}") | ||
| } | ||
| AvroError::ParseError(message) => write!(fmt, "Parser error: {message}"), | ||
| AvroError::SchemaError(message) => write!(fmt, "Schema error: {message}"), | ||
| AvroError::External(e) => write!(fmt, "External: {e}"), | ||
| AvroError::IoError(message, e) => write!(fmt, "I/O Error: {message}: {e}"), | ||
| AvroError::NeedMoreData(needed) => write!(fmt, "NeedMoreData: {needed}"), | ||
| AvroError::NeedMoreDataRange(range) => { | ||
| write!(fmt, "NeedMoreDataRange: {}..{}", range.start, range.end) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl 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()), | ||
| AvroError::IoError(_, e) => Some(e), | ||
| _ => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<TryFromIntError> for AvroError { | ||
| fn from(e: TryFromIntError) -> AvroError { | ||
| AvroError::General(format!("Integer overflow: {e}")) | ||
| } | ||
| } | ||
|
|
||
| impl From<io::Error> for AvroError { | ||
| fn from(e: io::Error) -> AvroError { | ||
| AvroError::External(Box::new(e)) | ||
| } | ||
| } | ||
|
|
||
| impl From<str::Utf8Error> for AvroError { | ||
| fn from(e: str::Utf8Error) -> AvroError { | ||
| AvroError::External(Box::new(e)) | ||
| } | ||
| } | ||
|
|
||
| impl From<FromUtf8Error> for AvroError { | ||
| fn from(e: FromUtf8Error) -> AvroError { | ||
| AvroError::External(Box::new(e)) | ||
| } | ||
| } | ||
|
|
||
| impl From<ArrowError> for AvroError { | ||
| fn from(e: ArrowError) -> Self { | ||
| AvroError::ArrowError(Box::new(e)) | ||
| } | ||
| } | ||
|
|
||
| impl From<AvroError> for io::Error { | ||
| fn from(e: AvroError) -> Self { | ||
| io::Error::other(e) | ||
| } | ||
| } | ||
|
|
||
| impl From<AvroError> for ArrowError { | ||
| fn from(e: AvroError) -> Self { | ||
| match e { | ||
| AvroError::External(inner) => ArrowError::from_external_error(inner), | ||
| AvroError::IoError(msg, err) => ArrowError::IoError(msg, err), | ||
| AvroError::ArrowError(inner) => *inner, | ||
| other => ArrowError::AvroError(other.to_string()), | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -195,6 +195,9 @@ pub mod compression; | |||||
| /// Avro data types and Arrow data types. | ||||||
| pub mod codec; | ||||||
|
|
||||||
| /// AvroError variants | ||||||
| pub mod errors; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, if internal only, then should we make this change?
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||||||
|
|
||||||
| /// Extension trait for AvroField to add Utf8View support | ||||||
| /// | ||||||
| /// This trait adds methods for working with Utf8View support to the AvroField struct. | ||||||
|
|
||||||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If these errors are internal only, then why make this
pub?My preference would be to return
pubif possible (like in theparquetcrate), but if we can't shouldn't we make thispub(crate)?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.
Left this alone having changed the boundary type.