make errors consistent

This commit is contained in:
evan-schott 2023-11-30 15:45:26 -08:00
parent 6ab9415a02
commit 25af3dd2c3
5 changed files with 106 additions and 10 deletions

View File

@ -50,9 +50,12 @@ pub use self::parser::*;
/// Contains the Type Checker error definitions.
pub mod type_checker;
pub use self::type_checker::*;
/// Contains the Utils error definitions.
pub mod utils;
pub use self::utils::*;
/// The LeoError type that contains all sub error types.
/// This allows a unified error type throughout the Leo crates.
#[derive(Debug, Error)]
@ -88,6 +91,9 @@ pub enum LeoError {
/// not re-displaying an error.
#[error("")]
LastErrorCode(i32),
/// Represents a Utils Error in a Leo Error
#[error(transparent)]
UtilError(#[from] UtilError),
/// Anyhow errors.
#[error(transparent)]
Anyhow(#[from] anyhow::Error),
@ -108,6 +114,7 @@ impl LeoError {
TypeCheckerError(error) => error.error_code(),
LoopUnrollerError(error) => error.error_code(),
FlattenError(error) => error.error_code(),
UtilError(error) => error.error_code(),
LastErrorCode(_) => unreachable!(),
Anyhow(_) => unimplemented!(), // todo: implement error codes for snarkvm errors.
}
@ -127,6 +134,7 @@ impl LeoError {
TypeCheckerError(error) => error.exit_code(),
LoopUnrollerError(error) => error.exit_code(),
FlattenError(error) => error.exit_code(),
UtilError(error) => error.exit_code(),
LastErrorCode(code) => *code,
Anyhow(_) => unimplemented!(), // todo: implement exit codes for snarkvm errors.
}

View File

@ -300,14 +300,6 @@ create_messages!(
help: None,
}
/// Enforce that cannot use import in program scope
@formatted
cannot_import_inside_program_body {
args: (),
msg: format!("Cannot use import inside program body."),
help: None,
}
@formatted
array_must_have_at_least_one_element {
args: (kind: impl Display),

View File

@ -688,7 +688,7 @@ create_messages!(
@formatted
stub_functions_must_not_be_inlines {
args: (),
msg: format!("Function stubs must be transitions or function variants not inlines"),
msg: format!("Function stubs must be transitions or functions not inlines"),
help: None,
}

View File

@ -0,0 +1,19 @@
// 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/>.
/// This module contains the Input error definitions.
pub mod util_errors;
pub use self::util_errors::*;

View File

@ -0,0 +1,77 @@
// 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: (error: impl ErrorArg),
msg: format!("File system io error: {error}"),
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,
}
);