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

Better error message when cwd is invalid #799

Closed
ehmicky opened this issue Feb 7, 2024 · 0 comments · Fixed by #803
Closed

Better error message when cwd is invalid #799

ehmicky opened this issue Feb 7, 2024 · 0 comments · Fixed by #803

Comments

@ehmicky
Copy link
Collaborator

ehmicky commented Feb 7, 2024

process.cwd() throws when the current directory does not exist.

Error: ENOENT: no such file or directory, uv_cwd
    at process.wrappedCwd [as cwd] (node:internal/bootstrap/switches/does_own_process_state:138:28) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'uv_cwd'
}

child_process.spawn() also throws when the cwd option's directory does not exist.

Error: spawnSync echo ENOENT
    at __node_internal_captureLargerStackTrace (node:internal/errors:563:5)
    at __node_internal_errnoException (node:internal/errors:690:12)
    ... // 20 lines of stack trace
    at TTY.callbackTrampoline (node:internal/async_hooks:130:17) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawnSync echo',
  path: 'echo',
  spawnargs: []
},

There are also other reasons which can make cwd fail such as missing file permissions, pointing to a non-directory, or using a file name too long (libuv uses getcwd on Unix and GetCurrentDirectory on Windows).

When the above problems happen, we should provide with better error messages. The current error messages are confusing as they do not always mention cwd, making it look like the issue is the command not existing. I have actually gotten this myself in the past, and it can lead to long debugging sessions before realizing what the problem is.

@ehmicky ehmicky changed the title Error when cwd is missing Better error message when cwd is invalid Feb 8, 2024
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 a pull request may close this issue.

1 participant