-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: more Results, fewer panics, always have backtraces #761
Conversation
What do you mean we wouldn’t get backtraces by default using builtin expect? |
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.
LGTM, seems to me like most rust projects end up having something like this and I think it solves most things that bothered me with the current clippy config while still maintaining error context and backtraces
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.
I left some comments about lazy unwraps. I am not convinced this is the best way of doing things but don't know how to do anything better
@@ -190,7 +190,8 @@ pub fn compress_taxi_data() -> Array { | |||
let chunks = reader | |||
.into_iter() | |||
.map(|batch_result| batch_result.unwrap()) | |||
.map(Array::from) | |||
.map(Array::try_from) | |||
.map(Result::unwrap) |
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.
should collect errors and unwrap at the ends
@@ -45,7 +45,7 @@ pub fn data_vortex_uncompressed(fname_out: &str, downloaded_data: PathBuf) -> Pa | |||
let array = ChunkedArray::try_new( | |||
reader | |||
.into_iter() | |||
.map(|batch_result| Array::from(batch_result.unwrap())) | |||
.map(|batch_result| Array::try_from(batch_result.unwrap()).unwrap()) |
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.
collect errors and unwrap at the end
@@ -101,7 +102,7 @@ pub fn compress_parquet_to_vortex(parquet_path: &Path) -> VortexResult<ChunkedAr | |||
let chunks = reader | |||
.map(|batch_result| batch_result.unwrap()) | |||
.map(|record_batch| { | |||
let vortex_array = Array::from(record_batch); | |||
let vortex_array = Array::try_from(record_batch).unwrap(); |
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.
should collect errors and unwrap at the end
.map(Array::from) | ||
.map(|a| a.into_struct().unwrap()) | ||
.map(Array::try_from) | ||
.map(|a| a.unwrap().into_struct().unwrap()) |
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.
should collect errors
We're a library. Unless the actual binary sets
Which is just not that helpful |
fixes #564
The goals of this PR is to ensure the following:
VortexResult
with a well-formed error from most fallible functionsassert
)To accomplish this, this PR does several things.
First, it adds much stricter clippy lints (e.g., deny on
unwrap
,expect
,panic
; forbids fallibleFrom
impls; etc.).Second, I did an audit to make functions that are truly fallible return
VortexResult
instead of panicking. The remaining ones that I saw but didn't fix are tracked under #765Third, for places where we truly want to panic (specifically because an internal invariant has been violated, typically indicating programmer error), this PR adds:
vortex_panic!
)VortexUnwrap
trait, which is implemented only onVortexResult
and adds avortex_unwrap()
functionVortexExpect
trait, which is implemented onVortexResult
andOption<T>
and adds avortex_expect
function that takes a string literalTaken together, the main downsides are that we have a special snowflake unwrap/expect instead of the traditional ones, and we don't have an effective lint rule to prevent calling those in functions that return Result... but I think the latter at least is acceptable (I know @AdamGS finds those lints overly restrictive anyway).
ALTERNATIVELY, a middle ground would be to replace calls to
vortex_unwrap
andvortex_expect
withexpect
and un-denyexpect_used
. This would be more "typical" Rust but with the disadvantage that we wouldn't get backtraces by default in the cases where we have bugs. Or we could dounwrap_or_else(|err| vortex_panic!(err))
orok_or_else(|| vortex_panic!(...))
everywhere, but that's pretty verbose.