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

fs methods should expose error.code #1171

Open
leoortizz opened this issue Sep 1, 2023 · 1 comment
Open

fs methods should expose error.code #1171

leoortizz opened this issue Sep 1, 2023 · 1 comment
Labels

Comments

@leoortizz
Copy link

leoortizz commented Sep 1, 2023

Is your feature request related to a problem? Please describe:

When writing a file to a non-existing directory, the error thrown does not expose the error code, making it hard to handle the error.

try {
  await webcontainer.fs.writeFile('non-existent-path/new-file.ts', content);
} catch (err: any) {
  console.log(error.code) // undefined
}

Describe the solution you'd like:

The error thrown should match Node.js's fs errors, at least exposing error.code to allow error handling.

try {
  await webcontainer.fs.writeFile('non-existent-path/new-file.ts', content);
} catch (err: any) {
  if (error.code === 'ENOENT') {
    await webcontainer.fs.mkdir('non-existent-path', {
      recursive: true,
    });

    await webcontainer.fs.writeFile('non-existent-path/new-file.ts', content);
  }
}

Describe alternatives you've considered:

No response

Additional context:

No response

@Nemikolh
Copy link
Member

Nemikolh commented Sep 4, 2023

Hey @leoortizz ! This is a pretty nice idea, I like it a lot. I'll add this to our internal tracking system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants