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

Gracefully handle invalid paths #10

Closed
wants to merge 1 commit into from

Conversation

AlexMeah
Copy link

@AlexMeah AlexMeah commented Apr 6, 2022

This adds graceful handling of invalid paths.

I think false is the correct response rather than throwing as the file is not of that type if it cannot be read.

Context:

This is affecting Vite due to their use of virtual modules, which they signify by using \0 in the path.

[vite:react-babel] dp-ideal/commonjsHelpers.js: The argument 'path' must be a string or Uint8Array without null bytes. Received 'dp-ideal/\x00commonjsHelpers.js'
file: commonjsHelpers.js
error during build:
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'path' must be a string or Uint8Array without null bytes. Received 'dp-ideal/\x00commonjsHelpers.js'
    at Object.statSync (fs.js:1124:10)
    at isTypeSync (dp-ideal/node_modules/path-type/index.js:28:24)
    at getDirectorySync (dp-ideal/node_modules/cosmiconfig/dist/getDirectory.js:28:61)
    at ExplorerSync.searchSync (dp-ideal/node_modules/cosmiconfig/dist/ExplorerSync.js:26:63)
    at getConfigFromFile (dp-ideal/node_modules/babel-plugin-macros/dist/index.js:256:40)
    at getConfig (dp-ideal/node_modules/babel-plugin-macros/dist/index.js:294:24)
    at applyMacros (dp-ideal/node_modules/babel-plugin-macros/dist/index.js:210:18)
    at ImportDeclaration (dp-ideal/node_modules/babel-plugin-macros/dist/index.js:110:28)
    at NodePath._call (dp-ideal/node_modules/@babel/traverse/lib/path/context.js:53:20)
    at NodePath.call (dp-ideal/node_modules/@babel/traverse/lib/path/context.js:40:17)

@sindresorhus
Copy link
Owner

I don't think this is a good idea. It would make it really hard to debug if you accidentally passed an invalid path. I think programmer errors should fail loudly. And it could potentially be a security issue as you're silencing null-byte path errors.

What we I think should be done is to better document when it would throw.

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.

2 participants