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(fs/walk): WalkError class #3054

Merged
merged 10 commits into from
Mar 29, 2023
Merged

feat(fs/walk): WalkError class #3054

merged 10 commits into from
Mar 29, 2023

Conversation

lino-levan
Copy link
Contributor

closes #3023.

The concept is that if you want to catch an error and see what caused it, you should be able to use err.cause instanceof ErrorClassYouWantToCatch.

fs/walk.ts Outdated Show resolved Hide resolved
fs/walk.ts Show resolved Hide resolved
Co-authored-by: Yoshiya Hinosawa <stibium121@gmail.com>
@kt3k
Copy link
Member

kt3k commented Jan 19, 2023

@lino-levan Can you also add a simple test case which checks WalkError being thrown?

@lino-levan
Copy link
Contributor Author

SGTM, I'll get around to it when I get around to it. Maybe tomorrow if I get the chance.

@lino-levan
Copy link
Contributor Author

@kt3k I tried my hand at writing a test for this but can't think of a way for this to error out consistently (without relying on something like removing a folder after we already started walking it). Do you have any ideas?

fs/walk.ts Outdated Show resolved Hide resolved
lino-levan and others added 2 commits March 1, 2023 22:33
Co-authored-by: Jesse Jackson <jsejcksn@users.noreply.github.com>
@jsejcksn
Copy link
Contributor

jsejcksn commented Mar 2, 2023

I tried my hand at writing a test for this but can't think of a way for this to error out consistently (without relying on something like removing a folder after we already started walking it). Do you have any ideas?

@lino-levan I just tested this locally and it reliably throws every run:

test.ts:

// deno test --allow-read=exampleRootTestDir --allow-write=exampleRootTestDir

import { assertRejects } from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { walk } from "https://deno.land/std@0.178.0/fs/walk.ts";

Deno.test("throws", async () => {
  const dir = "exampleRootTestDir";

  await assertRejects(async () => {
    await Deno.mkdir(dir);
    for await (const _walkEntry of walk(dir)) await Deno.remove(dir);
  });
});
 % deno --version
deno 1.31.1 (release, aarch64-apple-darwin)
v8 11.0.226.13
typescript 4.9.4

% deno test --allow-read=exampleRootTestDir --allow-write=exampleRootTestDir
running 1 test from ./test.ts
throws ... ok (6ms)

ok | 1 passed | 0 failed (20ms)

Check out the testWalk function in the test file.

@lino-levan
Copy link
Contributor Author

LGTM, thanks for your help on this PR!

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.

LGTM. Thanks! @lino-levan

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.

std/fs: Use original Error class for walk errors
3 participants