-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash on reaching line number limit (#3093)
* Fixes: #3075 * Related to: #3076 The second commit is the actual fix. But to avoid this family of crashes, the cpuwritegpuread belt now always does error checks and returns errors instead of paniking * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/3093) (if applicable) - [PR Build Summary](https://build.rerun.io/pr/3093) - [Docs preview](https://rerun.io/preview/b6b737939d3219b0ca32e763d7276b5ca0d504ee/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/b6b737939d3219b0ca32e763d7276b5ca0d504ee/examples) <!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--><!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://ref.rerun.io/dev/bench/) - [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
- Loading branch information
Showing
18 changed files
with
294 additions
and
85 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
pub trait ResultExt<T, E> { | ||
/// Logs an error if the result is an error and returns the result. | ||
fn ok_or_log_error(self) -> Option<T> | ||
where | ||
E: std::fmt::Display; | ||
|
||
/// Unwraps in debug builds otherwise logs an error if the result is an error and returns the result. | ||
fn unwrap_debug_or_log_error(self) -> Option<T> | ||
where | ||
E: std::fmt::Display + std::fmt::Debug; | ||
} | ||
|
||
impl<T, E> ResultExt<T, E> for Result<T, E> { | ||
#[track_caller] | ||
fn ok_or_log_error(self) -> Option<T> | ||
where | ||
E: std::fmt::Display, | ||
{ | ||
match self { | ||
Ok(t) => Some(t), | ||
Err(err) => { | ||
let loc = std::panic::Location::caller(); | ||
log::error!("{}:{} {err}", loc.file(), loc.line()); | ||
None | ||
} | ||
} | ||
} | ||
|
||
#[track_caller] | ||
fn unwrap_debug_or_log_error(self) -> Option<T> | ||
where | ||
E: std::fmt::Display + std::fmt::Debug, | ||
{ | ||
if cfg!(debug_assertions) { | ||
Some(self.unwrap()) | ||
} else { | ||
self.ok_or_log_error() | ||
} | ||
} | ||
} |
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
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.