Quality: Non-null assertions on potentially undefined env vars will crash at module load - #479
Open
kumburovicbranko682-boop wants to merge 1 commit into
Conversation
…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>
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.
Problem
getServerEnv()likely returns an object where properties may beundefinedifthe corresponding env vars are missing. The non-null assertions (
!) onS3_REGION,S3_ACCESS_KEY, andS3_SECRET_KEYwill silently passundefinedto 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.tsfile which wraps withString(), these valuesare 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:
highFile:
packages/common/src/common-utils.tsSolution
Add explicit validation at module init so the process fails fast with a clear message:
Changes
packages/common/src/common-utils.ts(modified)Testing