Skip to content

Replace 45 non-null assertions with explicit handling: crash-on-null paths are hidden in compiled code #1083

Closed

Description

@nanaf6203-bit

Replace 45 non-null assertions with explicit handling: crash-on-null paths are hidden in compiled code

Labels / Complexity: bug · Medium Complexity — Medium

Problem

The codebase contains 45 non-null assertion operators (!) on values that are not statically guaranteed present (verified with a repository-wide grep). Each one is a runtime undefined/null dereference waiting to happen: the type system is told "trust me", and when the value is absent at runtime the failure is a generic TypeError instead of a typed error, often inside a request handler with no context.

  • The failures are silent until they crash. Because ! suppresses the check at compile time, the first signal is a runtime exception in production, not a type error in CI.
  • The assertion sites are the risk map. They cluster where the code already doubts its data (conditional access, optional fields, map lookups) — exactly the paths that deserve explicit if/throw handling with typed errors.

Why this is architecturally hard

  1. Each site needs a decision. The fix is not a mechanical ! → ? swap: every site must decide between a typed NotFoundException/BadRequestException, a default value, or a genuine invariant (in which case the assertion should be a checked helper, not a bare !).
  2. The error contract must stay consistent. The repo uses NestJS exceptions; replacing crash sites with the right exception type is part of the fix, and the API error shape must not change for callers.
  3. Slicing is required. 45 sites span many modules; the migration should land per module so each PR is reviewable and the remaining count is tracked.

Acceptance criteria

  • Every non-null assertion is replaced with explicit handling: a typed exception, a default, or a documented checked invariant.
  • The repository-wide ! count on non-typed values is zero (or the remaining sites are documented invariants with a checked helper).
  • npx tsc --noEmit and npm test pass; no behavior change for valid inputs.

Out of scope

The @ts-nocheck migrations (#890 slices); changing API error messages.

Getting started

  • Repository-wide: grep -rn "!" src --include=*.ts to enumerate sites
  • src/common/ — where a checked invariant helper would live

Commands: npx tsc --noEmit, npm test.

Good first files to read: one module's service with the most assertion sites, then src/common/.

Activity

  1. kaizercodes commented on Aug 26, 2026

    @kaizercodes

    @kaizercodes has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    hi maintainer, can i work on this?

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @kaizercodes to this issue.

  2. Teejay2696 commented on Aug 26, 2026

    @Teejay2696

    @Teejay2696 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    I can do this Maintainer
    Let me get to work already

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Teejay2696 to this issue.

  3. codewithzubair07 commented on Aug 26, 2026

    @codewithzubair07

    @codewithzubair07 has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    i would like to work on this issue

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @codewithzubair07 to this issue.

  4. shadrackmanfred commented on Aug 26, 2026

    @shadrackmanfred
    Contributor

    @shadrackmanfred has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hi Maintainer! I'm a senior developer with experience building high-quality, production-ready software. I'd love to take on this issue and deliver a clean, well-tested solution that aligns with the project's standards. Please assign it to me—I'm ready to get started and contribute effectively.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @shadrackmanfred to this issue.

  5. drips-wave commented on Aug 26, 2026

    @drips-wave

    Congratulations, @shadrackmanfred! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.

    🧑‍💻 @shadrackmanfred: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  6. shadrackmanfred commented on Aug 28, 2026

    @shadrackmanfred
    Contributor

    Resolved on branch fix/type-safety-and-admin-tests (commit 1f932bf): all runtime non-null assertions in src/ replaced with typed exceptions, defaults, or narrowed conditions (runtime ! count 45 → 0). Verified: tsc --noEmit clean, 71 suites / 515 unit tests pass. PR is pending push from a token with write access.

  7. shadrackmanfred commented on Aug 29, 2026

    @shadrackmanfred
    Contributor

    test

  8. shadrackmanfred commented on Sep 1, 2026

    @shadrackmanfred
    Contributor

    Addressed by #1171.

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions