-
Notifications
You must be signed in to change notification settings - Fork 634
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
std/fs: Use original Error class for walk
errors
#3023
Comments
Could you elaborate on your use case here, I'm curious. In what situation would the error message not be good enough? Not against this change, I think it makes sense(?) but I would appreciate further elaboration. |
@lino-levan Sure. First of all, a CLI tool might want custom error messages. It also might want to add additional context to the error. For example, the filepath, or the name of a plugin. Secondly, if the walk function receives a path which doesn't exist, it throws. But If I check first that the path exists, I seem to be introducing a race condition. But I can't handle the error easily, because it's transformed to look like a generic error. In other cases, I would use The only way I've found to check if it's a "Not found" error, is to parse the stack-trace. Which is not ideal, and could get complicated. |
@iuioiua thoughts on this proposal? I would borderline push for a |
After some further thinking, I think I like the idea of a |
@binyamin Does the suggested solution by @lino-levan support your use case? You can use the proposed fix from import { walk } from "https://raw.githubusercontent.com/lino-levan/deno_std/fix-wrap-error/fs/walk.ts"; |
@kt3k Yes. It would be nice if |
Related to #1310
Summary
Whenever the "walk" function encounters an error, it transforms it using the code below. In the process, it uses a generic
Error
class as the constructor. This means that there's no easy way to identify the type of error.https://github.com/denoland/deno_std/blob/7afe49284d0b5357eaf0f5668080cd26f13a1d8b/fs/walk.ts#L32-L42
Proposed Solution
Use
new err.constructor()
instead ofnew Error()
, when instantiating the new error class.The text was updated successfully, but these errors were encountered: