Skip to content

refactor(src): migrate jobs commands to AppError, drop 484 LOC#83

Merged
saagpatel merged 1 commit intomasterfrom
codex/refactor/app-error-jobs
Apr 22, 2026
Merged

refactor(src): migrate jobs commands to AppError, drop 484 LOC#83
saagpatel merged 1 commit intomasterfrom
codex/refactor/app-error-jobs

Conversation

@saagpatel
Copy link
Copy Markdown
Owner

Summary

Two changes bundled because the dead mod.rs job wrappers don't delegate to jobs_commands::* — they're full reimplementations, so deleting them is orthogonal to the migration and pulls in cleanly.

1. Migrate jobs_commands.rs (10 commands)

All ten move from Result<T, String> to Result<T, AppError>:

  • DB-bound commands (create_job, list_jobs, get_job, cancel_job, get_job_logs, get_job_counts, cleanup_old_jobs) route through AppError::db_lock_failed / db_not_initialized / db_query_failed.
  • batch_generateempty_input("Inputs list"), model_not_loaded(), ValidationError auto-converts.
  • get_batch_status / export_batch_results — introduced local job_not_found(id) helper routed to NotFound category with code NOT_FOUND_JOB (no dedicated constructor exists for job records yet).
  • Filesystem errors in the export path — via existing From<io::Error> impl.
  • Invalid format / unsupported exportAppError::invalid_format.
  • serde_json serialize failuresAppError::internal(detail).

2. Delete 484 LOC of dead mod.rs duplicates

Same pattern as PR #82 (Jira). Two dead blocks in commands/mod.rs:

  • Lines 3993-4119 (Job Commands section): duplicate JobSummary struct + 7 wrappers that reimplement the DB-bound commands with their own queries
  • Lines 4968-5324 (Phase 9: Batch Processing Commands section): duplicate BatchInput / BatchResult / BatchSource / BatchStatus structs + full reimplementations of batch_generate / get_batch_status / export_batch_results

Neither block was registered (registry points at jobs_commands::*), neither was called externally. mod.rs: 5592 → 5108 lines.

Test plan

  • cargo check --all-targets — clean, zero warnings
  • cargo test --lib — 311 pass, 1 ignored
  • cargo test --test command_contracts — 8 pass
  • pnpm test — 67 files, 262 tests pass
  • Frontend audit: no exact-string matches on jobs error messages

🤖 Generated with Claude Code

Two changes bundled because the dead mod.rs wrappers don't delegate to
jobs_commands::* — they're full reimplementations, so deleting them is
orthogonal to the migration.

1. Migrate jobs_commands.rs (10 commands) from Result<T, String> to
   Result<T, AppError>:
   - create_job / list_jobs / get_job / cancel_job / get_job_logs /
     get_job_counts / cleanup_old_jobs — all route through
     AppError::db_lock_failed / db_not_initialized / db_query_failed
   - Invalid job type or unsupported export format -> invalid_format
   - Empty input list -> empty_input("Inputs list")
   - No model loaded -> model_not_loaded()
   - Job not found -> custom NOT_FOUND_JOB code with id as detail
     (we don't have a dedicated constructor for job records, so
     introduced a local job_not_found(id) helper routed to the
     NotFound category)
   - filesystem write errors -> AppError::from(io::Error) via the
     existing From impl
   - serde_json serialize errors in the export path -> internal()

2. Delete ~484 LOC of dead mod.rs duplicates:
   - commands/mod.rs lines 3993-4119 (Job Commands section): duplicate
     JobSummary struct + 7 wrappers that reimplement create_job /
     list_jobs / get_job / cancel_job / get_job_logs / get_job_counts /
     cleanup_old_jobs with their own DB queries.
   - commands/mod.rs lines 4968-5324 (Phase 9: Batch Processing
     Commands section): duplicate BatchInput / BatchResult /
     BatchSource / BatchStatus structs + full reimplementations of
     batch_generate / get_batch_status / export_batch_results.
   - None were registered (registry.rs points at jobs_commands::*),
     none were called externally. Same dead-duplicate pattern as the
     Jira block cleaned up in PR #82.

mod.rs: 5592 -> 5108 lines (-484).

Verified:
- cargo check --all-targets clean, zero warnings
- cargo test --lib: 311 pass, 1 ignored
- cargo test --test command_contracts: 8 pass
- pnpm test: 67 files, 262 tests pass
- No frontend exact-string matches on jobs errors
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.

2 participants