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

feat(runtime): improve error messages of runtime fs #11984

Merged
merged 14 commits into from
Oct 11, 2021

Conversation

F3n67u
Copy link
Contributor

@F3n67u F3n67u commented Sep 11, 2021

fix #10553

related pr: #10642

output:

% ./target/debug/deno 
Deno 1.13.2
exit using ctrl+d or close()
> Deno.statSync('/home/nickolay/not_existing_file')
Uncaught NotFound: No such file or directory (os error 2), stat '/home/nickolay/not_existing_file'
    at deno:core/01_core.js:106:46
    at unwrapOpResult (deno:core/01_core.js:126:13)
    at Object.opSync (deno:core/01_core.js:140:12)
    at Object.statSync (deno:runtime/js/30_fs.js:236:22)
    at <anonymous>:2:6

@F3n67u F3n67u marked this pull request as draft September 11, 2021 08:30
@bartlomieju bartlomieju added this to the 1.15.0 milestone Sep 13, 2021
@ahabhgk
Copy link
Contributor

ahabhgk commented Sep 25, 2021

The tests failed because the renameSyncErrorsUnix will check the error message, change fs_err::rename back to std::fs::rename separately will pass the test, but It may be a little weird that only rename uses the method in the std::fs, so may be we can change the renameSyncErrorsUnix test to let the code pass or write the error message for every fs method manually, any suggestions? @bartlomieju @F3n67u

@F3n67u
Copy link
Contributor Author

F3n67u commented Sep 25, 2021

The tests failed because the renameSyncErrorsUnix will check the error message, change fs_err::rename back to std::fs::rename separately will pass the test, but It may be a little weird that only rename uses the method in the std::fs, so may be we can change the renameSyncErrorsUnix test to let the code pass or write the error message for every fs method manually, any suggestions? @bartlomieju @F3n67u

I'll prefer the latter approach: write the error message for every fs method manually.

@bartlomieju
Copy link
Member

The tests failed because the renameSyncErrorsUnix will check the error message, change fs_err::rename back to std::fs::rename separately will pass the test, but It may be a little weird that only rename uses the method in the std::fs, so may be we can change the renameSyncErrorsUnix test to let the code pass or write the error message for every fs method manually, any suggestions? @bartlomieju @F3n67u

I'll prefer the latter approach: write the error message for every fs method manually.

I agree, message should be written manually.

@F3n67u F3n67u changed the title use fs-err for improved error messages of runtime fs Improve error messages of runtime fs Sep 30, 2021
@F3n67u F3n67u marked this pull request as ready for review September 30, 2021 13:17
@F3n67u F3n67u changed the title Improve error messages of runtime fs feat(runtime/fs): improve error messages of runtime fs Sep 30, 2021
@F3n67u F3n67u changed the title feat(runtime/fs): improve error messages of runtime fs feat(runtime): improve error messages of runtime fs Sep 30, 2021
@F3n67u
Copy link
Contributor Author

F3n67u commented Sep 30, 2021

@bartlomieju I already add path info to all std::fs call's error in runtime fs. Could you help to review?

I don't known how to add path info to permissions.read.check(&path)? and permissions.write.check(&path)? bec those method return anyhow::Error instead of std::io::Error(I don't know how to add path info to anyhow::Error and make path info print). I will very appreciate if you can help with this problem.

@bartlomieju
Copy link
Member

@bartlomieju I already add path info to all std::fs call's error in runtime fs. Could you help to review?

The PR looks good! I'm sure there will be some bike-shedding regarding what errors should print exactly, but it's not a big deal.

I don't known how to add path info to permissions.read.check(&path)? and permissions.write.check(&path)? bec those method return anyhow::Error instead of std::io::Error(I don't know how to add path info to anyhow::Error and make path info print). I will very appreciate if you can help with this problem.

Permission errors coming from read.check() and write.check() already have paths printed out so there's no need to do anything there.

Would be great to see some updated to the unit tests that call assertThrows or assertRejects and verify that expected filepaths are included in the error message.

@bartlomieju bartlomieju requested a review from dsherret October 4, 2021 10:45
@bartlomieju
Copy link
Member

@dsherret do you have any suggestion as for the error messages?

@F3n67u please add some tests asserting error message contain paths so we can land this PR.

@dsherret
Copy link
Member

dsherret commented Oct 4, 2021

@bartlomieju nope, it looks good to me other than the tests.

@F3n67u
Copy link
Contributor Author

F3n67u commented Oct 5, 2021

@bartlomieju I already add path info to all std::fs call's error in runtime fs. Could you help to review?

The PR looks good! I'm sure there will be some bike-shedding regarding what errors should print exactly, but it's not a big deal.

I don't known how to add path info to permissions.read.check(&path)? and permissions.write.check(&path)? bec those method return anyhow::Error instead of std::io::Error(I don't know how to add path info to anyhow::Error and make path info print). I will very appreciate if you can help with this problem.

Permission errors coming from read.check() and write.check() already have paths printed out so there's no need to do anything there.

Would be great to see some updated to the unit tests that call assertThrows or assertRejects and verify that expected filepaths are included in the error message.

@bartlomieju sorry for slow reply. I am on the holiday. I will update the unit tests when i am back.

@F3n67u F3n67u closed this Oct 5, 2021
@F3n67u F3n67u reopened this Oct 5, 2021
@F3n67u
Copy link
Contributor Author

F3n67u commented Oct 5, 2021

@dsherret do you have any suggestion as for the error messages?

@F3n67u please add some tests asserting error message contain paths so we can land this PR.

@bartlomieju I will back 2 days later. If you hurry, You can pick up and update the unit tests.

@bartlomieju
Copy link
Member

@dsherret do you have any suggestion as for the error messages?
@F3n67u please add some tests asserting error message contain paths so we can land this PR.

@bartlomieju I will back 2 days later. If you hurry, You can pick up and update the unit tests.

It's fine, enjoy your holiday :)

@F3n67u F3n67u force-pushed the refactor/fs_err branch 4 times, most recently from f8a4d17 to 8ac835b Compare October 10, 2021 08:23
@bartlomieju
Copy link
Member

@F3n67u this is close to landing, there are two failures in tests on Windows.

@F3n67u
Copy link
Contributor Author

F3n67u commented Oct 10, 2021

@F3n67u this is close to landing, there are two failures in tests on Windows.

@bartlomieju Those two fail is fixed and test is included. ready to review again.

@bartlomieju
Copy link
Member

Tried it locally:

Deno 1.14.3
exit using ctrl+d or close()
> Deno.openSync("./non_existent")
Uncaught NotFound: No such file or directory (os error 2), open './non_existent'
    at Object.opSync (deno:core/01_core.js:138:12)
    at Object.openSync (deno:runtime/js/40_files.js:37:22)
    at <anonymous>:2:6
> Deno.renameSync("./non_existent", "./non_existent2");
Uncaught NotFound: No such file or directory (os error 2), rename './non_existent' -> './non_existent2'
    at Object.opSync (deno:core/01_core.js:138:12)
    at Object.renameSync (deno:runtime/js/30_fs.js:165:10)
    at <anonymous>:2:6

I think the messages could be improved further, but this is way better than current situation. Let's land it and improve messages in upcoming releases.

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @F3n67u!

@bartlomieju bartlomieju merged commit 668b400 into denoland:main Oct 11, 2021
@F3n67u F3n67u deleted the refactor/fs_err branch October 11, 2021 15:02
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.

Improve the error message from stat/statSync
4 participants