Skip to content

refactor(desktop): kill hand-written types.ts mirror + adopt typed CoreError at IPC boundary #68

Open

Description

@utof

Per docs/research/architecture_audit.md §3.6, §3.11, §4.3 (combined because both are IPC-type-boundary concerns).

Problem A: hand-written types.ts mirror has drifted

apps/desktop/src/types.ts is a hand-written TS mirror of specta bindings. The "SHA-256" vs BLAKE3 drift documented in §3.6 is proof the pattern produces latent bugs. Today's flow is a three-layer drift pipeline:

core type → specta wire-type → hand-written TS mirror

The #[cfg(debug_assertions)] gate on specta bindings export is Spacedrive's v1 anti-pattern; bindings.ts is ungit'd and unreviewable.

Fix A

  1. Delete apps/desktop/src/types.ts entirely. Re-export from bindings.ts.
  2. Always export bindings (drop cfg(debug_assertions) gate). Commit bindings.ts to git. Add CI step that fails if bindings.ts has a diff after a rebuild.
  3. Unify the 8 wire types with the 7 domain types via feature-gated specta derives on core domain types: #[cfg_attr(feature = "specta", derive(specta::Type))]. This is the challenge to the "core has zero framework deps" hard exclusion — see §4.3; every Tauri 2 codebase surveyed (Cap, Hyprnote, AppFlowy, TauRPC) does this.
  4. Eliminates ~300 LOC of wire-type duplication + hand-written From impls.

Problem B: Result<T, String> flattens typed errors at IPC

Tauri commands return Result<T, String> — loses the typed CoreError taxonomy at the frontend boundary. neverthrow gets a string, can't pattern-match, has to parse.

Fix B

Typed CoreError as a serde-tagged discriminated union via specta:

#[derive(Debug, thiserror::Error, Serialize, specta::Type)]
#[serde(tag = "kind", content = "data")]
pub enum CoreError {
    #[error("not found: {0}")]
    NotFound(String),
    #[error("invalid input: {field}: {reason}")]
    InvalidInput { field: String, reason: String },
    // ...
}

Tauri commands return Result<T, CoreError> directly — specta generates the TS discriminated union — the invoke call returns a typed union. Wrap once:

// ipc/invoke.ts
export const invokeResult = <T>(
  cmd: (...args: any[]) => Promise<T>,
  ...args: any[]
): ResultAsync<T, CoreError> =>
  ResultAsync.fromPromise(cmd(...args), (e) => e as CoreError);

Dual-derive note

For HTTP (Phase 6), DTOs get #[derive(Serialize, Deserialize, specta::Type, ToSchema)] — accept the two-macro tax. specta-rs's JSON-schema export is experimental.

Rejected alternatives

  • TauRPC — pins to specific specta RC; router abstraction duplicates AppContainer (see issue for crates/app extract).
  • rspc — more ambitious; overkill for 13 Tauri commands.
  • Switch specta → ts-rs — the keep-or-switch question is distraction; the correctness fix is architectural (re-export, don't mirror).

Source

docs/research/architecture_audit.md §3.6, §3.11, §4.3.

Execution hint

Can be split:

  • A) Delete types.ts + always-export bindings + CI diff check (mechanical; wave-3 candidate).
  • B) Typed CoreError union at IPC (brainstorm + plan; blocks on crates/app extract for cleanest landing).

Activity

  1. added
    type/chore
    on Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/chore

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions