1use uuid::Uuid;
2
3#[derive(Debug, thiserror::Error)]
5pub enum MnemeError {
6 #[error("Memoria no encontrada: {0}")]
8 NotFound(Uuid),
9
10 #[error("Se requiere un proyecto para esta operación")]
12 ProjectRequired,
13
14 #[error("La consulta de búsqueda no puede estar vacía")]
16 EmptyQuery,
17
18 #[error("Tipo de memoria inválido: {0}")]
20 InvalidMemoryType(String),
21
22 #[error("Importancia inválida: {0}")]
24 InvalidImportance(String),
25
26 #[error("Alcance inválido: {0}")]
28 InvalidScope(String),
29
30 #[error("Tipo de relación inválido: {0}")]
32 InvalidRelationType(String),
33
34 #[error("La relación entre {0} y {1} ya existe")]
36 RelationAlreadyExists(Uuid, Uuid),
37
38 #[error("No se permite relacionar una memoria consigo misma: {0}")]
40 SelfRelation(Uuid),
41
42 #[error("Duplicado detectado: {0}")]
44 DuplicateDetected(String),
45
46 #[error("Error de base de datos: {0}")]
48 Database(#[from] rusqlite::Error),
49
50 #[error("Error de migración: {0}")]
52 Migration(String),
53
54 #[error("Error de E/S: {0}")]
56 Io(#[from] std::io::Error),
57
58 #[error("Error de serialización: {0}")]
60 Serialization(#[from] serde_json::Error),
61
62 #[error("Error de configuración: {0}")]
64 Config(String),
65
66 #[error("Error HTTP: {0}")]
68 Http(String),
69
70 #[error("Error MCP: {0}")]
72 Mcp(String),
73
74 #[error("error de embeddings: {0}")]
76 Embeddings(String),
77
78 #[error("modelo de embeddings no disponible")]
80 EmbeddingsDisabled,
81
82 #[error("peer no encontrado: {0}")]
84 PeerNotFound(uuid::Uuid),
85
86 #[error("error de sync con peer '{peer}': {message}")]
88 SyncFailed { peer: String, message: String },
89
90 #[error("sync deshabilitado")]
92 SyncDisabled,
93
94 #[error("transporte no soportado: {0}")]
96 UnsupportedTransport(String),
97
98 #[error("archivo de sync invalido: {0}")]
100 InvalidSyncFile(String),
101
102 #[error("error de compresion: {0}")]
104 Compression(String),
105
106 #[error("encriptación no disponible — configurar al menos una clave con 'mneme keys add'")]
108 NoRecipientsConfigured,
109
110 #[error("no se pudo desencriptar — verificar que la clave privada es correcta")]
112 DecryptionFailed,
113
114 #[error("identidad de desencriptación no disponible — ejecutar 'mneme keys load'")]
116 IdentityNotLoaded,
117
118 #[error("la memoria {0} ya está encriptada")]
120 AlreadyEncrypted(Uuid),
121
122 #[error("la memoria {0} no está encriptada")]
124 NotEncrypted(Uuid),
125
126 #[error("clave no encontrada: {0}")]
128 KeyNotFound(String),
129
130 #[error("error de plugin: {0}")]
132 Plugin(String),
133}
134
135impl From<rusqlite_migration::Error> for MnemeError {
136 fn from(err: rusqlite_migration::Error) -> Self {
137 MnemeError::Migration(err.to_string())
138 }
139}
140
141impl From<automerge::AutomergeError> for MnemeError {
142 fn from(err: automerge::AutomergeError) -> Self {
143 MnemeError::Config(format!("automerge error: {}", err))
144 }
145}
146
147pub type Result<T> = std::result::Result<T, MnemeError>;
149
150impl MnemeError {
151 pub fn memory_id(&self) -> Option<Uuid> {
153 match self {
154 MnemeError::NotFound(id)
155 | MnemeError::SelfRelation(id)
156 | MnemeError::AlreadyEncrypted(id)
157 | MnemeError::NotEncrypted(id) => Some(*id),
158 _ => None,
159 }
160 }
161}