1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Copyright (C) 2019-2023 Aleo Systems Inc.
// This file is part of the Leo library.

// The Leo library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// The Leo library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use crate::create_messages;
use std::{
    error::Error as ErrorArg,
    fmt::{Debug, Display},
};

create_messages!(
    /// InputError enum that represents all the errors for the `utils` crate.
    UtilError,
    code_mask: 10000i32,
    code_prefix: "UTL",

    @formatted
    util_file_io_error {
        args: (msg: impl Display, err: impl ErrorArg),
        msg: format!("File system io error: {msg}. Error: {err}"),
        help: None,
    }

    @formatted
    toml_serizalization_error {
        args: (error: impl ErrorArg),
        msg: format!("TOML serialization error: {error}"),
        help: None,
    }

    @formatted
    json_serialization_error {
        args: (error: impl ErrorArg),
        msg: format!("JSON serialization error: {error}"),
        help: None,
    }

    @formatted
    snarkvm_parsing_error {
        args: (),
        msg: format!("SnarkVM failure to parse `.aleo` program"),
        help: None,
    }

    @formatted
    circular_dependency_error {
        args: (),
        msg: format!("Circular dependency detected"),
        help: None,
    }

    @formatted
    network_error {
        args: (url: impl Display, status: impl Display),
        msg: format!("Failed network request to {url}. Status: {status}"),
        help: None,
    }

    @formatted
    duplicate_dependency_name_error {
        args: (dependency: impl Display),
        msg: format!("Duplicate dependency found: {dependency}"),
        help: None,
    }

    @backtraced
    reqwest_error {
        args: (error: impl Display),
        msg: format!("{}", error),
        help: None,
    }

    @backtraced
    failed_to_open_file {
        args: (error: impl Display),
        msg: format!("Failed to open file {error}"),
        help: None,
    }

    @backtraced
    failed_to_read_file {
        args: (error: impl Display),
        msg: format!("Failed to read file {error}"),
        help: None,
    }

    @backtraced
    failed_to_deserialize_file {
        args: (error: impl Display),
        msg: format!("Failed to deserialize file {error}"),
        help: None,
    }

    @formatted
    failed_to_retrieve_dependencies {
        args: (error: impl Display),
        msg: format!("Failed to retrieve dependencies. {error}"),
        help: None,
    }

    @formatted
    missing_network_error {
        args: (dependency: impl Display),
        msg: format!("Dependency {dependency} is missing a network specification"),
        help: Some("Add a network specification to the dependency in the `program.json` file. Example: `network: \"testnet3\"`".to_string()),
    }

    @formatted
    missing_path_error {
        args: (dependency: impl Display),
        msg: format!("Local dependency {dependency} is missing a path specification"),
        help: Some("Add a path in the `program.json` file to the dependency project root . Example: `path: \"../../board\"`".to_string()),
    }

    @formatted
    program_name_mismatch_error {
        args: (program_json_name: impl Display, dep_name: impl Display, path: impl Display),
        msg: format!("Name mismatch: Local program at path `{path}` is named `{program_json_name}` in `program.json` but `{dep_name}` in the program that imports it"),
        help: Some("Change one of the names to match the other".to_string()),
    }

    @formatted
    snarkvm_error_building_program_id {
        args: (),
        msg: "Snarkvm error building program id".to_string(),
        help: None,
    }

    @formatted
    failed_to_retrieve_from_endpoint {
        args: (endpoint: impl Display, error: impl ErrorArg),
        msg: format!("Failed to retrieve from endpoint `{endpoint}`. Error: {error}"),
        help: None,
    }

    @formatted
    build_file_does_not_exist {
        args: (path: impl Display),
        msg: format!("Compiled file at `{path}` does not exist, cannot compile parent."),
        help: Some("If you were using the `--non-recursive` flag, remove it and try again.".to_string()),
    }
);