agentmux_srv\backend\storage/
error.rs

1// Copyright 2025-2026, AgentMux Corp.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error types for the storage layer.
5
6
7#[derive(Debug, thiserror::Error)]
8pub enum StoreError {
9    #[error("not found")]
10    NotFound,
11
12    #[error("already exists")]
13    #[allow(dead_code)]
14    AlreadyExists,
15
16    #[error("empty OID")]
17    EmptyOID,
18
19    #[error("version mismatch: expected {expected}, got {actual}")]
20    #[allow(dead_code)]
21    VersionMismatch { expected: i64, actual: i64 },
22
23    #[error("sqlite error: {0}")]
24    Sqlite(#[from] rusqlite::Error),
25
26    #[error("json error: {0}")]
27    Json(#[from] serde_json::Error),
28
29    /// The on-disk database was written by a NEWER AgentMux binary
30    /// than the one running now. Refusing to open it is the
31    /// channels-design safety lock from
32    /// `SPEC_DATA_CHANNELS_2026_05_24.md` §3.3 — a forward-compat
33    /// guard that prevents a downgrade from silently corrupting
34    /// state the newer schema added. The user must upgrade the
35    /// binary or switch channels (e.g.
36    /// `AGENTMUX_CHANNEL=experiment` for an empty side dir) to
37    /// recover.
38    #[error(
39        "{db}: this AgentMux is too old to open this data — schema v{found} \
40         on disk, this binary speaks v{expected}. Upgrade AgentMux, or set \
41         AGENTMUX_CHANNEL=<other> to use a fresh channel."
42    )]
43    SchemaTooNew {
44        db: String,
45        found: i64,
46        expected: i64,
47    },
48
49    #[error("{0}")]
50    Other(String),
51}