Skip to content
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

resolve clippy::unwrap_used in re_viewer #8745

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

brody4hire
Copy link
Contributor

Related

Part of: #6330

What

  • remove allow directive & TODO comment from crates/viewer/re_viewer/src/lib.rs
  • use . unwrap_or_else with panic in 1 case
  • use focused #[allow(clippy::unwrap_used)] directives in limited, focused cases
  • use .expect with descriptive messages in all other cases

(no changelog updates)

General rationale:

Most of the cases using .unwrap seem to need these to work. I think the best solution is to use .expect with a clear message in most of these cases.

Sanity checks done:

These succeed for me with no warnings:

  • cargo clippy -p re_viewer --all-features
  • cargo build -p re_viewer --all-features

@Wumpf Wumpf self-requested a review January 22, 2025 09:15
@Wumpf Wumpf added 🚜 refactor Change the code, not the functionality exclude from changelog PRs with this won't show up in CHANGELOG.md labels Jan 22, 2025
Copy link
Member

@Wumpf Wumpf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you!!

@brody4hire brody4hire marked this pull request as draft January 22, 2025 17:39
@brody4hire brody4hire force-pushed the resolve-clippy-unwrap_used-in-re_viewer branch from 41931d1 to e0d4ff3 Compare January 22, 2025 18:05
@brody4hire brody4hire force-pushed the resolve-clippy-unwrap_used-in-re_viewer branch from a719ec0 to fd9e54a Compare January 22, 2025 18:18
@brody4hire brody4hire marked this pull request as ready for review January 22, 2025 18:19
Copy link
Contributor Author

@brody4hire brody4hire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Wumpf I have shamelessly thrown away your cleanup work in favor of using .expect("... (internal error)") calls (I am assuming no offense will be taken). I think this should both reduce the number of lines in most cases and clarify the code a little better.

I think this should be ready now. Please do feel free to apply any other cleanup you think may be needed & be sure to add yourself as a co-author.

@@ -89,7 +89,7 @@ impl Screenshotter {
let h = image.height() as _;
let image =
image::RgbaImage::from_raw(w, h, bytemuck::pod_collect_to_vec(&image.pixels))
.expect("Failed to create image");
.expect("Failed to create image (internal error)");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the "internal error" message for our users, but I think we should add that to the panic handler of re_crash_handler instead, since any panic is an internal error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would agree in most but not all cases, I think this points to a counter-example as I commented below: https://github.com/rerun-io/rerun/pull/8745/files#r1928954634

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you think we should proceed with this?

Copy link
Member

@emilk emilk Jan 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A panic should only happen because of a bug in the rerun codebase, which is what I would call an internal error. If there are panics that could happen because of user error, we should fix that separately.

@brody4hire brody4hire marked this pull request as draft January 24, 2025 15:59
@brody4hire brody4hire force-pushed the resolve-clippy-unwrap_used-in-re_viewer branch from a1df8c2 to 82a262c Compare January 24, 2025 16:11
@brody4hire brody4hire marked this pull request as ready for review January 24, 2025 16:24
Ok(any) => Some(*any.downcast::<T>().unwrap()),
Ok(any) => Some(
*any.downcast::<T>()
.unwrap_or_else(|err| panic!("downcast failure: {err:?}")),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an example where a panic is triggered not by an internal error but by an issue with the calling code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking it may be ideal to update the API to return a promise or result with a promise so that the calling code can poll it without the need for this downcast. We could add a separate API function to do this without breaking any API users. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calling code is still Rerun code, so any panic here is still an error internal to the Rerun application (as opposed to a user error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exclude from changelog PRs with this won't show up in CHANGELOG.md 🚜 refactor Change the code, not the functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants