Skip to content

Commit

Permalink
Make debug log for .env not found less scary (#7272)
Browse files Browse the repository at this point in the history
  • Loading branch information
penalosa authored Nov 28, 2024
1 parent 98d2725 commit a3f56d1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/four-zebras-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Make debug log for `.env` not found less scary
8 changes: 8 additions & 0 deletions packages/wrangler/src/__tests__/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,14 @@ describe.sequential("wrangler dev", () => {
const output = fs.readFileSync("var.txt", "utf8");
expect(output).toMatch("custom");
});
it("should show reasonable debug output if `.env` does not exist", async () => {
fs.rmSync(".env");
writeWranglerConfig({
main: "index.js",
});
await runWranglerUntilConfig("dev --log-level debug");
expect(std.debug).toContain(".env file not found at");
});
});
});

Expand Down
8 changes: 7 additions & 1 deletion packages/wrangler/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,13 @@ function tryLoadDotEnv(path: string): DotEnv | undefined {
const parsed = dotenv.parse(fs.readFileSync(path));
return { path, parsed };
} catch (e) {
logger.debug(`Failed to load .env file "${path}":`, e);
if ((e as { code: string }).code === "ENOENT") {
logger.debug(
`.env file not found at "${path}". Continuing... For more details, refer to https://developers.cloudflare.com/workers/wrangler/system-environment-variables/`
);
} else {
logger.debug(`Failed to load .env file "${path}":`, e);
}
}
}

Expand Down

0 comments on commit a3f56d1

Please sign in to comment.