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

BREAKING(fs): throw Deno.errors.NotFound instead of WalkError in walk[Sync]() #5477

Merged
merged 5 commits into from
Jul 24, 2024

Conversation

iuioiua
Copy link
Contributor

@iuioiua iuioiua commented Jul 18, 2024

What's changed

walk() and walkSync() now naturally throw Deno.errors.NotFound instead of throwing WalkError. The root property has also been removed and the message property no longer includes the normalized path.

Motivation

This change was made to allow these functions to delegate error throwing functionality to the Deno runtime, which provides sufficient context naturally. This also removes a dependency on @std/path/normalize and slightly reduces the API surface area of @std/fs/walk.

Migration guide

To migrate, compare against Deno.errors.NotFound instead of WalkError when error-handling walk().

- import { walk, WalkError } from "@std/fs/walk";
+ import { walk } from "@std/fs/walk";

const root = "../my-dir";

try {
  await Array.fromAsync(
    walk(root),
    async () => await Deno.remove(root, { recursive: true }),
  );
} catch (error) {
- if (error instanceof WalkError) {
+ if (error instanceof Deno.errors.NotFound) {
    // ...
  }
}

Related

Towards #5476

@github-actions github-actions bot added the fs label Jul 18, 2024
Copy link

codecov bot commented Jul 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.40%. Comparing base (2e542ff) to head (3f75c00).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5477      +/-   ##
==========================================
+ Coverage   96.39%   96.40%   +0.01%     
==========================================
  Files         465      465              
  Lines       37757    37727      -30     
  Branches     5579     5574       -5     
==========================================
- Hits        36397    36372      -25     
+ Misses       1318     1313       -5     
  Partials       42       42              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@iuioiua iuioiua changed the title BREAKING(fs): replace WalkError exception with Deno.errors.NotFound in walk[Sync]() BREAKING(fs): throw Deno.errors.NotFound instead of WalkError in walk[Sync]() Jul 18, 2024
@iuioiua iuioiua mentioned this pull request Jul 18, 2024
8 tasks
@iuioiua iuioiua changed the title BREAKING(fs): throw Deno.errors.NotFound instead of WalkError in walk[Sync]() BREAKING(fs): remove throwing of WalkError in walk[Sync]() Jul 18, 2024
@iuioiua iuioiua marked this pull request as ready for review July 18, 2024 06:13
@iuioiua iuioiua requested a review from kt3k as a code owner July 18, 2024 06:13
@kt3k
Copy link
Member

kt3k commented Jul 18, 2024

WalkError.path WalkError.root seems to have a usage #3023 (comment)

@iuioiua
Copy link
Contributor Author

iuioiua commented Jul 18, 2024

That suggestion was made as a passing remark rather than being triggered from a reported need from a user. After recent work on errors in the codebase, I'm becoming more convinced that throwing naturally is sufficient in almost all cases. If it's good enough for the runtime, I think it's good enough for the Standard Library.

@iuioiua
Copy link
Contributor Author

iuioiua commented Jul 23, 2024

Furthermore, Deno.errors.NotFound naturally provides clearer context for the error.

@kt3k
Copy link
Member

kt3k commented Jul 23, 2024

Furthermore, Deno.errors.NotFound naturally provides clearer context for the error.

WalkError.prototype.root gives the root path of walk. On the other hand, Deno.error.NotFound only shows the exact path, which was not found. The same information is not available with this change.

Also the user needs to parse the path from the error message of Deno.errors.NotFound to get the path. The feels like degraded DX.

@kt3k
Copy link
Member

kt3k commented Jul 23, 2024

@lowlighter and @lambdalisue are the users of WalkError in open source https://github.com/search?q=WalkError+std%2Ffs&type=code

What do you think about this change?

@kt3k
Copy link
Member

kt3k commented Jul 23, 2024

Also I think @binyamin uses this in some projects #3023 (comment)

@binyamin Do you still use WalkError in your projects? What do you think about this change?

@lambdalisue
Copy link
Contributor

If the change is clearly mentioned in the release notes, I'm fine with it. In fact, I prefer Deno.errors.NotFound over WalkError because users of walk() can wrap the error themselves if they need root information. I believe that certain responsibilities should lie with the users rather than the providers.

@marvinhagemeister
Copy link
Contributor

+1 on going with Deno.errors.NotFound. It feels more consistent with the rest of Deno to me as other file system APIs throw that too.

@iuioiua iuioiua changed the title BREAKING(fs): remove throwing of WalkError in walk[Sync]() BREAKING(fs): throw Deno.errors.NotFound instead of WalkError in walk[Sync]() Jul 24, 2024
@lowlighter
Copy link
Contributor

I concur with what have been already said

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.

Thanks for the feedbacks/comments!

LGTM

@iuioiua iuioiua merged commit 0dc7ce1 into main Jul 24, 2024
16 checks passed
@iuioiua iuioiua deleted the fs-remove-WalkError branch July 24, 2024 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants