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

fix(fs): no root path in walk error #875

Merged
merged 4 commits into from
Apr 30, 2021

Conversation

Nautigsam
Copy link
Contributor

This adds the root path to error object. I am not sure this is the way to go, maybe I should put it in the message?

Fix #863

@CLAassistant
Copy link

CLAassistant commented Apr 24, 2021

CLA assistant check
All committers have signed the CLA.

@kt3k
Copy link
Member

kt3k commented Apr 27, 2021

I think we should show the path in error message because otherwise it doesn't show up when the user didn't catch it. I also think we should show the full path which caused the error, instead of the root path.

@Nautigsam Nautigsam force-pushed the dev/walk_error_root_path branch 2 times, most recently from 8652492 to c285075 Compare April 27, 2021 13:36
@Nautigsam
Copy link
Contributor Author

@kt3k I put the path in the error message.

I also think we should show the full path which caused the error, instead of the root path.

Do you mean if the root path is a relative path we should make it absolute by joining it with Deno.cwd() ?

@kt3k
Copy link
Member

kt3k commented Apr 28, 2021

@Nautigsam
I mean we should print more granular path which caused the actual permission error. For example when walking from './foo' and './foo/bar.txt' caused the permission error, I think the error message should be something like Error: Could not read the path /abs/path/to/foo/bar.txt.

I think that's possible by moving the try-catch clause to nearer place to the actual fs API calls.

@Nautigsam
Copy link
Contributor Author

Nautigsam commented Apr 28, 2021

I think that's possible by moving the try-catch clause to nearer place to the actual fs API calls.

@kt3k I don't think it is possible. The error is fired by Deno.readDir in walk() function. I put my try-catch right around it.

@kt3k
Copy link
Member

kt3k commented Apr 29, 2021

@Nautigsam Ok. Let's show root path in the error message. BTW I think it might be better to surround only Deno.readDir() call with try-catch to be specific about what is being caught here.

let files
try {
  files = Deno.readDir(root);
} catch (e) {
  throw new Error("Couldn't read...");
}
for await (const entry of files) { ... }

@Nautigsam
Copy link
Contributor Author

Ok I'll do it. One last question: I don't know if there is some kind of convention about composing error messages? I chose to make it more natural by appending ... at path X at the end of the message:

Uncaught Permission Denied: ... at path X

We could as well put it at the start but it feels more robotic when it's thrown:

Uncaught At path X: Permission Denied: ...

@kt3k
Copy link
Member

kt3k commented Apr 29, 2021

Ah, I missed your latest update. The error message now looks good to me!

@Nautigsam
Copy link
Contributor Author

I could narrow the try-catch arount readDirSync but not readDir. Since it returns an AsyncIterable, the error is thrown by the for await..of. If you think it's okay then I'm done.

@Nautigsam Nautigsam force-pushed the dev/walk_error_root_path branch 5 times, most recently from 9740193 to a48efae Compare April 29, 2021 18:36
This adds the root path to error message.
The `root` property is set to properly handle errors in case of
recursion.

Fix denoland#863
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

@Nautigsam LGTM. Thank you for your contribution!

@kt3k kt3k merged commit a0984a6 into denoland:main Apr 30, 2021
@Nautigsam Nautigsam deleted the dev/walk_error_root_path branch April 30, 2021 07:16
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.

🙏🏻[feat/req] Need more details in error messages for thrown errors
3 participants