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

BugFix: Error propagation is silenced #511

Merged
merged 3 commits into from
Oct 18, 2023

Conversation

martinfrances107
Copy link
Contributor

warning: unused `Result` that must be used
   --> plotters/src/style/font/ttf.rs:135:9
    |
135 | /         data.clone().map(|handle| {
136 | |             handle
137 | |                 .load()
138 | |                 .map(FontExt::new)
139 | |                 .map_err(|e| FontError::FontLoadError(Arc::new(e)))
140 | |         })?;
    | |___________^
    |
    = note: this `Result` may be an `Err` variant, which should be handled
    = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
    |
135 |         let _ = data.clone().map(|handle| {

When I remove the ? and look at the type of the droppped variable I see that is it Result<Result<FontExt, FontError>, FontError>

Rust is very unintuative on this matter. The solution is to double unwrap.

There are many ways to do this .. I went with a soltions I think is readable.

```
warning: unused `Result` that must be used
   --> plotters/src/style/font/ttf.rs:135:9
    |
135 | /         data.clone().map(|handle| {
136 | |             handle
137 | |                 .load()
138 | |                 .map(FontExt::new)
139 | |                 .map_err(|e| FontError::FontLoadError(Arc::new(e)))
140 | |         })?;
    | |___________^
    |
    = note: this `Result` may be an `Err` variant, which should be handled
    = note: `#[warn(unused_must_use)]` on by default
help: use `let _ = ...` to ignore the resulting value
    |
135 |         let _ = data.clone().map(|handle| {
```

When I remove the ? and look at the type of the droppped variable
I see that is it Result<Result<FontExt, FontError>, FontError>

Rust is very unintuative on this matter. The solution is to double
unwrap.

There are many ways to do this .. I went with a soltions I think is readable.
@AaronErhardt
Copy link
Member

Does a double question mark ?? or flatten with .flatten()? not work in this case?

@martinfrances107
Copy link
Contributor Author

martinfrances107 commented Oct 18, 2023

I did not even consider using ??.. Readability is such a subjective thing.

I am happy enough to get behind this as a simplification....

and single character bugfixes make me happy.

Copy link
Member

@AaronErhardt AaronErhardt left a comment

Choose a reason for hiding this comment

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

Thanks!

@AaronErhardt AaronErhardt merged commit d84fdb5 into plotters-rs:master Oct 18, 2023
18 checks passed
@martinfrances107 martinfrances107 deleted the double_unwrap branch October 18, 2023 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants