Skip to content

process.loadEnvFile() error message issue: Failed to load '%s' #52463

@hyrious

Description

@hyrious

Version

v21.7.2

Platform

Darwin MAGIT00999.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:11:05 PDT 2024; root:xnu-10063.101.17~1/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

Run the command at somewhere without a .env file.

$ node -p 'process.loadEnvFile()'

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

No response

What do you see instead?

node:internal/process/per_thread:265
      _loadEnvFile();
      ^

Error: ENOENT: .env, Failed to load '%s'.

Additional information

This is because someone wronly used ThrowUVException:

case dotenv.ParseResult::FileError: {
env->ThrowUVException(UV_ENOENT, "Failed to load '%s'.", path.c_str());
break;

Maybe this patch would work:

    case dotenv.ParseResult::FileError: {
-     env->ThrowUVException(UV_ENOENT, "Failed to load '%s'.", path.c_str());
+     env->ThrowUVException(UV_ENOENT, "read", nullptr, path.c_str());
      break;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    errorsIssues and PRs related to JavaScript errors originated in Node.js core.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions