microcad_lang/resolve/
resolve_error.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Resolve error
5
6use thiserror::Error;
7
8use crate::{diag::*, parse::*, syntax::*};
9
10/// Resolve error.
11#[derive(Debug, Error)]
12pub enum ResolveError {
13    /// Parse Error.
14    #[error("Parse Error: {0}")]
15    ParseError(#[from] ParseError),
16
17    /// Can't find a project file by hash.
18    #[error("Could not find a file with hash {0}")]
19    UnknownHash(u64),
20
21    /// Hash is zero
22    #[error("Hash is zero")]
23    NulHash,
24
25    /// Name of external symbol is unknown.
26    #[error("External symbol `{0}` not found")]
27    ExternalSymbolNotFound(QualifiedName),
28
29    /// Path of external file is unknown.
30    #[error("External path `{0}` not found")]
31    ExternalPathNotFound(std::path::PathBuf),
32
33    /// Can't find a project file by it's path.
34    #[error("Could not find a file with path {0}")]
35    FileNotFound(std::path::PathBuf),
36
37    /// Symbol not found.
38    #[error("Symbol {0} not found while resolving.")]
39    SymbolNotFound(QualifiedName),
40
41    /// Symbol not found (retry to load from external).
42    #[error("Symbol {0} must be loaded from {1}")]
43    SymbolMustBeLoaded(QualifiedName, std::path::PathBuf),
44
45    /// Symbol is not a value
46    #[error("Symbol {0} is not a value")]
47    NotAValue(QualifiedName),
48
49    /// Declaration of property not allowed here
50    #[error("Declaration of {0} not allowed within {1}")]
51    DeclNotAllowed(Identifier, QualifiedName),
52
53    /// Sternal module file not found
54    #[error("Ambiguous external module files found {0:?}")]
55    AmbiguousExternals(Vec<std::path::PathBuf>),
56
57    /// Ambiguous symbol was found
58    #[error("Symbol {0} already defined")]
59    SymbolAlreadyDefined(QualifiedName),
60
61    /// Ambiguous symbol was found
62    #[error("Ambiguous symbol found: {0}")]
63    AmbiguousSymbol(QualifiedName, QualifiedNames),
64
65    /// ScanDir Error
66    #[error("{0}")]
67    ScanDirError(#[from] scan_dir::Error),
68
69    /// Invalid path.
70    #[error("Invalid path: {0:?}")]
71    InvalidPath(std::path::PathBuf),
72
73    /// Diagnostic error
74    #[error("Diagnostic error: {0}")]
75    DiagError(#[from] DiagError),
76
77    /// Statement is not supported in this context.
78    #[error("{0} is not available within {1}")]
79    StatementNotSupported(String, String),
80
81    /// Resolve check failed
82    #[error("Resolve failed")]
83    ResolveCheckFailed,
84
85    /// Symbol is private
86    #[error("Symbol {0} is private")]
87    SymbolIsPrivate(QualifiedName),
88
89    /// ScanDir Error
90    #[error("{0}")]
91    IoError(#[from] std::io::Error),
92
93    /// Invalid path.
94    #[error(
95        "Source of module '{0}' could not be found in {1:?} (expecting a file '{0}.µcad' or '{0}/mod.µcad')"
96    )]
97    SourceFileNotFound(Identifier, std::path::PathBuf),
98
99    /// Wrong lookup target
100    #[error("Wrong lookup target")]
101    WrongTarget,
102
103    /// Statement not allowed within workbenches
104    #[error("Statement not allowed within workbenches")]
105    IllegalWorkbenchStatement,
106
107    /// Code Between initializers
108    #[error("Code between initializers is not allowed")]
109    CodeBetweenInitializers,
110
111    /// Statement not allowed prior initializers
112    #[error("Statement not allowed prior initializers")]
113    StatementNotAllowedPriorInitializers,
114}
115
116/// Result type of any resolve.
117pub type ResolveResult<T> = std::result::Result<T, ResolveError>;