From b05e639e279486604b42f569af82ab5a3853db85 Mon Sep 17 00:00:00 2001 From: mathis-west-1 Date: Wed, 17 Apr 2024 03:21:18 +0200 Subject: [PATCH] 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'`. PR-URL: https://github.com/nodejs/node/pull/52438 Reviewed-By: Yagiz Nizipli --- src/node_process_methods.cc | 2 +- test/parallel/test-process-load-env-file.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/node_process_methods.cc b/src/node_process_methods.cc index bfa9e88a9f2d01..a7178eddf6ca06 100644 --- a/src/node_process_methods.cc +++ b/src/node_process_methods.cc @@ -492,7 +492,7 @@ static void LoadEnvFile(const v8::FunctionCallbackInfo& 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: diff --git a/test/parallel/test-process-load-env-file.js b/test/parallel/test-process-load-env-file.js index a07ba6771bb381..8aeaef42c97805 100644 --- a/test/parallel/test-process-load-env-file.js +++ b/test/parallel/test-process-load-env-file.js @@ -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 () => {