Skip to main content

panproto_project/
error.rs

1//! Error types for project assembly operations.
2
3use miette::Diagnostic;
4
5/// Errors from multi-file project assembly.
6#[non_exhaustive]
7#[derive(Debug, thiserror::Error, Diagnostic)]
8pub enum ProjectError {
9    /// A file could not be parsed.
10    #[error("failed to parse {path}: {reason}")]
11    ParseFailed {
12        /// The file path that failed.
13        path: String,
14        /// The reason parsing failed.
15        reason: String,
16    },
17
18    /// Language detection failed for a file.
19    #[error("unknown language for {path}")]
20    UnknownLanguage {
21        /// The file path with unrecognized language.
22        path: String,
23    },
24
25    /// Schema coproduct construction failed.
26    #[error("coproduct construction failed: {reason}")]
27    CoproductFailed {
28        /// Description of the construction failure.
29        reason: String,
30    },
31
32    /// A cross-file import could not be resolved.
33    #[error("unresolved import in {source_file}: {import_target}")]
34    UnresolvedImport {
35        /// The file containing the unresolved import.
36        source_file: String,
37        /// The target that could not be resolved.
38        import_target: String,
39    },
40
41    /// The panproto.toml manifest is malformed.
42    #[error("invalid manifest at {path}: {reason}")]
43    InvalidManifest {
44        /// Path to the malformed manifest.
45        path: String,
46        /// Description of the error.
47        reason: String,
48    },
49
50    /// A glob pattern in the manifest is invalid.
51    #[error("invalid exclude pattern {pattern:?}: {reason}")]
52    InvalidPattern {
53        /// The offending glob pattern.
54        pattern: String,
55        /// Description of the error.
56        reason: String,
57    },
58
59    /// An I/O error occurred reading files.
60    #[error("I/O error: {0}")]
61    Io(#[from] std::io::Error),
62
63    /// A parse error propagated from panproto-parse.
64    #[error(transparent)]
65    Parse(#[from] panproto_parse::ParseError),
66
67    /// A cross-file import edge has a source vertex that does not
68    /// belong to any file in the project.
69    #[error("orphan import edge: {src} -> {tgt}")]
70    OrphanImportEdge {
71        /// The source vertex name, which did not match any file.
72        src: String,
73        /// The target vertex name.
74        tgt: String,
75    },
76}