Skip to main content

writerslogic_warm/core/
error.rs

1// Copyright 2024-2026 WritersLogic Contributors
2// SPDX-License-Identifier: Apache-2.0
3
4use serde::{Deserialize, Serialize};
5use thiserror::Error;
6
7#[derive(Debug, Error)]
8#[error("data mutation is durable, but {effect} failed; reopen or reconcile before retrying")]
9pub struct CommittedMutationError {
10    pub effect: &'static str,
11    #[source]
12    pub source: anyhow::Error,
13}
14
15pub(crate) fn after_commit<T>(
16    effect: &'static str,
17    result: anyhow::Result<T>,
18) -> anyhow::Result<T> {
19    result.map_err(|source| CommittedMutationError { effect, source }.into())
20}
21
22#[derive(Debug, Error, Clone, Serialize, Deserialize)]
23#[cfg_attr(
24    feature = "node-api",
25    derive(ts_rs::TS),
26    ts(export, export_to = "bindings/")
27)]
28#[cfg_attr(feature = "server", derive(schemars::JsonSchema))]
29#[serde(tag = "type", content = "message")]
30pub enum WarmError {
31    #[error("Invalid parameter: {details}")]
32    InvalidParam { details: String },
33
34    #[error("Storage failure: {context}")]
35    StorageFailure { context: String },
36
37    #[error("Encoding failed: {context}")]
38    EncodingFailure { context: String },
39
40    #[error("Query failed: {context}")]
41    QueryFailure { context: String },
42
43    #[error("Index not trained: {index_type}")]
44    IndexNotTrained { index_type: String },
45
46    #[error("Capacity exceeded: {limit}")]
47    CapacityExceeded { limit: String },
48
49    #[error("Internal error (code {code}): {context}")]
50    Internal { code: i32, context: String },
51}