Skip to main content

caliban_memory/
error.rs

1//! Error type for memory-tier loading.
2
3use std::path::PathBuf;
4
5/// Errors that can occur while loading or splicing memory tiers.
6#[derive(thiserror::Error, Debug)]
7pub enum MemoryError {
8    /// IO failure reading a tier file.
9    #[error("io error reading {path}: {source}")]
10    Io {
11        /// The path that failed to read.
12        path: PathBuf,
13        /// Underlying error.
14        #[source]
15        source: std::io::Error,
16    },
17    /// Failed to seed or write to the auto-memory directory.
18    #[error("failed to initialise auto-memory dir {path}: {source}")]
19    AutoMemorySeed {
20        /// The directory we tried to create or seed.
21        path: PathBuf,
22        /// Underlying error.
23        #[source]
24        source: std::io::Error,
25    },
26    /// A topic file's frontmatter was missing, malformed, or contained an
27    /// invalid `metadata.type` value.
28    #[error("invalid topic frontmatter at {path}: {reason}")]
29    InvalidTopic {
30        /// The topic file path.
31        path: PathBuf,
32        /// Human-readable reason.
33        reason: String,
34    },
35    /// A topic slug failed validation (path traversal, illegal characters, or empty).
36    #[error("invalid topic slug '{slug}': {reason}")]
37    InvalidSlug {
38        /// The offending slug.
39        slug: String,
40        /// Reason it was rejected.
41        reason: String,
42    },
43}
44
45/// Convenience `Result` alias for this crate.
46pub type Result<T> = std::result::Result<T, MemoryError>;