Skip to content

fix: replace non-null assertions with explicit handling - #1171

Merged
nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
shadrackmanfred:fix/1083-non-null-assertions
Sep 1, 2026
Merged

fix: replace non-null assertions with explicit handling#1171
nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
shadrackmanfred:fix/1083-non-null-assertions

Conversation

@shadrackmanfred

Copy link
Copy Markdown
Contributor

Summary

Replaces every non-null assertion operator (!) in src/ with explicit handling so that missing values surface as typed, contextual errors (or safe defaults) instead of generic TypeErrors at runtime. Count of real assertion sites in src/: 45 → 0.

What changed

Area Before After
cache / notifications / duplicate-detection map.get(x)!.add(y) after a guarded has() check fall back to a fresh Set / existing map entry, then re-insert (?? new Set(), or reuse the entry when present)
properties dto.lat! / dto.lng! inside the radius bounding-box math lat/lng captured up front and validated with the existing BadRequestException('Both lat and lng must be provided together'); math uses narrowed locals
auth data.totpCode! / data.backupCode! in 2FA login code grabbed into a local and guarded with UnauthorizedException before verification
property-comparison properties.find(...)! per-id lookup throws NotFoundException if a property is missing
neighborhoods neighborhood!.metadata explicit NotFoundException after findUnique
versioning toHttpDate(meta.sunsetDate)! Sunset header set only when a date resolves
specs (analytics, login-rate-limit, support-tickets, email-digest) prisma.requestLog!, info!, supportTicket!, digestPreference! mocks fully typed with MockPrisma-style interfaces; stats?.x assertions instead of !

No behavior change for valid inputs — the same exceptions (NotFoundException / BadRequestException / UnauthorizedException) that existed are preserved, and the API error contract is unchanged.

Verification

  • npx tsc --noEmit — no new errors vs main (baseline carries 2 pre-existing errors in untouched files: sessions.service.ts and version-header.interceptor.spec.ts)
  • npm test — all affected suites pass; the only failing suite (version-header.interceptor.spec.ts:111) fails identically on main
  • Remaining ! matches in src/ after this change are all inside string literals or comments

Closes #1083

Remove all non-null assertion operators in src/ so null paths surface
typed errors or defaults instead of crashing with a generic TypeError.

- cache/notifications/duplicate-detection: fall back to a fresh Set or
  existing map entry instead of asserting presence after a guarded get
- properties: validate lat/lng upfront and use narrowed locals for the
  radius bounding-box math
- auth: guard TOTP/backup codes before verifying 2FA
- property-comparison/neighborhoods: throw NotFoundException when a
  looked-up entity is missing
- versioning: only set the Sunset header when a date resolves
- specs: type prisma mocks fully so requestLog!/supportTicket!/
  digestPreference!/info! assertions are no longer needed
@drips-wave

drips-wave Bot commented Sep 1, 2026

Copy link
Copy Markdown

@shadrackmanfred Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nanaf6203-bit
nanaf6203-bit merged commit 8028d44 into MettaChain:main Sep 1, 2026
1 of 4 checks passed
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.

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

2 participants