Skip to main content

agentmux_srv/backend/storage/
error.rs

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