-
Notifications
You must be signed in to change notification settings - Fork 286
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
Improve error handling #1560
base: main
Are you sure you want to change the base?
Improve error handling #1560
Conversation
src/info/langs/mod.rs
Outdated
get_loc_by_language(&locs).context("Could not find any source code in this repository")?; | ||
get_loc_by_language(&locs).with_context(|| { | ||
format!( | ||
"Could not find any source code in this repository at path '{}'. Try using --include-hidden if your files are hidden, or check your exclude patterns.", |
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.
The most common point of confusion I've seen is languages that are excluded by default not being shown. For example, JSON, a data language, is excluded by default, so a repo that is only JSON files would have "no source code" unless they use the -T
option. Perhaps you should mention that instead.
src/info/churn.rs
Outdated
@@ -16,6 +16,7 @@ pub struct FileChurn { | |||
} | |||
|
|||
impl FileChurn { | |||
#[allow(dead_code)] |
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.
Why are we allowing dead code here?
hey @spenserblack thank you for your feedback. I'm actually still learning Rust, so I Thanks for the guidance! Should I update the PR with the language suggestion? |
|
||
let file_name = path.split('/').last().unwrap_or(path); | ||
Some(FileChurn::new( | ||
file_name.to_string(), |
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.
Why did you change file_path
to file_name
?
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.
Actually, I didn't change the behavior there - the original code was already extracting and storing just the file name. I just switched from direct struct initialization to using the constructor method.
The original code was:
let file_name = path.split('/').last().unwrap_or(path); Some(FileChurn { file_path: file_name.to_string(), nbr_of_commits: *count, number_separator, })
And I changed it to:
let file_name = path.split('/').last().unwrap_or(path); Some(FileChurn::new( file_name.to_string(), *count, number_separator, ))
The variable name file_name was already there, and it was already being assigned to the file_path field. I just switched to using the constructor to eliminate the "unused method" warning since FileChurn::new() wasn't being used in the main code (only in tests).
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.
I'm confused, this is not what I see in the diff.
ah sorry I misclicked start a review button |
While improving the error messages to provide more info is a good idea, I think this PR does too much. The best PR does only what it says, and doesn't include possibly unrelated changes. |
When the compiler complains, it's best to handle the complaint instead of silence it. In this case, if the code is only used in tests, then you can move the implementation to inside the test scope. |
Adds more context to error messages