Skip to content

Commit 85be2b6

Browse files
Simplify ENOENT debug logs for .env files (#10427)
--------- Co-authored-by: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 7c339ae commit 85be2b6

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

.changeset/green-bugs-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Simplify ENOENT debug logs for `.env` files

packages/wrangler/src/__tests__/dev.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,17 @@ describe.sequential("wrangler dev", () => {
11181118
__DOT_ENV_TEST_CUSTOM_BUILD_VAR_LOCAL=other-local"
11191119
`);
11201120
});
1121+
1122+
it("should show reasonable debug output if `.env` does not exist", async () => {
1123+
fs.rmSync(".env");
1124+
writeWranglerConfig({
1125+
main: "index.js",
1126+
});
1127+
await runWranglerUntilConfig("dev --log-level debug");
1128+
expect(std.debug).toContain(
1129+
'.env file not found at "<cwd>/.env". Continuing... For more details, refer to https://developers.cloudflare.com/workers/wrangler/system-environment-variables/'
1130+
);
1131+
});
11211132
});
11221133
});
11231134

packages/wrangler/src/config/dot-env.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ export function loadDotEnv(
4949
override: true,
5050
});
5151
if (error) {
52-
logger.debug(`Failed to load .env file "${envPath}":`, error);
52+
if ("code" in error && error.code === "ENOENT") {
53+
logger.debug(
54+
`.env file not found at "${envPath}". Continuing... For more details, refer to https://developers.cloudflare.com/workers/wrangler/system-environment-variables/`
55+
);
56+
} else {
57+
logger.debug(`Failed to load .env file "${envPath}":`, error);
58+
}
5359
} else if (parsed && !silent) {
5460
const relativePath = path.relative(process.cwd(), envPath);
5561
logger.log(`Using vars defined in ${relativePath}`);

0 commit comments

Comments
 (0)