rust-errors
Maps Rust errors to TypeScript discriminated unions for Tauri apps.
Install
mkdir -p .claude/skills/rust-errors && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/1548" && unzip -o skill.zip -d .claude/skills/rust-errors && rm skill.zipInstalls to .claude/skills/rust-errors
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Rust to TypeScript error handling for Tauri apps. Use when mentioning Rust errors, Tauri command errors, invoke errors, or defining Rust error types for TS consumption.Key capabilities
- →Define internally-tagged Rust enums for serialization
- →Map Rust error variants to TypeScript discriminated unions
- →Validate IPC payloads using arktype
- →Generate type-safe bindings for Tauri commands
- →Implement consistent error logging levels
- →Handle async command errors in frontend code
How it works
The skill uses internally-tagged Rust enums to serialize errors into a consistent JSON format that TypeScript consumes as a discriminated union.
Inputs & outputs
When to use rust-errors
- →Defining Rust error types for Tauri commands
- →Mapping Rust error variants to TypeScript discriminated unions
- →Handling async Tauri command errors in frontend code
About this skill
Rust to TypeScript Error Handling
Reference Repositories
- Tauri: Desktop app framework (source of Rust-to-TypeScript error patterns)
Upstream Grounding
When Rust error serialization, Tauri command error transport, IPC payload shape, generated bindings, or frontend invoke error behavior affects correctness, use source-backed grounding before relying on memory. If DeepWiki MCP is available, ask a narrow question against tauri-apps/tauri; if it is unavailable or the repo is not indexed, use upstream source or official docs directly. Treat DeepWiki as orientation, then verify decisive details against local Rust code, generated bindings, installed crates, TypeScript types, source, or official docs before changing code.
Skip DeepWiki for local error naming conventions already documented below.
Use this skill when a Rust command returns failures that TypeScript consumes. The tauri skill owns command registration, generated bindings, capabilities, and native verification. The error-handling skill owns Result composition and presentation after the IPC boundary. The logging skill owns diagnostic levels and sinks.
Let Rust define the failure
A command returns Result<T, E> when failure is part of its contract. Define an error variant when a caller can respond differently or needs structured data; keep operational detail in message. The recorder's PermissionDenied, NoInputDevice, and Busy variants are examples. Do not divide one frontend action into several variants merely to label different internal causes. An internal Rust error that never crosses IPC does not need Serde or Specta derives.
For a typed command error that crosses IPC, derive serde::Serialize and specta::Type from the same enum. Derive Deserialize only when the value also crosses back into Rust. An internally tagged enum such as #[serde(tag = "name")] gives TypeScript a discriminant for exhaustive handling:
#[derive(Debug, thiserror::Error, serde::Serialize, specta::Type)]
#[serde(tag = "name")]
pub enum RecordingError {
#[error("{message}")]
PermissionDenied { message: String },
#[error("{message}")]
Failed { message: String },
}
Keep the error non-nullable. Specta's DataError mode uses null to mean success and rejects nullable command error types during binding export. A success value may itself be nullable. Do not add a parallel ArkType schema or handwritten TypeScript union for a generated Rust error. Browser code can use explicit import type from the generated bindings without loading the Tauri runtime.
Generate the application result shape
The native plugins' Specta builders set ErrorHandlingMode::DataError. The generated command returns { data: T, error: null } | { data: null, error: E }, which is compatible with Wellcrafted's Result<T, E>. Callers branch on error !== null, forward an error they do not own, and let the interaction owner present the final outcome. Infallible commands retain their plain generated return type.
This mode changes the generated TypeScript API. Tauri still sends a Rust Err through its rejected IPC channel. The generated helper catches a non-Error rejection and casts it to E; it rethrows a JavaScript Error. Generation therefore establishes the compile-time contract, not runtime validation of every rejection. Do not present an unexpected thrown failure as a known Rust domain variant. Adapt a transport rejection only where an operation deliberately owns that failure meaning.
A consumer's command boundary combines generated commands with any handwritten raw-byte command. It must not reshape every generated command: DataError already produces the application Result. A raw tauri::ipc::Response command remains handwritten because Specta cannot export that response type.
Keep the generated contract in sync
Regenerate the bindings owned by a changed plugin and review their diff. Generated types should change when the wire contract changes. Check the relevant TypeScript type assertions and consumers. Keep exhaustive switch (error.name) handling where a caller translates every variant.
Rust's tracing and TypeScript's wellcrafted/logger both choose severity at the emission site, not on the error variant. See logging for the diagnostic contract and the mapping below. A returned Err is not itself a log event; log where an owner can add context or where the failure would otherwise be invisible.
tracing ↔ wellcrafted/logger
defineErrors mirrors thiserror; the workspace logger mirrors tracing. Together they give TypeScript the same split Rust has: errors are data, level is chosen at the emit site.
Level mapping (5 levels, no fatal)
tracing macro | Workspace Logger method | Use when |
|---|---|---|
tracing::trace!(...) | log.trace(message, data?) | Per-token / per-message noise for deep debugging |
tracing::debug!(...) | log.debug(message, data?) | Internal state transitions (handshakes, cache fills) |
tracing::info!(...) | log.info(message, data?) | Lifecycle events (connected, loaded, flushed) |
tracing::warn!(?err) | log.warn(err) | Recoverable failure: retry path, fallback taken |
tracing::error!(?err) | log.error(err) | Unrecoverable at this layer: call it loudly |
tracing has no fatal; neither do we. Process termination is the app's decision (process.exit), not the library's.
Level on the variant? No.
// Rust: level is on the CALL, not the enum variant
tracing::warn!(?err, "cache miss"); // same err, different sites
tracing::error!(?err, "giving up");
// TS: same rule
log.warn(CacheError.Miss({ key })); // recoverable
log.error(CacheError.Miss({ key })); // terminal
No Rust logging crate attaches level to the error type (thiserror, anyhow, slog, log). miette is the exception, but it is a compiler-diagnostics library, not a general logger. We follow tracing: level is context, not identity.
The ?err idiom ↔ tapErr
tracing's ?err interpolates a structured error field into the log event. In TS, the Result-flow equivalent is tapErr (from wellcrafted/result):
let result = do_thing().inspect_err(|err| tracing::warn!(?err, "do_thing failed"));
import { tapErr } from 'wellcrafted/result';
const result = await tryAsync({
try: () => doThing(),
catch: (cause) => DoThingError.Failed({ cause }),
}).then(tapErr(log.warn));
Both: pass-through on success, log the structured error on failure.
In practice this shape is rare in epicenter. Most call sites need the Ok data locally and so branch on result.error and log inside the branch. Reach for tapErr only when the Result flows out of the function in a .then(...) chain.
When not to use it
- →When using external or adjacent tagging for serialization
- →When implementing manual serialization logic
Prerequisites
Limitations
- →Requires consistent naming conventions for enum variants
- →Avoids nested structures created by content tagging
How it compares
This method ensures type safety across the IPC boundary by generating bindings and using runtime validation rather than relying on manual string parsing.
Compared to similar skills
rust-errors side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| rust-errors (this skill) | 5 | 4mo | No flags | Advanced |
| hula-skill | 3 | 10mo | Review | Intermediate |
| tauri-syntax-permissions | 0 | 8mo | No flags | Intermediate |
| perf | 0 | 5mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by EpicenterHQ
View all by EpicenterHQ →You might also like
hula-skill
HuLaSpark
HuLa project skill for frontend (Vue 3 + Vite + UnoCSS + Naive UI/Vant), backend (Tauri v2 + Rust + SeaORM/SQLite), full-stack flows, and build/release work. Use when the user mentions hula or HuLa or requests changes in this repository; after triggering, ask which scope (frontend/backend/fullstack/build-release) to enable.
tauri-syntax-permissions
OpenAEC-Foundation
>
perf
microsoft
Speed and memory performance rules for Rust crates, webui-framework, and webui-router.
add-new-setting-field
tsukumijima
【設定追加時は必ず参照】KonomiTV に新しい設定 (v-switch/v-select など) を追加する際の必須手順。SettingsStore.ts / Settings.ts / config.py / Settings/*.vue への追加が必要
shadmin-dev
ahaodev
Apply Shadmin feature-development standards (backend Go/Gin/Ent + frontend React/TS). Use when adding/modifying features, CRUD modules, API routes/controllers/usecases/repositories, Ent schemas, frontend pages/routes, React components, TanStack hooks, or any full-stack work in this project. Trigger
scaffold-feature
niklasbrandt
Scaffold a complete full-stack feature: FastAPI endpoint, dashboard Web Component, i18n keys, test stubs, and documentation checks.