Skip to content

Commit

Permalink
src: fix loadEnvFile ENOENT error
Browse files Browse the repository at this point in the history
Before this change the error message for `process.loadEnvFile()` without
an `.env` file present in the current working directory was looking like
this: `ENOENT: .env, Failed to load '%s'.` This obviously isn't what the
author intended.

To fix that, just return a "plain" ENOENT open error. It should be
descriptive enough. That means for the above example, the error message
is now `ENOENT: no such file or directory, open '.env'`.

PR-URL: #52438
Reviewed-By: Yagiz Nizipli <[email protected]>
  • Loading branch information
fahrradflucht authored and aduh95 committed Apr 29, 2024
1 parent 9794d21 commit f283d27
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/node_process_methods.cc
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ static void LoadEnvFile(const v8::FunctionCallbackInfo<v8::Value>& args) {
break;
}
case dotenv.ParseResult::FileError: {
env->ThrowUVException(UV_ENOENT, "Failed to load '%s'.", path.c_str());
env->ThrowUVException(UV_ENOENT, "open", nullptr, path.c_str());
break;
}
default:
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-process-load-env-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ describe('process.loadEnvFile()', () => {
it('should throw when file does not exist', async () => {
assert.throws(() => {
process.loadEnvFile(missingEnvFile);
}, { code: 'ENOENT' });
}, { code: 'ENOENT', syscall: 'open', path: missingEnvFile });
});

it('should throw when `.env` does not exist', async () => {
assert.throws(() => {
process.loadEnvFile();
}, { code: 'ENOENT' });
}, { code: 'ENOENT', syscall: 'open', path: '.env' });
});

it('should check for permissions', async () => {
Expand Down

0 comments on commit f283d27

Please sign in to comment.