refactor(src): migrate draft commands to AppError#88
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continuation of ADR 0012 migration.
draft_commands.rs— the biggest file yet at 38 Tauri commands plus 7_implhelpers — all migrated toResult<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) -> AppErrorhelper 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_faileddb_not_initializeddb_query_failed(viadb_query_err)validate_non_empty→ValidationErrorFrom impl auto-converts"Choice must be 'original' or 'alternative'"→invalid_formatCompatibility bridging
7 delegating wrappers in
commands/mod.rscalldraft_commands::*_impland needed.map_err(|e| e.to_string())bridges to keep returningResult<_, 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— cleancargo test --lib— 311 pass, 1 ignoredcargo test --test command_contracts— 8 pass🤖 Generated with Claude Code