Forbid panic! in production code#10941
Conversation
|
Even with the proposed changes the build script should terminate with the correct status code, but without |
There was a problem hiding this comment.
Thanks for taking a stab at removing some more panics & unwraps!
rerun/crates/store/re_types_core/src/arrow_zip_validity.rs
Lines 196 to 202 in abc5f78
likely callsites need to be patched to remove the need for this method
rerun/crates/store/re_types_core/src/lib.rs
Lines 160 to 176 in abc5f78
I think we should keep this, rationale see documentation of the method.
Similarly, I'm very much on the fence of removing unwrap_debug_or_log_error since this is used in cases where we should absolutely not error in debug builds but don't want to crash in release if we accidentally shipped anyways. They fullfill the same purpose as debug_assert. Let's document it like that (being a stand-in for debug_assert) and keep them, using the appropriate expect
So, my thoughts is that the build script should always use Result to report issues back or abort execution directly without panic!.
sure, why not, but I'd like to see the tradeoff in outputs first. Generally for buildscripts we really don't care all that much since a the build will fail the same either way - the prime motivator of avoiding panic/unwrap is that the sdk/viewer never crash, so that's not a concern here. Arguably the advantage with panicing is that it's easier to pinpoint the error here.
Haven't worked with cargo::error yet, could you post a before/after example for a given error?
Co-authored-by: Andreas Reich <r_andreas2@web.de>
|
|
||
| Err(err) => panic!("{err}"), | ||
| Err(err) => { | ||
| println!("cargo::error={err}"); |
Here are a few examples of the output with the corresponding code. Note that
|
|
Thank you for the detailed overview! The cargo error variants look indeed nicer, I figure we should use those whenever there's an error in user command or user environment 👍 . For everything else (i.e. implementation errors of build.rs) we want the callstack, those should panic |
|
@Wumpf, are you fine that the current implementation tries to grab as many errors as possible or should the build script stop on the first one? If you want to stop ASAP, then I need to modify my code a bit as I proposed. |
|
generally I think it's nice to see all errors at once - too often sometimes they only show up in some circumstances (e.g. ci) and then it's nice to have all of them. That is unless there's too many non-sensical ones caused by the first. Tbh not sure how it playes out with the ones here. |
|
looks like there's some missed here. I think these should also have case-by-case allow because they're again just debug assertions |
|
Yeah, there are two places that should be patched with |
Wumpf
left a comment
There was a problem hiding this comment.
Practically all changes in 46cb497 are incorrect as they use cargo_error in libraries that are not necessarily part of build.rs.
re_types_builderis invoked not as a build tool inside of build.rs, but rather as command line tool to build types. We typically run it withpixi run codegenre_build_infoisn't a library exclusively used in build.rs, but rather to read out build info that was previously injected via a build.rsre_dev_toolsis a command line tool used by various build & testing scripts
|
I figure that's a huge drawback of printing with |
|
ci still doesn't run through https://github.com/rerun-io/rerun/actions/runs/17221558702/job/48887551457?pr=10941 |
|
It's caused by rust-lang/rust-clippy#15564. I will remove |
|
@Wumpf, I polished the pull request taking into account the provided information. Therefore, all |
| { | ||
| } | ||
|
|
||
| impl<T, I, V> ZipValidity<T, I, V> |
|
ci is still not happy. You can replicate its set of checks by running |
Yeah, I will come back to it and fix that as I get a bit of spare time. I still remember about the pull requests, it's not abandoned, just a startup I'm working for prepares for a conference and lots of thing have to be ready before that. |
|
putting this to draft for tracking purposes |
|
@Wumpf, could you run the workflows on the pull request? I have some time to finish it, finally. |
Related
Part of #7997.
What
The pull request forbids any usage of
panic!outside of tests, but I found that there are some cases that I don't know how to resolve. As an example:rerun/crates/store/re_types_core/src/arrow_zip_validity.rs
Lines 196 to 202 in abc5f78
For the follow up, I suppose, the
ResultExtshould be used to produce an error, right?rerun/crates/store/re_types_core/src/lib.rs
Lines 160 to 176 in abc5f78