Skip to content

Quality: Non-null assertions on potentially undefined env vars will crash at module load - #479

Open
kumburovicbranko682-boop wants to merge 1 commit into
kurrier-org:mainfrom
kumburovicbranko682-boop:contribai/improve/quality/non-null-assertions-on-potentially-undef
Open

Quality: Non-null assertions on potentially undefined env vars will crash at module load#479
kumburovicbranko682-boop wants to merge 1 commit into
kurrier-org:mainfrom
kumburovicbranko682-boop:contribai/improve/quality/non-null-assertions-on-potentially-undef

Conversation

@kumburovicbranko682-boop

Copy link
Copy Markdown

Problem

getServerEnv() likely returns an object where properties may be undefined if
the corresponding env vars are missing. The non-null assertions (!) on
S3_REGION, S3_ACCESS_KEY, and S3_SECRET_KEY will silently pass undefined
to the S3 client constructor, which will only fail later at runtime when an actual
S3 operation is attempted — producing a confusing error far from the root cause.
Unlike the drizzle.config.ts file which wraps with String(), these values
are asserted non-null without any validation, so a missing env var crashes
with an opaque AWS SDK error instead of a clear startup failure.

Severity: high
File: packages/common/src/common-utils.ts

Solution

Add explicit validation at module init so the process fails fast with a clear message:

Changes

  • packages/common/src/common-utils.ts (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

…rs will crash at module load

`getServerEnv()` likely returns an object where properties may be `undefined` if
the corresponding env vars are missing. The non-null assertions (`!`) on
`S3_REGION`, `S3_ACCESS_KEY`, and `S3_SECRET_KEY` will silently pass `undefined`
to the S3 client constructor, which will only fail later at runtime when an actual
S3 operation is attempted — producing a confusing error far from the root cause.
Unlike the `drizzle.config.ts` file which wraps with `String()`, these values
are asserted non-null without any validation, so a missing env var crashes
with an opaque AWS SDK error instead of a clear startup failure.


Affected files: common-utils.ts

Signed-off-by: kumburovicbranko682-boop <295886834+kumburovicbranko682-boop@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant