Skip to content

refactor(src): migrate draft commands to AppError#88

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

refactor(src): migrate draft commands to AppError#88
saagpatel merged 1 commit intomasterfrom
codex/refactor/app-error-draft-commands

Conversation

@saagpatel
Copy link
Copy Markdown
Owner

Summary

Continuation of ADR 0012 migration. draft_commands.rs — the biggest file yet at 38 Tauri commands plus 7 _impl helpers — all migrated to Result<T, AppError>.

Covers drafts, autosaves, versions, playbooks, action shortcuts, templates, custom variables, saved response templates, and response alternatives.

Structural improvement

Added a db_query_err(e: impl Display) -> AppError helper to collapse the repetitive .map_err(|e| AppError::db_query_failed(e.to_string())) down to .map_err(db_query_err) across every DB call. Makes each command body a single-line read.

Error mapping

  • DB lock → db_lock_failed
  • DB not initialized → db_not_initialized
  • DB queries → db_query_failed (via db_query_err)
  • validate_non_emptyValidationError From impl auto-converts
  • "Choice must be 'original' or 'alternative'"invalid_format

Compatibility bridging

7 delegating wrappers in commands/mod.rs call draft_commands::*_impl and needed .map_err(|e| e.to_string()) bridges to keep returning Result<_, String>. The larger ~1000 LOC dead-code block (~38 wrappers across two sections in mod.rs) is flagged as a separate follow-up task — same cleanup pattern as PR #82 (Jira), #83 (Jobs), #85 (Ops-Analytics).

Test plan

  • cargo check --all-targets — clean
  • cargo test --lib — 311 pass, 1 ignored
  • cargo test --test command_contracts — 8 pass

🤖 Generated with Claude Code

Continue ADR 0012 migration. draft_commands.rs is the biggest file
yet - 38 Tauri commands + 7 _impl helpers covering drafts,
autosaves, versions, playbooks, action shortcuts, templates, custom
variables, saved response templates, and response alternatives.

Added a db_query_err(e: Display) helper to collapse the repeated
.map_err(|e| AppError::db_query_failed(e.to_string())) pattern to
.map_err(db_query_err) across every DB call. Otherwise the change
is a uniform signature swap from Result<T, String> to
Result<T, AppError>.

Error mapping:
- DB lock -> db_lock_failed
- DB not initialized -> db_not_initialized
- DB queries -> db_query_failed (via db_query_err helper)
- validate_non_empty -> ValidationError From impl auto-converts
- "Choice must be 'original' or 'alternative'" -> invalid_format

mod.rs bridges: 7 delegating wrappers in mod.rs call
draft_commands::*_impl and need a .map_err(|e| e.to_string())
bridge to keep returning Result<_, String>. The larger block of
~38 dead duplicate wrappers in mod.rs (~1000 LOC total across two
sections) is a separate follow-up task.

Verified:
- cargo check --all-targets clean
- cargo test --lib: 311 pass, 1 ignored
- cargo test --test command_contracts: 8 pass
@saagpatel saagpatel merged commit 79b7532 into master Apr 22, 2026
@saagpatel saagpatel deleted the codex/refactor/app-error-draft-commands branch April 22, 2026 13:12
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