Skip to content

[I-001] [Tech Debt]: Remove all unwrap() calls from production code #357

Closed

Description

@indpurvesh

Priority: High
Phase: Phase 1 (Code Quality)
Dependencies: None


📝 User Story

As a developer / operator,
I want to eliminate every unwrap() in production paths,
So that the CMS never panics unexpectedly in production and returns meaningful errors instead.


🎯 Scope & Requirements

  • Replace unwrap() in main.rs (lines 7, 15, 18) with proper error propagation (? operator or graceful exit with eprintln!)
  • Replace unwrap() in auth_middleware.rs (lines 28, 73) with ? returning an appropriate UNAUTHORIZED response
  • Replace unwrap() in rest_api_routes.rs (line 64) with map_err or filter_map
  • Replace unwrap() in workflow_dispatcher.rs (IP parse calls, lines 284-295) with compile-time validated constants or expect() with justification
  • Replace unwrap() in login_page.rs (line 79) with user-facing error handling
  • Replace unwrap() in workflow.rs domain entity serde calls (lines 66-108) with proper error propagation

✅ Acceptance Criteria

  • Given the full src/ tree, When grep -rn 'unwrap()' src/ is run, Then zero results are returned (or all remaining uses have // SAFETY: justification).
  • Given an invalid CORS origin in .env, When the server starts, Then a descriptive error is logged instead of a panic.
  • Given a malformed Authorization header, When a request hits the auth middleware, Then a 401 JSON error is returned without a panic.

🛠️ Technical Context / Notes

  • Files affected: main.rs, auth_middleware.rs, rest_api_routes.rs, workflow_dispatcher.rs, login_page.rs, workflow.rs
  • Consider adding #![deny(clippy::unwrap_used)] to lib.rs after cleanup.

📋 Task Checklist

  • Audit all unwrap() call sites (19 identified)
  • Replace each with ?, map_err, unwrap_or_default, or justified expect()
  • Add clippy::unwrap_used deny lint
  • Verify all existing tests still pass

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions