Skip to content

Commit c643a3a

Browse files
committed
src: fix loadEnvFile ENOENT error
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'`.
1 parent 8c0b723 commit c643a3a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/node_process_methods.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static void LoadEnvFile(const v8::FunctionCallbackInfo<v8::Value>& args) {
492492
break;
493493
}
494494
case dotenv.ParseResult::FileError: {
495-
env->ThrowUVException(UV_ENOENT, "Failed to load '%s'.", path.c_str());
495+
env->ThrowUVException(UV_ENOENT, "open", nullptr, path.c_str());
496496
break;
497497
}
498498
default:

test/parallel/test-process-load-env-file.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ describe('process.loadEnvFile()', () => {
4545
it('should throw when file does not exist', async () => {
4646
assert.throws(() => {
4747
process.loadEnvFile(missingEnvFile);
48-
}, { code: 'ENOENT' });
48+
}, /ENOENT: no such file or directory, open '.*non-existent-file\.env'/);
4949
});
5050

5151
it('should throw when `.env` does not exist', async () => {
5252
assert.throws(() => {
5353
process.loadEnvFile();
54-
}, { code: 'ENOENT' });
54+
}, /ENOENT: no such file or directory, open '\.env'/);
5555
});
5656

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

0 commit comments

Comments
 (0)