fix(config): throw typed EnvValidationError from validateEnv instead of process.exit - #228
Open
Jatinprajapati7869 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
validateEnv()no longer callsprocess.exit(1)inline on validation failure (finding M7 indocs/ISSUES.md). It now throws a typedEnvValidationErrorcarrying every individual failure message in anerrors: string[]payload. The boot boundary inserver.tscatches this error, logs each failure in the exact same format as before, and exits with code 1 so the decision to terminate the process is owned by the entrypoint, not by a validation helper. This makes the validator unit-testable (previously any failing test killed the test runner) and safe for future non-boot callers. Boot behaviour is unchanged and proven by a new smoke test that runs the real entrypoint with an invalid environment and asserts exit code 1.Related issue
Closes #227
Type of change
Area affected
/admin/*)/communityposts, comments, auto-answer)CI verification
cd apps/backend && npx tsc --noEmitexits 0cd apps/backend && npx vitest runall tests pass (6 pre-existing failures onmain, unrelated details below)cd apps/frontend && npx tsc --noEmitexits 0cd apps/frontend && npx vitest runall tests passpnpm run lint0 errors (1 pre-existing error onmain, unrelated details below)main, no merge commitsNotes for reviewer
Behaviour contract (unchanged): an invalid environment still prevents startup with exit code 1 and identical log output (
Environment validation failed:+ one- <error>line each). This is verified end-to-end bysrc/__tests__/server-boot.test.ts, which spawns the realsrc/server.tsvia tsx withMONGODB_URI/JWT_SECRETremoved nothing mocked.API change (intentional): any future caller of
validateEnv()now receives a catchableEnvValidationErrorinstead of having its process killed.server.tsis currently the only caller.Tests added (9):
src/config/__tests__/envValidator.test.ts- missing/malformedMONGODB_URI, missing/shortJWT_SECRET, non-numericPORT, multiple failures aggregated into one error, valid env passes (8 tests).src/__tests__/server-boot.test.ts— boot-boundary smoke test (1 test).Deliberately untested: the two-line rethrow of non-
EnvValidationErrorexceptions inserver.ts. Covering it would require fault-injection hooks in the validator, which conflicts with keeping this a single minimal change.Pre-existing failures on
main(not caused by this PR):src/__tests__/journey-tracks.test.ts- 6 tests fail on a pristine clone ofmain(500 vs expected 200/404/400). Verified identical before/after this change.pnpm run lint1 pre-existing error onmain(no-constant-conditioninsrc/modules/ai/ai-client.service.ts:623). The four files in this PR lint with 0 errors and 0 warnings.