refactor(errors): unified AgentflareError for MCP dispatch helpers - #176
Merged
Conversation
Adds AgentflareError (src/errors.rs) wrapping the heterogeneous error sources a handful of MCP dispatch-layer helpers touch (mutex poison, rusqlite, skill_registry::LoadError, agentflare_backend::Error), plus impl From<AgentflareError> for ErrorData so callers convert once, at their own '?', instead of every intermediate step needing its own .map_err(|e| ErrorData::internal_error(e.to_string(), None)). Converts with_fresh_registry, resolve_workspace_id, and claim_db to return crate::errors::Result<T> internally; their own call sites (skill_search, skill_load, handoff, resolve_project, asset x2) already used '?' and needed no changes at all — the new From impl is what makes that '?' work against the tightened internal error type. 5 explicit .map_err(...) call sites collapse to plain '?' across the 3 helpers.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe change adds a unified ChangesMCP error propagation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
3 tasks
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
Several internal MCP dispatch-layer helpers touch more than one heterogeneous fallible source (mutex lock, rusqlite, a sub-crate registry, agentflare-backend) and manually map each one with
.map_err(|e| ErrorData::internal_error(e.to_string(), None))?— repetitive boilerplate the same pattern the codebase already avoids for backend errors viamap_backend_err.Fix
AgentflareError(src/errors.rs), wrapping: mutex-lock poisoning,rusqlite::Error,std::io::Error,skill_registry::LoadError,agentflare_backend::Error— pluspub type Result<T> = std::result::Result<T, AgentflareError>.impl From<AgentflareError> for ErrorData(src/mcp_server.rs, next tomap_backend_err, which it delegates to for theBackendvariant so existing error-code behavior —INVALID_PARAMSvsinternal_error— is unchanged).with_fresh_registry,resolve_workspace_id, andclaim_dbto returncrate::errors::Result<T>internally. Their own call sites (skill_search,skill_load,handoff,resolve_project,assetx2) already used?and needed zero changes — the newFromimpl is what makes that?work now that the internal error type isAgentflareErrorinstead ofErrorDatadirectly.5 explicit
.map_err(...)sites collapse to plain?across the 3 helpers.Note: this only converts internal helpers, not the giant
#[tool]-dispatch match arms inmcp_server.rs— those still returnResult<_, ErrorData>directly and are out of scope for this PR (would be a much larger, riskier refactor).Testing
cargo test --workspace— 365 passed, 0 failedcargo clippy --workspace --all-targets -- -D warnings -A unsafe_code -A clippy::pedantic— cleancargo fmt --check— cleanSummary by CodeRabbit