Skip to main content

squigit_storage/
error.rs

1// Copyright 2026 a7mddra
2// SPDX-License-Identifier: Apache-2.0
3
4//! Error types for persisted storage.
5
6use thiserror::Error;
7
8/// Storage error types.
9#[derive(Error, Debug)]
10pub enum StorageError {
11    /// No data directory found.
12    #[error("Could not find data directory")]
13    NoDataDir,
14
15    /// Failed to locate the user's config directory.
16    #[error("Could not locate config directory")]
17    NoConfigDir,
18
19    /// IO error.
20    #[error("IO error: {0}")]
21    Io(#[from] std::io::Error),
22
23    /// JSON serialization error.
24    #[error("JSON error: {0}")]
25    Json(#[from] serde_json::Error),
26
27    /// A locally parsed text attachment must contain valid UTF-8.
28    #[error("Text attachment is not valid UTF-8: {0}")]
29    InvalidUtf8(#[from] std::str::Utf8Error),
30
31    /// Empty image provided.
32    #[error("Empty image data")]
33    EmptyImage,
34
35    /// Invalid hash format.
36    #[error("Invalid hash format")]
37    InvalidHash,
38
39    /// A persisted Office-to-PDF conversion receipt is invalid.
40    #[error("Invalid document conversion: {0}")]
41    InvalidDocumentConversion(String),
42
43    /// Image not found.
44    #[error("Image not found: {0}")]
45    ImageNotFound(String),
46
47    /// Thread not found.
48    #[error("Thread not found: {0}")]
49    ThreadNotFound(String),
50
51    /// Workspace not found.
52    #[error("Workspace not found: {0}")]
53    WorkspaceNotFound(String),
54
55    /// Workspace names must contain at least one non-whitespace character.
56    #[error("Invalid workspace name")]
57    InvalidWorkspaceName,
58
59    /// Workspace path is invalid or too broad to use as an AI sandbox.
60    #[error("Invalid workspace path: {0}")]
61    InvalidWorkspacePath(String),
62
63    /// Persisted message IDs must use the `msg-<UUID>` contract.
64    #[error("Invalid thread message: {0}")]
65    InvalidThreadMessage(String),
66
67    /// Profile with the given ID was not found.
68    #[error("Profile not found: {0}")]
69    ProfileNotFound(String),
70
71    /// Cannot delete the last remaining profile.
72    #[error("Cannot delete the last profile")]
73    CannotDeleteLastProfile,
74
75    /// Profile ID is invalid.
76    #[error("Invalid profile ID: {0}")]
77    InvalidProfileId(String),
78
79    /// Stored auth state is unsupported or invalid.
80    #[error("{0}")]
81    AuthState(String),
82
83    /// Encrypted key-store structure, locking, or target safety failure.
84    #[error("{0}")]
85    KeyStore(String),
86
87    /// Unsupported OCR annotations key.
88    #[error("Unsupported OCR model id: {0}")]
89    InvalidOcrModel(String),
90}
91
92/// Result type alias for storage operations.
93pub type Result<T> = std::result::Result<T, StorageError>;