Skip to content

fix(obligatron): Only read .env locally#1860

Merged
akash1810 merged 1 commit intomainfrom
aa/obligatron-env
Mar 13, 2026
Merged

fix(obligatron): Only read .env locally#1860
akash1810 merged 1 commit intomainfrom
aa/obligatron-env

Conversation

@akash1810
Copy link
Member

@akash1810 akash1810 commented Mar 12, 2026

What does this change?

The changes in #1859 is producing runtime errors in PROD:

Uncaught Exception {"errorType":"Error","errorMessage":"ENOENT: no such file or directory, open '../../.env'","code":"ENOENT","errno":-2,"syscall":"open","path":"../../.env","stack":["Error: ENOENT: no such file or directory, open '../../.env'"," at loadEnvFile (node:internal/process/per_thread:260:7)"," at Object. (/var/task/index.js:22868:37)"," at Module._compile (node:internal/modules/cjs/loader:1521:14)"," at Module._extensions..js (node:internal/modules/cjs/loader:1623:10)"," at Module.load (node:internal/modules/cjs/loader:1266:32)"," at Module._load (node:internal/modules/cjs/loader:1091:12)"," at Module.require (node:internal/modules/cjs/loader:1289:19)"," at require (node:internal/modules/helpers:182:18)"," at _tryRequireFile (file:///var/runtime/index.mjs:1092:37)"," at _tryRequire (file:///var/runtime/index.mjs:1151:25)"]}

The .env file holds variables for use locally; this file is not included in production artifacts. This change updates obligatron to read .env within run-locally.ts.

Prior to PR #1859 we were using dotenv to read .env. It appears that dotenv silently continues if a file does not exist, which is why we hadn't seen this issue previously. See https://github.com/motdotla/dotenv/blob/4e5f0e9a08abd5cf0dbcf2c30a68509aa223d371/lib/main.js#L283-L293.

How has it been verified?

After deploying to CODE and invoking the lambda, the above issue has been removed from the logs (screenshot below) and the lambda runs successfully.

image

The changes in #1859 is producing runtime errors in PROD:

> Uncaught Exception 	{"errorType":"Error","errorMessage":"ENOENT: no such file or directory, open '../../.env'","code":"ENOENT","errno":-2,"syscall":"open","path":"../../.env","stack":["Error: ENOENT: no such file or directory, open '../../.env'","    at loadEnvFile (node:internal/process/per_thread:260:7)","    at Object.<anonymous> (/var/task/index.js:22868:37)","    at Module._compile (node:internal/modules/cjs/loader:1521:14)","    at Module._extensions..js (node:internal/modules/cjs/loader:1623:10)","    at Module.load (node:internal/modules/cjs/loader:1266:32)","    at Module._load (node:internal/modules/cjs/loader:1091:12)","    at Module.require (node:internal/modules/cjs/loader:1289:19)","    at require (node:internal/modules/helpers:182:18)","    at _tryRequireFile (file:///var/runtime/index.mjs:1092:37)","    at _tryRequire (file:///var/runtime/index.mjs:1151:25)"]}

The `.env` file holds variables for use locally; this file is not included in production artifacts.
This change updates obligatron to read `.env` within `run-locally.ts`.

Prior to PR #1859 we were using `dotenv` to read `.env`.
It appears that `dotenv` silently continues if a file does not exist,
which is why we hadn't seen this issue previously.
See https://github.com/motdotla/dotenv/blob/4e5f0e9a08abd5cf0dbcf2c30a68509aa223d371/lib/main.js#L283-L293.
@akash1810 akash1810 marked this pull request as ready for review March 12, 2026 10:39
@akash1810 akash1810 requested review from a team as code owners March 12, 2026 10:39
@akash1810 akash1810 added the fix Departmental tracking: fix label Mar 12, 2026
@akash1810 akash1810 enabled auto-merge March 12, 2026 11:43
@akash1810 akash1810 merged commit d3d37f0 into main Mar 13, 2026
11 checks passed
@akash1810 akash1810 deleted the aa/obligatron-env branch March 13, 2026 09:27
@akash1810
Copy link
Member Author

This has deployed to PROD now. I've manually run the obligatron lambda; the logs show its working as expected again 🎉 :

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Departmental tracking: fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants