-
Notifications
You must be signed in to change notification settings - Fork 99
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
Conversation
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(); |
There was a problem hiding this comment.
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}"))
There was a problem hiding this comment.
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.
Thanks for you contribution! Left a small comment but this should be an easy merge once fixed |
Looks great! |
Updated all 4 commits, as I forgot to sign the them. |
When using the
typheshare-cli
I got an error notifying me of a file that has invalid UTF8 encoding: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: