Repository navigation
Description
Spun off from architectural-audit tracking issue #1228, finding B6. Backend-only; no overlap with the in-flight frontend C-cluster work.
Background (from audit #1228)
B6 — Lossy core→gRPC error mapping 🟠
service_error_to_status()routes most variants through a genericOpsErrorpass-through;fetch_node()wraps everything asStatus::internal(). Clients can't distinguish not-found / version-conflict / validation.
Action: map everyNodeServiceErrorvariant explicitly; ensureVersionConflict → aborted; add parity tests.
Verified current state — the audit OVER-states this; it's mostly done. Scope is now narrow.
After the B3/B4 work (#1244) routed the daemon through node_ops, the error path is:
NodeServiceError → From<NodeServiceError> for OpsError (packages/core/src/ops/mod.rs:42) → ops_error_to_status (daemon/src/services/node_service.rs:1387) → Status.
The important mappings ALREADY exist (verified):
NodeNotFound → OpsError::NotFound → Status::not_found✅VersionConflict → OpsError::VersionConflict → Status::aborted✅ (the audit's specific ask is already satisfied —ops_error_to_status:1388-1393)ValidationFailed / InvalidParent / InvalidRoot / CircularReference / HierarchyViolation → OpsError::ValidationFailed → Status::invalid_argument✅PlaybookValidationFailed → InvalidParams → invalid_argument;CollectionNotFound → NotFound → not_found✅
So service_error_to_status is NOT a generic pass-through anymore — it delegates to a conversion that explicitly distinguishes not-found / version-conflict / validation. The audit's premise is stale.
The REAL remaining gaps (the actual scope of this issue):
From<NodeServiceError>catch-all flattens several variants toInternal(ops/mod.rs, theother => OpsError::Internal(other.to_string())arm). These collapse toStatus::internal, losing client-actionable distinction:DatabaseError,TransactionFailed→ arguablyStatus::internal/unavailableis fine (genuinely internal) — but decide deliberately, don't leave them in a catch-all by accident.InvalidUpdate(String)→ should beinvalid_argument, notinternal(it's a client error).QueryFailed,SerializationError,BulkOperationFailed→ assess: client-actionable or genuinely internal? Map explicitly.
fetch_node(daemon/src/services/node_service.rs:1265) wrapsget_nodefailure asStatus::internal(format!("get_node failed..."))and only returnsnot_foundfor the missing-row case. ANodeServiceErrorfromget_node(e.g. aDatabaseError) is correctly internal, but verify it isn't swallowing a distinguishable variant. Low priority — confirm it's correct rather than rewrite.- No parity tests asserting the variant→Status mapping. This is the main deliverable.
The task
- Make
From<NodeServiceError> for OpsErrorexhaustive (ops/mod.rs:42): replace theother => Internalcatch-all with explicit arms for every remaining variant.InvalidUpdate→ a validation/invalid-params variant. Genuinely-internal variants (DatabaseError,TransactionFailed,SerializationError) map toInternalexplicitly (named arms, no catch-all), so adding a newNodeServiceErrorvariant later forces a compile error rather than silently becomingInternal. - Confirm
ops_error_to_statuscovers everyOpsErrorvariant explicitly (it currently does — NotFound/VersionConflict/ValidationFailed/InvalidParams/Internal). Keep it exhaustive (no_ =>). - Add parity tests (the core deliverable): for each
NodeServiceErrorvariant, assert the resultingtonic::Statuscode. At minimum: NodeNotFound→NotFound, VersionConflict→Aborted, ValidationFailed/InvalidParent/CircularReference/HierarchyViolation/InvalidUpdate→InvalidArgument, DatabaseError/TransactionFailed→Internal. Table-driven test in the daemon crate. - Audit
Status::internalcall sites indaemon/src/services/node_service.rs(e.g. the batch handlers at 711, 947; ExportMarkdown at 670) — confirm each is genuinely internal vs. a client error that should beinvalid_argument/not_found. Fix the mis-categorized ones.
Acceptance criteria
-
From<NodeServiceError> for OpsErrorhas no catch-allother =>arm — every variant is mapped explicitly (compile-error on a new unmapped variant). -
InvalidUpdate(and any other client-error variant) maps toinvalid_argument, notinternal. -
ops_error_to_statusremains exhaustive overOpsError(no_ =>). - Parity tests assert the variant→
Statuscode for everyNodeServiceErrorvariant;VersionConflict → abortedexplicitly covered. -
Status::internalcall sites in the daemon node_service are audited; client-errors re-mapped to the correct code. - No
#[allow(...)], no lint suppression.cargo clippy --workspace --all-targets -- -D warningsclean.
Testing
- New table-driven parity test in the daemon crate passes (
cargo test -p nodespaced). -
cargo test --workspacegreen. - An end-to-end check that a version-conflict RPC returns
Aborted(the frontend conflict-resolution UI from Implement conflict resolution UI for concurrent edits #1231 depends on distinguishing this) and a missing node returnsNotFound.
Coordination
- Backend-only — parallel-safe with the in-flight frontend C1a (C1a: Consolidate the node-CRUD transport layer — fold tauri-commands node half into backendAdapter #1251).
- Builds on B3/B4 (Make daemon NodeService RPCs thin: delegate collection/lifecycle/version logic to core node_ops (B3 + B4) #1244, merged) which established the
node_ops→ops_error_to_statuspath. - The frontend conflict-resolution UI (Implement conflict resolution UI for concurrent edits #1231) and C5 (daemon-adjudicated conflicts, not yet filed) both rely on
VersionConflict → Abortedbeing distinguishable — this issue locks that in with tests.
Standard NodeSpace startup / PR sequence
EnterWorktree({name: "issue-<N>-explicit-grpc-error-mapping"}); bun install; baseline cargo test -p nodespaced; bun run gh:assign/gh:status. Before PR: cargo test --workspace + bun run test:all (no new failures), bun run quality:fix (revert unrelated cargo fmt churn via git status), bun run gh:pr <N>, /pragmatic-code-review, then ExitWorktree + gh pr merge --squash --delete-branch.
Spun off from #1228 (architectural audit), finding B6.
Activity
B6: Exhaustive NodeServiceError→gRPC error mapping + parity tests (#1257
B6: Exhaustive NodeServiceError→gRPC error mapping + parity tests (#1257