-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: more Results, fewer panics, always have backtraces (#761)
fixes #564 The goals of this PR is to ensure the following: - reasonable developer ergonomics / not too verbose - return a `VortexResult` with a well-formed error from most fallible functions - panics are allowed in cases of programmer error / invariants being violated (i.e., panics should correspond logically to places where we might write an `assert`) - ensure a good error message and a backtrace in case of panic To accomplish this, this PR does several things. First, it adds much stricter clippy lints (e.g., deny on `unwrap`, `expect`, `panic`; forbids fallible `From` impls; etc.). 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 #765 For places where we truly want to panic (specifically because an internal invariant has been violated, typically indicating programmer error), this PR adds: - a new macro (`vortex_panic!`) - `VortexUnwrap` trait, which is implemented only on `VortexResult` and adds a `vortex_unwrap()` function - `VortexExpect` trait, which is implemented on `VortexResult` and `Option<T>` and adds a `vortex_expect` function that takes a string literal Basically, the state after this PR is one-off good. 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 result functions... 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` and `vortex_expect` with `expect` and un-deny `expect_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 do `unwrap_or_else(|err| vortex_panic!(err))` or `ok_or_else(|| vortex_panic!(...))` everywhere, but that's pretty verbose. --------- Co-authored-by: Robert Kruszewski <[email protected]> Co-authored-by: Adam Gutglick <[email protected]>
- Loading branch information
1 parent
a82eb07
commit 2c3da0c
Showing
145 changed files
with
1,223 additions
and
761 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
#![allow(clippy::use_debug)] | ||
|
||
use std::collections::HashMap; | ||
use std::process::ExitCode; | ||
use std::sync; | ||
|
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
allow-expect-in-tests = true | ||
allow-unwrap-in-tests = true |
This file contains 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 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.