-
Notifications
You must be signed in to change notification settings - Fork 510
feat: refactor use of Error::io #5612
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
wjones127
left a comment
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 for starting this. I have several suggestions.
Feel free to suggest that we add or change an error type. For example, maybe we want to make a more general NotFound error that's separate from FileNotFound error.
| pub fn not_found(message: impl Into<String>, location: Location) -> Self { | ||
| let message: String = message.into(); | ||
| Self::NotFound { | ||
| uri: message, | ||
| location, | ||
| } |
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.
We could probably simplify this a lot by just using std::panic::Location::caller(). This can even be applied to existing variants.
| pub fn not_found(message: impl Into<String>, location: Location) -> Self { | |
| let message: String = message.into(); | |
| Self::NotFound { | |
| uri: message, | |
| location, | |
| } | |
| pub fn not_found(uri: impl Into<String>) -> Self { | |
| Self::NotFound { | |
| uri: uri.into(), | |
| location: std::panic::Location::caller().to_snafu_location(), | |
| } |
| // Regular data column - validate it exists in base schema | ||
| if base.schema().field(&field.name).is_none() { | ||
| return Err(Error::io( | ||
| return Err(Error::not_found( |
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.
The not_found error is really a FileNotFound error, so doesn't apply here.
| return Err(Error::not_found( | |
| return Err(Error::invalid_input( |
| batch.column_by_name(&field.name).ok_or_else(|| { | ||
| Error::io( | ||
| format!("FileWriter::write: Field '{}' not found", field.name), | ||
| Error::not_found( |
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.
| Error::not_found( | |
| Error::invalid_input( |
| })?; | ||
|
|
||
| let value_arr = dict_info.values.as_ref().ok_or_else(|| { | ||
| Error::io( |
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.
Missed one here:
| Error::io( | |
| Error::invalid_input( |
| Error::io( | ||
| format!( | ||
| "Lance field {} is dictionary type, but misses the dictionary value array", | ||
| "Lance field {} is dictionary type, but misses the dictionary value array", |
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.
We should probably make it standard that we wrap the field names in quotes:
| "Lance field {} is dictionary type, but misses the dictionary value array", | |
| "Lance field '{}' is dictionary type, but misses the dictionary value array", |
| ) -> Result<&'a PageInfo> { | ||
| page_table.get(field.id, batch_id).ok_or_else(|| { | ||
| Error::io( | ||
| Error::not_found( |
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.
| Error::not_found( | |
| Error::invalid_input( |
|
|
||
| if buf.len() < 16 { | ||
| return Err(Error::io( | ||
| return Err(Error::invalid_input( |
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 seems like it might be corrupt file to me.
| return Err(Error::invalid_input( | |
| return Err(Error::corrupt_file( |
| } | ||
| if !buf.ends_with(MAGIC) { | ||
| return Err(Error::io( | ||
| return Err(Error::invalid_input( |
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.
Same here:
| return Err(Error::invalid_input( | |
| return Err(Error::corrupt_file( |
fix #5601