Skip to content

Commit 276b999

Browse files
committed
src: make dotenv return warning when not found
1 parent 8e9686d commit 276b999

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/node.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ static ExitCode InitializeNodeWithArgsInternal(
845845
errors->push_back(file_path + ": invalid format");
846846
break;
847847
case Dotenv::ParseResult::FileError:
848-
errors->push_back(file_path + ": not found");
848+
// Do nothing
849849
break;
850850
default:
851851
UNREACHABLE();

src/node_dotenv.cc

+1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ Dotenv::ParseResult Dotenv::ParsePath(const std::string_view path) {
228228
uv_file file = uv_fs_open(nullptr, &req, path.data(), 0, 438, nullptr);
229229
if (req.result < 0) {
230230
// req will be cleaned up by scope leave.
231+
fprintf(stderr, "Warning: Requested .env file not found\n\n");
231232
return ParseResult::FileError;
232233
}
233234
uv_fs_req_cleanup(&req);

test/parallel/test-dotenv-edge-cases.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ describe('.env supports edge cases', () => {
4848
[ '--env-file=.env', '--eval', code ],
4949
{ cwd: __dirname },
5050
);
51-
assert.notStrictEqual(child.stderr.toString(), '');
52-
assert.strictEqual(child.code, 9);
51+
assert.ok(child.stderr.includes('Requested .env file not found'));
52+
assert.strictEqual(child.code, 0);
5353
});
5454

5555
it('should not override existing environment variables but introduce new vars', async () => {

0 commit comments

Comments
 (0)