src: return error --env-file if file is not found · nodejs/node@6f46d31 · GitHub
Skip to content

Commit 6f46d31

Browse files
arxngrUlisesGascon
authored andcommitted
src: return error --env-file if file is not found
PR-URL: #50588 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent bb7d764 commit 6f46d31

4 files changed

Lines changed: 10 additions & 7 deletions

File tree

src/node.cc

Lines changed: 3 additions & 1 deletion

src/node_dotenv.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ void Dotenv::SetEnvironment(node::Environment* env) {
6464
}
6565
}
6666

67-
void Dotenv::ParsePath(const std::string_view path) {
67+
bool Dotenv::ParsePath(const std::string_view path) {
6868
uv_fs_t req;
6969
auto defer_req_cleanup = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); });
7070

7171
uv_file file = uv_fs_open(nullptr, &req, path.data(), 0, 438, nullptr);
7272
if (req.result < 0) {
7373
// req will be cleaned up by scope leave.
74-
return;
74+
return false;
7575
}
7676
uv_fs_req_cleanup(&req);
7777

@@ -89,7 +89,7 @@ void Dotenv::ParsePath(const std::string_view path) {
8989
auto r = uv_fs_read(nullptr, &req, file, &buf, 1, -1, nullptr);
9090
if (req.result < 0) {
9191
// req will be cleaned up by scope leave.
92-
return;
92+
return false;
9393
}
9494
uv_fs_req_cleanup(&req);
9595
if (r <= 0) {
@@ -104,6 +104,7 @@ void Dotenv::ParsePath(const std::string_view path) {
104104
for (const auto& line : lines) {
105105
ParseLine(line);
106106
}
107+
return true;
107108
}
108109

109110
void Dotenv::AssignNodeOptionsIfAvailable(std::string* node_options) {

src/node_dotenv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Dotenv {
1818
Dotenv& operator=(const Dotenv& d) = default;
1919
~Dotenv() = default;
2020

21-
void ParsePath(const std::string_view path);
21+
bool ParsePath(const std::string_view path);
2222
void AssignNodeOptionsIfAvailable(std::string* node_options);
2323
void SetEnvironment(Environment* env);
2424

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

Lines changed: 2 additions & 2 deletions

0 commit comments

Comments
 (0)