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

Adds more useful output for invalid UTF8 error. #117

Merged
merged 4 commits into from
Jul 3, 2023

Conversation

xhain
Copy link
Contributor

@xhain xhain commented May 11, 2023

When using the typheshare-cli I got an error notifying me of a file that has invalid UTF8 encoding:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: InvalidData, message: "stream did not contain valid UTF-8" }', cli/src/main.rs:264:58

I still had to manually backtrace which file was affected, so I implemented a more useful error message for this case that additionally lists the file path:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: "/project/core/._nonUTF8file.rs, stream did not contain valid UTF-8"', cli/src/main.rs:264:98

@xhain xhain marked this pull request as ready for review May 11, 2023 10:35
cli/src/main.rs Outdated
let data = std::fs::read_to_string(filepath).unwrap();
let data = std::fs::read_to_string(filepath)
.map_err(|e| format!("{filepath}, {e}"))
.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of unwrapping a string, recommend just unwrap_or_else with a panic:

std::fs::read_to_string(filepath)
    .unwrap_or_else(|e| panic!("failed to read file at {filepath:?}: {e}"))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! I updated the change to use this pattern.

@Lucretiel
Copy link
Contributor

Thanks for you contribution! Left a small comment but this should be an easy merge once fixed

@Lucretiel
Copy link
Contributor

Looks great!

@xhain
Copy link
Contributor Author

xhain commented Jul 2, 2023

Updated all 4 commits, as I forgot to sign the them.

@Lucretiel Lucretiel merged commit cda9491 into 1Password:main Jul 3, 2023
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