Skip to main content

systemprompt_template_provider/traits/
error.rs

1use std::path::PathBuf;
2
3use thiserror::Error;
4
5#[derive(Error, Debug)]
6pub enum TemplateLoaderError {
7    #[error("Template not found: {0}")]
8    NotFound(PathBuf),
9
10    #[error("Directory traversal not allowed: {0}")]
11    DirectoryTraversal(PathBuf),
12
13    #[error("Path not within allowed directories: {0}")]
14    OutsideBasePath(PathBuf),
15
16    #[error("Cannot load single template from directory: {0}")]
17    DirectoryNotSupported(PathBuf),
18
19    #[error("Directory loading not supported by this loader")]
20    DirectoryLoadingUnsupported,
21
22    #[error("Invalid template name encoding: {0}")]
23    InvalidEncoding(PathBuf),
24
25    #[error("No base paths configured")]
26    NoBasePaths,
27
28    #[error("IO error for {path}: {source}")]
29    Io {
30        path: PathBuf,
31        #[source]
32        source: std::io::Error,
33    },
34
35    #[error("Loader only handles embedded templates")]
36    EmbeddedOnly,
37}
38
39impl TemplateLoaderError {
40    pub fn io(path: impl Into<PathBuf>, source: std::io::Error) -> Self {
41        Self::Io {
42            path: path.into(),
43            source,
44        }
45    }
46}
47
48pub type Result<T> = std::result::Result<T, TemplateLoaderError>;