GeezerVison is showing github.com — src: return error --env-file if file is not found · nodejs/node@0d3aa72
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: src/node.cc +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -866,7 +866,9 @@ static ExitCode InitializeNodeWithArgsInternal( | 866 | 866 |
| 867 | 867 | for (const auto& file_path : file_paths) { | 868 | 868 | std::string path = cwd + kPathSeparator + file_path; | 869 | | - per_process::dotenv_file.ParsePath(path); | | 869 | + auto path_exists = per_process::dotenv_file.ParsePath(path); | | 870 | + | | 871 | + if (!path_exists) errors->push_back(file_path + ": not found"); | 870 | 872 | } | 871 | 873 |
| 872 | 874 | per_process::dotenv_file.AssignNodeOptionsIfAvailable(&node_options); | |
Collapse file Copy file name to clipboardExpand all lines: src/node_dotenv.cc +4-3Lines changed: 4 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -64,14 +64,14 @@ void Dotenv::SetEnvironment(node::Environment* env) { | 64 | 64 | } | 65 | 65 | } | 66 | 66 |
| 67 | | -void Dotenv::ParsePath(const std::string_view path) { | | 67 | +bool Dotenv::ParsePath(const std::string_view path) { | 68 | 68 | uv_fs_t req; | 69 | 69 | auto defer_req_cleanup = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); }); | 70 | 70 |
| 71 | 71 | uv_file file = uv_fs_open(nullptr, &req, path.data(), 0, 438, nullptr); | 72 | 72 | if (req.result < 0) { | 73 | 73 | // req will be cleaned up by scope leave. | 74 | | - return; | | 74 | + return false; | 75 | 75 | } | 76 | 76 | uv_fs_req_cleanup(&req); | 77 | 77 |
| @@ -89,7 +89,7 @@ void Dotenv::ParsePath(const std::string_view path) { | 89 | 89 | auto r = uv_fs_read(nullptr, &req, file, &buf, 1, -1, nullptr); | 90 | 90 | if (req.result < 0) { | 91 | 91 | // req will be cleaned up by scope leave. | 92 | | - return; | | 92 | + return false; | 93 | 93 | } | 94 | 94 | uv_fs_req_cleanup(&req); | 95 | 95 | if (r <= 0) { | @@ -104,6 +104,7 @@ void Dotenv::ParsePath(const std::string_view path) { | 104 | 104 | for (const auto& line : lines) { | 105 | 105 | ParseLine(line); | 106 | 106 | } | | 107 | + return true; | 107 | 108 | } | 108 | 109 |
| 109 | 110 | void Dotenv::AssignNodeOptionsIfAvailable(std::string* node_options) { | |
Collapse file Copy file name to clipboardExpand all lines: src/node_dotenv.h +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -18,7 +18,7 @@ class Dotenv { | 18 | 18 | Dotenv& operator=(const Dotenv& d) = default; | 19 | 19 | ~Dotenv() = default; | 20 | 20 |
| 21 | | - void ParsePath(const std::string_view path); | | 21 | + bool ParsePath(const std::string_view path); | 22 | 22 | void AssignNodeOptionsIfAvailable(std::string* node_options); | 23 | 23 | void SetEnvironment(Environment* env); | 24 | 24 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-dotenv-edge-cases.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -34,8 +34,8 @@ describe('.env supports edge cases', () => { | 34 | 34 | [ '--env-file=.env', '--eval', code ], | 35 | 35 | { cwd: __dirname }, | 36 | 36 | ); | 37 | | - assert.strictEqual(child.stderr, ''); | 38 | | - assert.strictEqual(child.code, 0); | | 37 | + assert.notStrictEqual(child.stderr.toString(), ''); | | 38 | + assert.strictEqual(child.code, 9); | 39 | 39 | }); | 40 | 40 |
| 41 | 41 | it('should not override existing environment variables but introduce new vars', async () => { | |
|