leo_errors/errors/static_analyzer/
static_analyzer_error.rs

1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::create_messages;
18use std::fmt::{Debug, Display};
19
20// TODO: Consolidate errors.
21
22create_messages!(
23    /// StaticAnalyzer enum that represents all the errors for static analysis.
24    StaticAnalyzerError,
25    code_mask: 4000i32,
26    code_prefix: "SAZ",
27
28    @formatted
29    no_path_awaits_all_futures_exactly_once {
30        args: (num_total_paths: impl Display),
31        msg: format!("Futures must be awaited exactly once. Out of `{num_total_paths}`, there does not exist a single path in which all futures are awaited exactly once."),
32        help: Some("Ex: for `f: Future` call `f.await()` to await a future. Remove duplicate future await redundancies, and add future awaits for un-awaited futures.".to_string()),
33    }
34
35    @formatted
36    future_awaits_missing {
37        args: (unawaited: impl Display),
38        msg: format!("The following futures were never awaited: {unawaited}"),
39        help: Some("Ex: for `f: Future` call `f.await()` to await a future.".to_string()),
40    }
41
42    @formatted
43    invalid_await_call {
44        args: (),
45        msg: "Not a valid await call.".to_string(),
46        help: Some("Ex: for `f: Future` call `f.await()` or `Future::await(f)` to await a future.".to_string()),
47    }
48
49    @formatted
50    expected_future {
51        args: (type_: impl Display),
52        msg: format!("Expected a future, but found `{type_}`"),
53        help: Some("Only futures can be awaited.".to_string()),
54    }
55
56    @formatted
57    async_transition_call_with_future_argument {
58        args: (function_name: impl Display),
59        msg: format!("The call to {function_name} will result in failed executions on-chain."),
60        help: Some("There is a subtle error that occurs if an async transition call follows a non-async transition call, and the async call returns a `Future` that itself takes a `Future` as an input. See See `https://github.com/AleoNet/snarkVM/issues/2570` for more context.".to_string()),
61    }
62
63    @formatted
64    misplaced_future {
65        args: (),
66        msg: "A future may not be used in this way".to_string(),
67        help: Some("Futures should be created, assigned to a variable, and consumed without being moved or reassigned.".to_string()),
68    }
69
70    @formatted
71    compile_time_unary_op {
72        args: (value: impl Display, op: impl Display, err: impl Display),
73        msg: format!("Unary operation `{value}.{op}()` failed at compile time: {err}."),
74        help: None,
75    }
76
77    @formatted
78    compile_time_binary_op {
79        args: (value_lhs: impl Display, value_rhs: impl Display, op: impl Display, err: impl Display),
80        msg: format!("Binary operation `{value_lhs} {op} {value_rhs}` failed at compile time: {err}."),
81        help: None,
82    }
83
84    @formatted
85    compile_time_cast {
86        args: (value: impl Display, type_: impl Display),
87        msg: format!("Compile time cast failure: `{value} as {type_}`."),
88        help: None,
89    }
90
91    @formatted
92    compile_core_function {
93        args: (err: impl Display),
94        msg: format!("Error during compile time evaluation of this core function: {err}."),
95        help: None,
96    }
97
98    @formatted
99    array_bounds {
100        args: (index: impl Display, len: impl Display),
101        msg: format!("Array index {index} out of bounds (array length is {len})."),
102        help: None,
103    }
104);