factorio_frontend/
error.rs1#[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)]
2pub enum FrontendError {
3 #[error("failed to parse Rust source: {0}")]
4 Syn(String),
5
6 #[error("unsupported item `{item}` at {location}")]
7 UnsupportedItem { item: String, location: String },
8
9 #[error("unsupported statement at {location}")]
10 UnsupportedStatement { location: String },
11
12 #[error("unsupported expression at {location}")]
13 UnsupportedExpression { location: String },
14
15 #[error("unsupported type `{ty}` at {location}")]
16 UnsupportedType { ty: String, location: String },
17
18 #[error("unsupported operator at {location}")]
19 UnsupportedOperator { location: String },
20
21 #[error("expected an identifier pattern at {location}")]
22 ExpectedIdentifierPattern { location: String },
23
24 #[error("expected an identifier assignment target at {location}")]
25 ExpectedIdentifierAssignmentTarget { location: String },
26
27 #[error("let binding requires an initializer at {location}")]
28 MissingLetInitializer { location: String },
29
30 #[error("unsupported macro `{name}` at {location}")]
31 UnsupportedMacro { name: String, location: String },
32
33 #[error("format string `{template}` expects {expected} argument(s), got {found} at {location}")]
34 FormatArgumentMismatch {
35 template: String,
36 expected: usize,
37 found: usize,
38 location: String,
39 },
40
41 #[error(
42 "module `{module}` must be marked with `factorio_rs::control_mod!`, `#[factorio_rs::control]`, or live under `src/control/`, `src/shared/`, or `src/data/`"
43 )]
44 InvalidModuleStage { module: String },
45
46 #[error("event handlers are only allowed in control-stage modules, found in `{module}`")]
47 EventOutsideControlStage { module: String },
48
49 #[error("invalid event filter at {location}")]
50 InvalidEventFilter { location: String },
51
52 #[error("unsupported event filter method `{method}` at {location}")]
53 UnsupportedEventFilterMethod { method: String, location: String },
54
55 #[error("could not resolve locale key `{path}` to a string constant in this module")]
56 LocaleKeyUnresolved { path: String },
57
58 #[error("invalid locale entry: {message}")]
59 InvalidLocale { message: String },
60}
61
62pub type FrontendResult<T> = Result<T, FrontendError>;
63
64impl From<syn::Error> for FrontendError {
65 fn from(error: syn::Error) -> Self {
66 Self::Syn(error.to_string())
67 }
68}