Skip to content

Eliminate All 251 Request-Path Panics and Introduce Fail-Fast Typed Startup Configuration #339

Description

@Christopherdominic

Summary

src/ contains 251 unwrap()/expect() call sites. Several sit on hot request paths where a panic aborts the task servicing a live request; the worst pattern is configuration read per call instead of at startup:

// src/services/auth_service.rs:13
fn jwt_secret() -> String {
    std::env::var("JWT_SECRET").expect("JWT_SECRET must be set")
}

A missing/corrupted env var here panics inside token issuance/verification at runtime, rather than failing deployment at boot. The same late-read pattern appears across config consumers (e.g. cors_layer_from_env parses env on construction with silent fallbacks).

Task

  1. Introduce a typed, validated AppConfig loaded and validated once at startup (fail-fast with a precise, aggregated error report listing all missing/invalid variables, not just the first). Include: database, Redis, JWT (secret length/entropy minimum enforced), SMTP, CORS, rate limits, webhook secrets.
  2. Thread AppConfig through AppState; delete every runtime std::env::var read outside the config loader (grep-enforceable).
  3. Audit all 251 unwrap()/expect() sites and classify:
    • request-path sites → convert to typed AppError propagation with correct status codes
    • startup-path sites → move behind config validation or keep with a documented invariant comment
    • test-only sites → out of scope
      Include the classification table in the PR description.
  4. Enforce regression prevention: enable clippy::unwrap_used and clippy::expect_used as deny for src/ (allow in #[cfg(test)]), wired into the lint configuration.
  5. Add a startup-failure integration test: boot with an intentionally missing JWT_SECRET and assert a clean, aggregated config error (no panic backtrace, no partial boot).

Acceptance criteria

  • Zero std::env::var outside the config module; zero unwrap()/expect() in non-test request-path code
  • clippy::unwrap_used/expect_used deny-level active and passing
  • Misconfigured boot exits with an aggregated human-readable error, verified by test
  • No behavioral changes for valid configurations; all checks pass

PR requirements (mandatory)

  • ✅ Your PR must pass all checks — PRs with failing or skipped checks will not be merged.
  • 📸 You must attach a screenshot in the PR description demonstrating the result (for this issue: the aggregated startup validation error output plus the clean clippy run).
  • 🔗 You must link this issue number in your PR description (e.g. Closes #<issue-number>). PRs without a linked issue will not be reviewed.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26architectureStructural or architectural changebugSomething isn't workingdifficulty: very hardRequires deep expertise and substantial effort

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions