Files
Lumotia/crates/core/src/error.rs
jake 95c8d490c3 fix(kon): harden core crate — shared System instance, accurate CPU field, serialisable errors
- Share single System::new_all() in probe_system() instead of calling it twice
- Rename CpuInfo::core_count to logical_processors (sys.cpus().len() returns logical, not physical)
- Add fallback arm to probe_os() for unsupported cfg targets
- Add serde::Serialize to KonError for structured frontend error reporting
- Annotate dead code (ProviderRegistry, TranscriptMetadata) with #[allow(dead_code)] + TODO comments
- Update downstream references in recommendation tests and tauri hardware command

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-17 00:19:04 +00:00

61 lines
1.4 KiB
Rust

use std::path::PathBuf;
use serde::Serialize;
use crate::types::ModelId;
/// Structured error type for Kon.
///
/// Implements `Serialize` so errors can be sent to the frontend as
/// structured JSON rather than opaque strings.
#[derive(Debug, thiserror::Error, Serialize)]
pub enum KonError {
#[error("model not found: {0}")]
ModelNotFound(ModelId),
#[error("model not downloaded: {0}")]
ModelNotDownloaded(ModelId),
#[error("engine not loaded: call load_model first")]
EngineNotLoaded,
#[error("transcription failed: {0}")]
TranscriptionFailed(String),
#[error("audio decode failed: {0}")]
AudioDecodeFailed(String),
#[error("audio capture failed: {0}")]
AudioCaptureFailed(String),
#[error("model download failed: {0}")]
DownloadFailed(String),
#[error("file not found: {}", .0.display())]
FileNotFound(PathBuf),
#[error("storage error: {0}")]
StorageError(String),
#[error("io error: {0}")]
Io(
#[from]
#[serde(serialize_with = "serialize_io_error")]
std::io::Error,
),
#[error("{0}")]
Other(String),
}
/// Serialises `std::io::Error` as its display string, since it does
/// not implement `Serialize` natively.
fn serialize_io_error<S: serde::Serializer>(
err: &std::io::Error,
s: S,
) -> std::result::Result<S::Ok, S::Error> {
s.serialize_str(&err.to_string())
}
pub type Result<T> = std::result::Result<T, KonError>;