diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-10-31 10:02:17 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-31 10:02:17 -0700 |
commit | 951103fc8de952f32386121d3f0e4803fe267ea4 (patch) | |
tree | cab451d94038a975f1bf4f578bbd18171685dcf6 /ext/node/polyfills/_fs/_fs_readFile.ts | |
parent | 90edca21a26fd2decd0603fea37af10d1e11e454 (diff) |
fix(ext/node): convert errors from `fs.readFile/fs.readFileSync` to node format (#26632)
Fixes the original issue reported in #26404. storybook runs into other
errors after this PR (the new errors will be fixed in other PRs).
Some code used by a dependency of storybook does a [string comparison on
the error
message](https://github.com/chromaui/chromatic-cli/blob/ce30b2be343cb96a0826390b95ea42befb2be547/node-src/lib/getConfiguration.ts#L88-L92)
thrown here to check for a file not found error.
Diffstat (limited to 'ext/node/polyfills/_fs/_fs_readFile.ts')
-rw-r--r-- | ext/node/polyfills/_fs/_fs_readFile.ts | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/ext/node/polyfills/_fs/_fs_readFile.ts b/ext/node/polyfills/_fs/_fs_readFile.ts index 0f05ee167..cf7e0305d 100644 --- a/ext/node/polyfills/_fs/_fs_readFile.ts +++ b/ext/node/polyfills/_fs/_fs_readFile.ts @@ -19,6 +19,7 @@ import { TextEncodings, } from "ext:deno_node/_utils.ts"; import { FsFile } from "ext:deno_fs/30_fs.js"; +import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts"; function maybeDecode(data: Uint8Array, encoding: TextEncodings): string; function maybeDecode( @@ -87,7 +88,7 @@ export function readFile( } const buffer = maybeDecode(data, encoding); (cb as BinaryCallback)(null, buffer); - }, (err) => cb && cb(err)); + }, (err) => cb && cb(denoErrorToNodeError(err))); } } @@ -117,7 +118,12 @@ export function readFileSync( opt?: FileOptionsArgument, ): string | Buffer { path = path instanceof URL ? pathFromURL(path) : path; - const data = Deno.readFileSync(path); + let data; + try { + data = Deno.readFileSync(path); + } catch (err) { + throw denoErrorToNodeError(err); + } const encoding = getEncoding(opt); if (encoding && encoding !== "binary") { const text = maybeDecode(data, encoding); |