Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 78bb945

Browse files
committed
chore: make optional .env loading best-effort
1 parent 12d1bdb commit 78bb945

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/__tests__/extension.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ describe("extension.ts", () => {
245245

246246
test("does not call dotenvx.config when optional .env does not exist", async () => {
247247
vi.resetModules()
248+
vi.clearAllMocks()
248249

249250
const fs = await import("fs")
250251
vi.mocked(fs.existsSync).mockReturnValue(false)
@@ -259,6 +260,7 @@ describe("extension.ts", () => {
259260

260261
test("calls dotenvx.config when optional .env exists", async () => {
261262
vi.resetModules()
263+
vi.clearAllMocks()
262264

263265
const fs = await import("fs")
264266
vi.mocked(fs.existsSync).mockReturnValue(true)

src/extension.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import * as fs from "fs"
44
import * as path from "path"
55

66
// Load environment variables from .env file
7-
try {
8-
// The extension-level .env is optional (not shipped in production builds).
9-
// Avoid calling dotenvx when the file doesn't exist, otherwise dotenvx emits
10-
// a noisy [MISSING_ENV_FILE] error to the extension host console.
11-
const envPath = path.join(__dirname, "..", ".env")
12-
if (fs.existsSync(envPath)) {
7+
// The extension-level .env is optional (not shipped in production builds).
8+
// Avoid calling dotenvx when the file doesn't exist, otherwise dotenvx emits
9+
// a noisy [MISSING_ENV_FILE] error to the extension host console.
10+
const envPath = path.join(__dirname, "..", ".env")
11+
if (fs.existsSync(envPath)) {
12+
try {
1313
dotenvx.config({ path: envPath })
14+
} catch (e) {
15+
// Best-effort only: never fail extension activation due to optional env loading.
16+
console.warn("Failed to load environment variables:", e)
1417
}
15-
} catch {
16-
// Best-effort only: never fail extension activation due to optional env loading.
1718
}
1819

1920
import type { CloudUserInfo, AuthState } from "@roo-code/types"

0 commit comments

Comments
 (0)