-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
Show Inaccuracy Warning on permission error #270
Conversation
@Aaronepower sorry for pinging you but I wasnt sure whether you didn't see this PR or not |
@Veykril Sorry, yes I did see it. I have a problem where if I'm unsure about a feature I tend to not reply till I have a more definitive answer 😅. Could you run |
I was concerned about the performance impact of this as well but i couldn't think of a different way to implement this.
I don't think these are accurate though, my machine isnt the best to benchmark things + Im running windows so im not too sure how well that goes. |
@Veykril Sorry, could you run the benchmark on a larger repo such as the rust repo? Also could you have two benchmarks, one with no warnings and one with a warning? |
No problem, i can see your concern over this since your tool should stay as fast as possible. I ran it on the rust repo now and I moved and renamed my exe out of the build dir cause i wasnt sure how windows handles path exes and the exes in the current dir, so iwanted to be safe that it actually executes my build. Output without an error: https://pastebin.com/3xHqpUJT |
@Veykril Sorry about this, I've since made a large scale refactor to the codebase that makes the changes here incompatible. You'll need to rewrite some of this for it to be accepted. |
No problem, will look into your changes sometime later this week and try to adapt my PR to that |
Alright, I adapted the changes and tested them. From what I have seen I didnt have to change much unless I've overlooked something. I also fixed an output bug that I didnt even notice at first, as you can see in the example output text from the PR, the total section wasnt correctly aligned. That shouldnt happen anymore now. |
src/language/mod.rs
Outdated
@@ -104,6 +112,9 @@ impl AddAssign for Language { | |||
self.blanks += rhs.blanks; | |||
self.code += rhs.code; | |||
self.stats.extend(mem::replace(&mut rhs.stats, Vec::new())); | |||
if rhs.inaccurate { | |||
self.inaccurate = rhs.inaccurate |
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.
Can you remove the if statement and replace with the following?
self.inaccurate = rhs.inaccurate | |
self.inaccurate |= rhs.inaccurate |
src/language/language_type.rs
Outdated
|
||
/// Parses the text provided. | ||
pub fn parse_from_str_with_accuracy(self, path: PathBuf, text: &str) -> Stats |
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 is parse_from_str_with_accuracy
necessary?
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.
oh it actually isnt now that you say it, i was just confused as to why parse_from_str
returns a result when it never returns an error. Probably due to previous implementations I guess? Will remove the function again
src/utils/fs.rs
Outdated
use ignore::Error; | ||
if let Error::WithDepth { err: ref error, .. } = error { | ||
if let Error::WithPath { ref path, err: ref error } = **error { | ||
if let Error::Io(ref error) = **error { |
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 think we can condense this code. Instead of just checking for Permission denied, couldn't we use the following?
error!("{} reading {}", error.description(), path.display());
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.
Yep, this is indeed better, I guess I was too focused on the PermissionDenied error there. Looks a lot better like this and makes more sense overall
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 have a few last change requests 😅 Thank you for your PR and your patience through this process.
src/language/language_type.rs
Outdated
s | ||
}; | ||
|
||
self.parse_from_str(path, &text) | ||
Ok(self.parse_from_str(path, &text).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.
Can you remove the Ok()
and the 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.
Oh right, I did this cause the results have different error cases and parse_from_str cannot fail from its implementation. Probably a bad idea to unwrap though since the implementation could change. Will have to do the same if let Err instead of map_err though due to the closure move that would happen otherwise though
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 have a problem here in general cause the parse_from_str error that wouldnt happen in its current implementation doesnt give back the pathbuf, so I am not sure how to even map the error here
src/language/language_type.rs
Outdated
} | ||
|
||
/// Parses the text provided. Returning `Stats` on success. | ||
pub fn parse_from_str(self, path: PathBuf, text: &str) | ||
-> io::Result<Stats> | ||
pub fn parse_from_str(self, path: PathBuf, text: &str) -> io::Result<Stats> |
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.
Can you revert the style changes on this method? I prefer the style used previously.
No problem, I am still learning you pointing all these things out is only helping me in the end. Better to do this properly than just letting everything through 👍 |
@Veykril Okay, I think if you could make the style change and resolve the conflicts this is ready to merge in. |
Haha, sorry you actually can break the API as I'm going to be making some changes that would also break the API so we might as well break them both in the same release. |
So i can change the function signatures as I please? |
@Veykril Remove the |
I suppose this is what you meant right? I hope |
Okay, this PR looks good to me. Thank you again for your PR and for making the requested changes! |
This PR roughly implements issue #165. I am sure there is room for some improvements on my code changes so feel free to comment on everything I changed. One thing I dislike that I did is this weird if let bundle I created to check for a permission error at one place:
https://github.com/Veykril/tokei/blob/0c7e18d1b0b45832c40c3a991be4bd57111ff5e5/src/utils/fs.rs#L52-L61
I couldnt come up with a better way since the nested errors are boxed and box patterns arent stable yet.
Example Output: