scratch_test_interpreter/
error.rs1use crate::State;
2
3pub type RResult<T, S> = Result<T, RunError<<S as State>::Error>>;
4
5#[derive(Debug, PartialEq, PartialOrd, Clone, thiserror::Error)]
6#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
7#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
10pub enum InvalidFileError {
11 #[error("statement calls procedure that doesn't exist in file")]
12 CantFindProcedureForCall,
13 #[error("found expression or comparison block when statement was expected")]
14 #[cfg_attr(feature = "utoipa", schema(value_type = String))]
15 FoundExpressionWhenStmtExpected(smodel::Id),
16 #[error("procedure call doesn't provide all arguments needed")]
17 MissingArgForProcedureParameter,
18 #[error("procedure call has extra arguments not expected by definition")]
19 ExtraArgWithoutProcedureParameter,
20 #[error("block reference doesn't point to an existing block")]
21 NoBlockFoundForReference(smodel::error::BlockReferenceInvalid),
22 #[error("next block reference points to no block in file")]
23 #[cfg_attr(feature = "utoipa", schema(value_type = String))]
24 ReachedUnknownBlock(smodel::Id),
25}
26
27#[derive(Debug, PartialEq, PartialOrd, Clone, thiserror::Error)]
28#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
29#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
30#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
32pub enum UserError {
33 #[error("without a body no data can change, so a condition-based loop will never stop")]
34 ConditionLoopWithoutBodyNeverStops,
35 #[error("a single-threadded wait-until block called with false will never continue")]
36 WaitUntilFalseNeverTerminatesInSingleThreadded,
37 #[error("an infinite loop without a body can never halt")]
38 InfiniteLoopWithoutBodyNeverStops,
39}
40#[derive(Debug, PartialEq, PartialOrd, Clone, thiserror::Error)]
41#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
42#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
43#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
45pub enum UnsupportedError {
46 #[error("blocks related to cloning are not supported")]
47 #[cfg_attr(feature = "utoipa", schema(value_type = String))]
48 CloneBlocksNotSupported(smodel::Id),
49 #[error("sending of events is not unsupported")]
50 EventSendingNotSupported,
51 #[error("uses of unsupported sensing block")]
52 UnsupportedSensingBlock,
53 #[error("uses of unsupported looks block")]
54 UnsupportedLooksBlock,
55 #[error("uses of unsupported motion block")]
56 UnsupportedMotionBlock,
57}
58
59#[derive(Debug, PartialEq, PartialOrd, Clone, thiserror::Error)]
60#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
61#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
62#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
63#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
64pub enum InternalError {
65 #[error("saved instruction asks to remove stack frame, but no frames are stored")]
66 PopOnEmptyArgumentFramesStack,
67 #[error("unexpected kind of stack frame found for this context")]
69 FatalWrongStackFrameForContext,
70 #[error("program stack doesn't contain another instruction")]
72 PopOnEmptyProgramStack,
73}
74
75#[derive(Debug, PartialEq, PartialOrd, Clone, thiserror::Error)]
76#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
77#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
78#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
79#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
80pub enum LimitError {
81 #[error("a string operation produced a text that is longer than allowed")]
82 StringExceededLengthLimit(usize),
83 #[error("executed more statements than allowed")]
84 ExceededAllowedStmtCount,
85 #[error("stack size exceeds limit")]
86 MaxStackSizeExceeded,
87}
88
89#[derive(Debug, PartialEq, PartialOrd, Clone, thiserror::Error)]
90#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
91#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
92#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
93#[cfg_attr(feature = "serde", serde(rename_all = "kebab-case"))]
94pub enum RunError<SErr> {
95 #[error("state: {0}")]
96 State(SErr),
97 #[error("terminated by stop block")]
98 TerminatedByControlStop,
99 #[error("limit: {0}")]
100 Limit(#[from] LimitError),
101 #[error("internal: {0}")]
102 Internal(#[from] InternalError),
103 #[error("damaged-file: {0}")]
104 File(#[from] InvalidFileError),
105 #[error("user: {0}")]
106 User(#[from] UserError),
107 #[error("unsupported: {0}")]
108 Unsupported(#[from] UnsupportedError),
109}