From 2a99a87da7e0c241368bb42d3eef501e1bceabbf Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Wed, 4 Aug 2021 14:19:19 -0700 Subject: [PATCH] colored backtrace reports, full and 1 for leo backtrace --- Cargo.lock | 22 ++++ Cargo.toml | 3 + asg/src/const_value.rs | 62 ++------- asg/src/expression/array_access.rs | 12 +- asg/src/expression/array_init.rs | 12 +- asg/src/expression/array_inline.rs | 6 +- asg/src/expression/array_range_access.rs | 27 ++-- asg/src/expression/binary.rs | 17 +-- asg/src/expression/call.rs | 67 ++++------ asg/src/expression/cast.rs | 4 +- asg/src/expression/circuit_access.rs | 25 ++-- asg/src/expression/circuit_init.rs | 42 ++---- asg/src/expression/constant.rs | 32 ++--- asg/src/expression/ternary.rs | 4 +- asg/src/expression/tuple_access.rs | 5 +- asg/src/expression/tuple_init.rs | 4 +- asg/src/expression/unary.rs | 16 +-- asg/src/expression/variable_ref.rs | 9 +- asg/src/program/circuit.rs | 15 +-- asg/src/program/function.rs | 12 +- asg/src/program/mod.rs | 20 +-- asg/src/scope.rs | 10 +- asg/src/statement/assign.rs | 46 ++----- asg/src/statement/definition.rs | 12 +- asg/src/statement/iteration.rs | 12 +- ast/src/lib.rs | 16 +-- ast/src/reducer/canonicalization.rs | 12 +- ast/src/reducer/reconstructing_director.rs | 4 +- compiler/src/compiler.rs | 6 +- compiler/src/console/assert.rs | 9 +- compiler/src/console/format.rs | 16 +-- compiler/src/constraints/constraints.rs | 8 +- compiler/src/expression/arithmetic/add.rs | 6 +- compiler/src/expression/arithmetic/bit_not.rs | 4 +- compiler/src/expression/arithmetic/div.rs | 6 +- compiler/src/expression/arithmetic/mul.rs | 6 +- compiler/src/expression/arithmetic/negate.rs | 4 +- compiler/src/expression/arithmetic/pow.rs | 6 +- compiler/src/expression/arithmetic/sub.rs | 6 +- compiler/src/expression/array/access.rs | 40 +++--- compiler/src/expression/array/array.rs | 6 +- compiler/src/expression/array/index.rs | 4 +- compiler/src/expression/circuit/access.rs | 19 +-- compiler/src/expression/circuit/circuit.rs | 4 +- .../src/expression/conditional/conditional.rs | 11 +- compiler/src/expression/logical/and.rs | 6 +- compiler/src/expression/logical/not.rs | 4 +- compiler/src/expression/logical/or.rs | 6 +- compiler/src/expression/relational/eq.rs | 9 +- compiler/src/expression/relational/ge.rs | 9 +- compiler/src/expression/relational/gt.rs | 9 +- compiler/src/expression/relational/le.rs | 9 +- compiler/src/expression/relational/lt.rs | 9 +- compiler/src/expression/tuple/access.rs | 6 +- .../expression/variable_ref/variable_ref.rs | 11 +- compiler/src/function/function.rs | 3 +- compiler/src/function/input/array.rs | 14 +- compiler/src/function/input/input_section.rs | 6 +- .../src/function/input/main_function_input.rs | 35 ++--- compiler/src/function/input/tuple.rs | 14 +- compiler/src/function/main_function.rs | 28 ++-- compiler/src/function/result/result.rs | 10 +- compiler/src/output/mod.rs | 12 +- compiler/src/output/output_bytes.rs | 12 +- compiler/src/output/output_file.rs | 8 +- compiler/src/phases/reducing_director.rs | 10 +- compiler/src/prelude/blake2s.rs | 10 +- compiler/src/statement/assign/assign.rs | 4 +- .../statement/assign/assignee/array_index.rs | 50 +++---- .../assign/assignee/array_range_index.rs | 8 +- .../src/statement/assign/assignee/member.rs | 11 +- compiler/src/statement/assign/assignee/mod.rs | 11 +- .../src/statement/assign/assignee/tuple.rs | 14 +- .../src/statement/conditional/conditional.rs | 7 +- .../src/statement/definition/definition.rs | 5 +- compiler/src/statement/iteration/iteration.rs | 6 +- compiler/src/statement/statement.rs | 10 +- compiler/src/value/address/address.rs | 10 +- compiler/src/value/boolean/input.rs | 6 +- compiler/src/value/char/char.rs | 4 +- compiler/src/value/field/field_type.rs | 24 ++-- compiler/src/value/field/input.rs | 16 +-- compiler/src/value/group/input.rs | 6 +- .../src/value/group/targets/edwards_bls12.rs | 70 +++++----- compiler/src/value/integer/integer.rs | 26 ++-- compiler/src/value/integer/macros.rs | 123 +++++++----------- errors/Cargo.toml | 3 + errors/src/asg/asg_errors.rs | 2 +- errors/src/ast/ast_errors.rs | 2 +- errors/src/cli/cli_errors.rs | 10 +- errors/src/common/backtraced.rs | 48 +++++-- errors/src/common/formatted.rs | 34 ++++- errors/src/common/macros.rs | 67 +++++----- errors/src/common/traits.rs | 18 +-- errors/src/compiler/compiler_errors.rs | 2 +- errors/src/import/import_errors.rs | 2 +- errors/src/lib.rs | 9 +- errors/src/package/package_errors.rs | 2 +- errors/src/parser/parser_errors.rs | 2 +- errors/src/state/state_errors.rs | 4 +- imports/src/parser/import_parser.rs | 4 +- imports/src/parser/parse_package.rs | 16 +-- imports/src/parser/parse_symbol.rs | 12 +- leo/api.rs | 42 +++--- leo/commands/build.rs | 4 +- leo/commands/init.rs | 8 +- leo/commands/new.rs | 8 +- leo/commands/package/add.rs | 30 ++--- leo/commands/package/clone.rs | 24 ++-- leo/commands/package/login.rs | 14 +- leo/commands/package/publish.rs | 12 +- leo/commands/prove.rs | 4 +- leo/commands/setup.rs | 14 +- leo/commands/test.rs | 4 +- leo/commands/update.rs | 5 +- leo/commands/watch.rs | 4 +- leo/config.rs | 55 ++++---- leo/context.rs | 4 +- leo/logger.rs | 4 +- leo/main.rs | 4 +- leo/updater.rs | 20 ++- package/src/imports/directory.rs | 8 +- package/src/inputs/directory.rs | 25 ++-- package/src/inputs/input.rs | 8 +- package/src/inputs/pairs.rs | 8 +- package/src/inputs/state.rs | 8 +- package/src/outputs/checksum.rs | 13 +- package/src/outputs/circuit.rs | 12 +- package/src/outputs/directory.rs | 7 +- package/src/outputs/proof.rs | 12 +- package/src/outputs/proving_key.rs | 11 +- package/src/outputs/verification_key.rs | 14 +- package/src/package.rs | 18 +-- package/src/root/gitignore.rs | 6 +- package/src/root/manifest.rs | 25 ++-- package/src/root/readme.rs | 6 +- package/src/root/zip.rs | 19 ++- package/src/source/directory.rs | 30 ++--- package/src/source/main.rs | 6 +- parser/src/parser/context.rs | 9 +- parser/src/parser/expression.rs | 14 +- parser/src/parser/file.rs | 29 ++--- parser/src/parser/mod.rs | 4 +- parser/src/parser/statement.rs | 24 +--- parser/src/parser/type_.rs | 4 +- parser/src/tokenizer/mod.rs | 7 +- 146 files changed, 875 insertions(+), 1289 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e4827c7909..0df69a59ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -340,6 +340,17 @@ dependencies = [ "vec_map", ] +[[package]] +name = "color-backtrace" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd6c04463c99389fff045d2b90ce84f5131332712c7ffbede020f5e9ad1ed685" +dependencies = [ + "atty", + "backtrace", + "termcolor", +] + [[package]] name = "colored" version = "2.0.0" @@ -1263,6 +1274,7 @@ name = "leo-errors" version = "1.5.3" dependencies = [ "backtrace", + "color-backtrace", "derivative", "eyre", "leo-input", @@ -1304,6 +1316,7 @@ dependencies = [ "ansi_term 0.12.1", "assert_cmd", "clap", + "color-backtrace", "colored", "console", "dirs", @@ -2802,6 +2815,15 @@ dependencies = [ "utf-8", ] +[[package]] +name = "termcolor" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" +dependencies = [ + "winapi-util", +] + [[package]] name = "terminal_size" version = "0.1.17" diff --git a/Cargo.toml b/Cargo.toml index b8dad67f1e..d534cd27c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,6 +102,9 @@ version = "0.3" [dependencies.clap] version = "2.33.3" +[dependencies] +color-backtrace = "0.5.1" + [dependencies.colored] version = "2.0" diff --git a/asg/src/const_value.rs b/asg/src/const_value.rs index bb83469e95..5ed2f9b40d 100644 --- a/asg/src/const_value.rs +++ b/asg/src/const_value.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{Circuit, Identifier, IntegerType, Type}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use indexmap::IndexMap; use num_bigint::BigInt; @@ -316,56 +316,16 @@ impl ConstInt { pub fn parse(int_type: &IntegerType, value: &str, span: &Span) -> Result { Ok(match int_type { - IntegerType::I8 => ConstInt::I8( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), - IntegerType::I16 => ConstInt::I16( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), - IntegerType::I32 => ConstInt::I32( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), - IntegerType::I64 => ConstInt::I64( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), - IntegerType::I128 => ConstInt::I128( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), - IntegerType::U8 => ConstInt::U8( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), - IntegerType::U16 => ConstInt::U16( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), - IntegerType::U32 => ConstInt::U32( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), - IntegerType::U64 => ConstInt::U64( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), - IntegerType::U128 => ConstInt::U128( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), + IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), + IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), + IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), + IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), + IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), + IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), + IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), + IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), + IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), + IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), }) } } diff --git a/asg/src/expression/array_access.rs b/asg/src/expression/array_access.rs index 903a3af83c..5987a48fd9 100644 --- a/asg/src/expression/array_access.rs +++ b/asg/src/expression/array_access.rs @@ -16,7 +16,7 @@ use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; use leo_ast::IntegerType; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -97,7 +97,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayAccessExpression> for ArrayAccessExpression<' "array", type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()), &value.span, - new_backtrace(), ) .into()); } @@ -115,12 +114,9 @@ impl<'a> FromAst<'a, leo_ast::ArrayAccessExpression> for ArrayAccessExpression<' .flatten() { if index >= array_len { - return Err(AsgError::array_index_out_of_bounds( - index, - &array.span().cloned().unwrap_or_default(), - new_backtrace(), - ) - .into()); + return Err( + AsgError::array_index_out_of_bounds(index, &array.span().cloned().unwrap_or_default()).into(), + ); } } diff --git a/asg/src/expression/array_init.rs b/asg/src/expression/array_init.rs index b3482fc8bb..23ea049271 100644 --- a/asg/src/expression/array_init.rs +++ b/asg/src/expression/array_init.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -74,7 +74,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> { Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims), None => (None, None), Some(type_) => { - return Err(AsgError::unexpected_type(type_, "array", &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(type_, "array", &value.span).into()); } }; let dimensions = value @@ -84,20 +84,19 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> { .map(|x| { Ok(x.value .parse::() - .map_err(|_| AsgError::parse_dimension_error(&value.span, new_backtrace()))?) + .map_err(|_| AsgError::parse_dimension_error(&value.span))?) }) .collect::>>()?; let len = *dimensions .get(0) - .ok_or_else(|| AsgError::parse_dimension_error(&value.span, new_backtrace()))?; + .ok_or_else(|| AsgError::parse_dimension_error(&value.span))?; if let Some(expected_len) = expected_len { if expected_len != len { return Err(AsgError::unexpected_type( format!("array of length {}", expected_len), format!("array of length {}", len), &value.span, - new_backtrace(), ) .into()); } @@ -112,7 +111,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> { format!("array of length {}", dimension), format!("array of length {}", len), &value.span, - new_backtrace(), ) .into()); } @@ -122,7 +120,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> { } None => None, Some(type_) => { - return Err(AsgError::unexpected_type("array", type_, &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type("array", type_, &value.span).into()); } } } diff --git a/asg/src/expression/array_inline.rs b/asg/src/expression/array_inline.rs index a16b6b3515..56bd7d8987 100644 --- a/asg/src/expression/array_inline.rs +++ b/asg/src/expression/array_inline.rs @@ -16,7 +16,7 @@ use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; use leo_ast::SpreadOrExpression; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -109,7 +109,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<' Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims), None => (None, None), Some(type_) => { - return Err(AsgError::unexpected_type(type_, "array", &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(type_, "array", &value.span).into()); } }; @@ -174,7 +174,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<' .unwrap_or("unknown"), type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()), &value.span, - new_backtrace(), ) .into()); } @@ -190,7 +189,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<' format!("array of length {}", expected_len), format!("array of length {}", len), &value.span, - new_backtrace(), ) .into()); } diff --git a/asg/src/expression/array_range_access.rs b/asg/src/expression/array_range_access.rs index 469d1ec87a..0d32f3933f 100644 --- a/asg/src/expression/array_range_access.rs +++ b/asg/src/expression/array_range_access.rs @@ -16,7 +16,7 @@ use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; use leo_ast::IntegerType; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -108,7 +108,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx Some(PartialType::Array(element, len)) => (Some(PartialType::Array(element, None)), len), None => (None, None), Some(x) => { - return Err(AsgError::unexpected_type(x, "array", &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, "array", &value.span).into()); } }; let array = <&Expression<'a>>::from_ast(scope, &*value.array, expected_array)?; @@ -120,7 +120,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx "array", type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()), &value.span, - new_backtrace(), ) .into()); } @@ -156,9 +155,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx } else { value.span.clone() }; - return Err( - AsgError::array_index_out_of_bounds(inner_value, &error_span, new_backtrace()).into(), - ); + return Err(AsgError::array_index_out_of_bounds(inner_value, &error_span).into()); } else if let Some(left) = const_left { if left > inner_value { let error_span = if let Some(right) = right { @@ -166,9 +163,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx } else { value.span.clone() }; - return Err( - AsgError::array_index_out_of_bounds(inner_value, &error_span, new_backtrace()).into(), - ); + return Err(AsgError::array_index_out_of_bounds(inner_value, &error_span).into()); } } } @@ -188,13 +183,9 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx if let Some(length) = length { if length != expected_len { let concrete_type = Type::Array(parent_element, length); - return Err(AsgError::unexpected_type( - expected_type.as_ref().unwrap(), - concrete_type, - &value.span, - new_backtrace(), - ) - .into()); + return Err( + AsgError::unexpected_type(expected_type.as_ref().unwrap(), concrete_type, &value.span).into(), + ); } } if let Some(left_value) = const_left { @@ -204,13 +195,13 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx } else { value.span.clone() }; - return Err(AsgError::array_index_out_of_bounds(left_value, &error_span, new_backtrace()).into()); + return Err(AsgError::array_index_out_of_bounds(left_value, &error_span).into()); } } length = Some(expected_len); } if length.is_none() { - return Err(AsgError::unknown_array_size(&value.span, new_backtrace()).into()); + return Err(AsgError::unknown_array_size(&value.span).into()); } Ok(ArrayRangeAccessExpression { diff --git a/asg/src/expression/binary.rs b/asg/src/expression/binary.rs index cda0e82e65..3029e2b98c 100644 --- a/asg/src/expression/binary.rs +++ b/asg/src/expression/binary.rs @@ -16,7 +16,7 @@ use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; pub use leo_ast::{BinaryOperation, BinaryOperationClass}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -123,7 +123,7 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { BinaryOperationClass::Boolean => match expected_type { Some(PartialType::Type(Type::Boolean)) | None => None, Some(x) => { - return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span).into()); } }, BinaryOperationClass::Numeric => match expected_type { @@ -131,9 +131,7 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { Some(x @ PartialType::Type(Type::Field)) => Some(x), Some(x @ PartialType::Type(Type::Group)) => Some(x), Some(x) => { - return Err( - AsgError::unexpected_type(x, "integer, field, or group", &value.span, new_backtrace()).into(), - ); + return Err(AsgError::unexpected_type(x, "integer, field, or group", &value.span).into()); } None => None, }, @@ -186,7 +184,6 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { "integer", type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()), &value.span, - new_backtrace(), ) .into()); } @@ -195,14 +192,14 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { BinaryOperation::And | BinaryOperation::Or => match left_type { Some(Type::Boolean) | None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, Type::Boolean, &value.span).into()); } }, BinaryOperation::Eq | BinaryOperation::Ne => (), // all types allowed _ => match left_type { Some(Type::Integer(_)) | None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, "integer", &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, "integer", &value.span).into()); } }, }, @@ -213,11 +210,11 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { match (left_type, right_type) { (Some(left_type), Some(right_type)) => { if !left_type.is_assignable_from(&right_type) { - return Err(AsgError::unexpected_type(left_type, right_type, &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(left_type, right_type, &value.span).into()); } } (None, None) => { - return Err(AsgError::unexpected_type("any type", "unknown type", &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type("any type", "unknown type", &value.span).into()); } (_, _) => (), } diff --git a/asg/src/expression/call.rs b/asg/src/expression/call.rs index d444d38fbb..2748ea9f6b 100644 --- a/asg/src/expression/call.rs +++ b/asg/src/expression/call.rs @@ -28,7 +28,7 @@ use crate::{ Type, }; pub use leo_ast::{BinaryOperation, Node as AstNode}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -94,7 +94,7 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { None, scope .resolve_function(&name.name) - .ok_or_else(|| AsgError::unresolved_function(&name.name, &name.span, new_backtrace()))?, + .ok_or_else(|| AsgError::unresolved_function(&name.name, &name.span))?, ), leo_ast::Expression::CircuitMemberAccess(leo_ast::CircuitMemberAccessExpression { circuit: ast_circuit, @@ -109,41 +109,28 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { "circuit", type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()), span, - new_backtrace(), ) .into()); } }; let circuit_name = circuit.name.borrow().name.clone(); let member = circuit.members.borrow(); - let member = member.get(name.name.as_ref()).ok_or_else(|| { - AsgError::unresolved_circuit_member(&circuit_name, &name.name, span, new_backtrace()) - })?; + let member = member + .get(name.name.as_ref()) + .ok_or_else(|| AsgError::unresolved_circuit_member(&circuit_name, &name.name, span))?; match member { CircuitMember::Function(body) => { if body.qualifier == FunctionQualifier::Static { - return Err(AsgError::circuit_static_call_invalid( - &circuit_name, - &name.name, - span, - new_backtrace(), - ) - .into()); + return Err(AsgError::circuit_static_call_invalid(&circuit_name, &name.name, span).into()); } else if body.qualifier == FunctionQualifier::MutSelfRef && !target.is_mut_ref() { - return Err(AsgError::circuit_member_mut_call_invalid( - circuit_name, - &name.name, - span, - new_backtrace(), - ) - .into()); + return Err( + AsgError::circuit_member_mut_call_invalid(circuit_name, &name.name, span).into(), + ); } (Some(target), *body) } CircuitMember::Variable(_) => { - return Err( - AsgError::circuit_variable_call(circuit_name, &name.name, span, new_backtrace()).into(), - ); + return Err(AsgError::circuit_variable_call(circuit_name, &name.name, span).into()); } } } @@ -153,35 +140,27 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { span, }) => { let circuit = if let leo_ast::Expression::Identifier(circuit_name) = &**ast_circuit { - scope.resolve_circuit(&circuit_name.name).ok_or_else(|| { - AsgError::unresolved_circuit(&circuit_name.name, &circuit_name.span, new_backtrace()) - })? + scope + .resolve_circuit(&circuit_name.name) + .ok_or_else(|| AsgError::unresolved_circuit(&circuit_name.name, &circuit_name.span))? } else { - return Err(AsgError::unexpected_type("circuit", "unknown", span, new_backtrace()).into()); + return Err(AsgError::unexpected_type("circuit", "unknown", span).into()); }; let circuit_name = circuit.name.borrow().name.clone(); let member = circuit.members.borrow(); - let member = member.get(name.name.as_ref()).ok_or_else(|| { - AsgError::unresolved_circuit_member(&circuit_name, &name.name, span, new_backtrace()) - })?; + let member = member + .get(name.name.as_ref()) + .ok_or_else(|| AsgError::unresolved_circuit_member(&circuit_name, &name.name, span))?; match member { CircuitMember::Function(body) => { if body.qualifier != FunctionQualifier::Static { - return Err(AsgError::circuit_member_call_invalid( - circuit_name, - &name.name, - span, - new_backtrace(), - ) - .into()); + return Err(AsgError::circuit_member_call_invalid(circuit_name, &name.name, span).into()); } (None, *body) } CircuitMember::Variable(_) => { - return Err( - AsgError::circuit_variable_call(circuit_name, &name.name, span, new_backtrace()).into(), - ); + return Err(AsgError::circuit_variable_call(circuit_name, &name.name, span).into()); } } } @@ -189,7 +168,6 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { return Err(AsgError::illegal_ast_structure( "non Identifier/CircuitMemberAccess/CircuitStaticFunctionAccess as call target", &value.span, - new_backtrace(), ) .into()); } @@ -197,7 +175,7 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { if let Some(expected) = expected_type { let output: Type = function.output.clone(); if !expected.matches(&output) { - return Err(AsgError::unexpected_type(expected, output, &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(expected, output, &value.span).into()); } } if value.arguments.len() != function.arguments.len() { @@ -205,7 +183,6 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { function.arguments.len(), value.arguments.len(), &value.span, - new_backtrace(), ) .into()); } @@ -218,14 +195,14 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { let argument = argument.get().borrow(); let converted = <&Expression<'a>>::from_ast(scope, expr, Some(argument.type_.clone().partial()))?; if argument.const_ && !converted.is_consty() { - return Err(AsgError::unexpected_nonconst(expr.span(), new_backtrace()).into()); + return Err(AsgError::unexpected_nonconst(expr.span()).into()); } Ok(Cell::new(converted)) }) .collect::>>()?; if function.is_test() { - return Err(AsgError::call_test_function(&value.span, new_backtrace()).into()); + return Err(AsgError::call_test_function(&value.span).into()); } Ok(CallExpression { parent: Cell::new(None), diff --git a/asg/src/expression/cast.rs b/asg/src/expression/cast.rs index d7ac7b5e4d..3f2765ba5a 100644 --- a/asg/src/expression/cast.rs +++ b/asg/src/expression/cast.rs @@ -16,7 +16,7 @@ use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; pub use leo_ast::UnaryOperation; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -80,7 +80,7 @@ impl<'a> FromAst<'a, leo_ast::CastExpression> for CastExpression<'a> { let target_type = scope.resolve_ast_type(&value.target_type, &value.span)?; if let Some(expected_type) = &expected_type { if !expected_type.matches(&target_type) { - return Err(AsgError::unexpected_type(expected_type, target_type, &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(expected_type, target_type, &value.span).into()); } } diff --git a/asg/src/expression/circuit_access.rs b/asg/src/expression/circuit_access.rs index 5efbfed9e3..2d3d75a267 100644 --- a/asg/src/expression/circuit_access.rs +++ b/asg/src/expression/circuit_access.rs @@ -28,7 +28,7 @@ use crate::{ Type, }; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; #[derive(Clone)] @@ -111,7 +111,6 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx "circuit", x.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()), &value.span, - new_backtrace(), ) .into()); } @@ -124,9 +123,7 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx if let CircuitMember::Variable(type_) = &member { let type_: Type = type_.clone(); if !expected_type.matches(&type_) { - return Err( - AsgError::unexpected_type(expected_type, type_, &value.span, new_backtrace()).into(), - ); + return Err(AsgError::unexpected_type(expected_type, type_, &value.span).into()); } } // used by call expression } @@ -146,20 +143,15 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx CircuitMember::Variable(expected_type.clone()), ); } else { - return Err(AsgError::input_ref_needs_type( - &circuit.name.borrow().name, - &value.name.name, - &value.span, - new_backtrace(), - ) - .into()); + return Err( + AsgError::input_ref_needs_type(&circuit.name.borrow().name, &value.name.name, &value.span).into(), + ); } } else { return Err(AsgError::unresolved_circuit_member( &circuit.name.borrow().name, &value.name.name, &value.span, - new_backtrace(), ) .into()); } @@ -183,14 +175,14 @@ impl<'a> FromAst<'a, leo_ast::CircuitStaticFunctionAccessExpression> for Circuit let circuit = match &*value.circuit { leo_ast::Expression::Identifier(name) => scope .resolve_circuit(&name.name) - .ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span, new_backtrace()))?, + .ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span))?, _ => { - return Err(AsgError::unexpected_type("circuit", "unknown", &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type("circuit", "unknown", &value.span).into()); } }; if let Some(expected_type) = expected_type { - return Err(AsgError::unexpected_type(expected_type, "none", &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(expected_type, "none", &value.span).into()); } if let Some(CircuitMember::Function(_)) = circuit.members.borrow().get(value.name.name.as_ref()) { @@ -200,7 +192,6 @@ impl<'a> FromAst<'a, leo_ast::CircuitStaticFunctionAccessExpression> for Circuit &circuit.name.borrow().name, &value.name.name, &value.span, - new_backtrace(), ) .into()); } diff --git a/asg/src/expression/circuit_init.rs b/asg/src/expression/circuit_init.rs index 26f53754d3..2636c068fa 100644 --- a/asg/src/expression/circuit_init.rs +++ b/asg/src/expression/circuit_init.rs @@ -28,7 +28,7 @@ use crate::{ Type, }; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use indexmap::{IndexMap, IndexSet}; use std::cell::Cell; @@ -96,18 +96,12 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<' ) -> Result> { let circuit = scope .resolve_circuit(&value.name.name) - .ok_or_else(|| AsgError::unresolved_circuit(&value.name.name, &value.name.span, new_backtrace()))?; + .ok_or_else(|| AsgError::unresolved_circuit(&value.name.name, &value.name.span))?; match expected_type { Some(PartialType::Type(Type::Circuit(expected_circuit))) if expected_circuit == circuit => (), None => (), Some(x) => { - return Err(AsgError::unexpected_type( - x, - circuit.name.borrow().name.to_string(), - &value.span, - new_backtrace(), - ) - .into()); + return Err(AsgError::unexpected_type(x, circuit.name.borrow().name.to_string(), &value.span).into()); } } let members: IndexMap<&str, (&Identifier, Option<&leo_ast::Expression>)> = value @@ -123,13 +117,9 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<' let circuit_members = circuit.members.borrow(); for (name, member) in circuit_members.iter() { if defined_variables.contains(name) { - return Err(AsgError::overridden_circuit_member( - &circuit.name.borrow().name, - name, - &value.span, - new_backtrace(), - ) - .into()); + return Err( + AsgError::overridden_circuit_member(&circuit.name.borrow().name, name, &value.span).into(), + ); } defined_variables.insert(name.clone()); let type_: Type = if let CircuitMember::Variable(type_) = &member { @@ -149,25 +139,17 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<' }; values.push(((*identifier).clone(), Cell::new(received))); } else { - return Err(AsgError::missing_circuit_member( - &circuit.name.borrow().name, - name, - &value.span, - new_backtrace(), - ) - .into()); + return Err( + AsgError::missing_circuit_member(&circuit.name.borrow().name, name, &value.span).into(), + ); } } for (name, (identifier, _expression)) in members.iter() { if circuit_members.get(*name).is_none() { - return Err(AsgError::extra_circuit_member( - &circuit.name.borrow().name, - name, - &identifier.span, - new_backtrace(), - ) - .into()); + return Err( + AsgError::extra_circuit_member(&circuit.name.borrow().name, name, &identifier.span).into(), + ); } } } diff --git a/asg/src/expression/constant.rs b/asg/src/expression/constant.rs index b79e1b4183..81834d95c2 100644 --- a/asg/src/expression/constant.rs +++ b/asg/src/expression/constant.rs @@ -28,7 +28,7 @@ use crate::{ Type, }; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -85,7 +85,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { match expected_type.map(PartialType::full).flatten() { Some(Type::Address) | None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, Type::Address, span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, Type::Address, span).into()); } } Constant { @@ -98,7 +98,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { match expected_type.map(PartialType::full).flatten() { Some(Type::Boolean) | None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, Type::Boolean, span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, Type::Boolean, span).into()); } } Constant { @@ -107,7 +107,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { value: ConstValue::Boolean( value .parse::() - .map_err(|_| AsgError::invalid_boolean(value, span, new_backtrace()))?, + .map_err(|_| AsgError::invalid_boolean(value, span))?, ), } } @@ -115,7 +115,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { match expected_type.map(PartialType::full).flatten() { Some(Type::Char) | None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, Type::Char, value.span(), new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, Type::Char, value.span()).into()); } } @@ -129,24 +129,20 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { match expected_type.map(PartialType::full).flatten() { Some(Type::Field) | None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, Type::Field, span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, Type::Field, span).into()); } } Constant { parent: Cell::new(None), span: Some(span.clone()), - value: ConstValue::Field( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), + value: ConstValue::Field(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), } } Group(value) => { match expected_type.map(PartialType::full).flatten() { Some(Type::Group) | None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, Type::Group, value.span(), new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, Type::Group, value.span()).into()); } } Constant { @@ -163,7 +159,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { } } Implicit(value, span) => match expected_type { - None => return Err(AsgError::unresolved_type("unknown", span, new_backtrace()).into()), + None => return Err(AsgError::unresolved_type("unknown", span).into()), Some(PartialType::Integer(Some(sub_type), _)) | Some(PartialType::Integer(None, Some(sub_type))) => { Constant { parent: Cell::new(None), @@ -174,11 +170,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { Some(PartialType::Type(Type::Field)) => Constant { parent: Cell::new(None), span: Some(span.clone()), - value: ConstValue::Field( - value - .parse() - .map_err(|_| AsgError::invalid_int(value, span, new_backtrace()))?, - ), + value: ConstValue::Field(value.parse().map_err(|_| AsgError::invalid_int(value, span))?), }, Some(PartialType::Type(Type::Group)) => Constant { parent: Cell::new(None), @@ -191,7 +183,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { value: ConstValue::Address(value.clone()), }, Some(x) => { - return Err(AsgError::unexpected_type(x, "unknown", span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, "unknown", span).into()); } }, Integer(int_type, value, span) => { @@ -200,7 +192,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { Some(PartialType::Integer(None, Some(_))) => (), None => (), Some(x) => { - return Err(AsgError::unexpected_type(x, int_type, span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(x, int_type, span).into()); } } Constant { diff --git a/asg/src/expression/ternary.rs b/asg/src/expression/ternary.rs index 7c0f9527af..8f286d4559 100644 --- a/asg/src/expression/ternary.rs +++ b/asg/src/expression/ternary.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -91,7 +91,7 @@ impl<'a> FromAst<'a, leo_ast::TernaryExpression> for TernaryExpression<'a> { let right = if_false.get().get_type().unwrap().into(); if left != right { - return Err(AsgError::ternary_different_types(left, right, &value.span, new_backtrace()).into()); + return Err(AsgError::ternary_different_types(left, right, &value.span).into()); } Ok(TernaryExpression { diff --git a/asg/src/expression/tuple_access.rs b/asg/src/expression/tuple_access.rs index 44619936e5..327ed51548 100644 --- a/asg/src/expression/tuple_access.rs +++ b/asg/src/expression/tuple_access.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -80,7 +80,7 @@ impl<'a> FromAst<'a, leo_ast::TupleAccessExpression> for TupleAccessExpression<' .index .value .parse::() - .map_err(|_| AsgError::parse_index_error(&value.span, new_backtrace()))?; + .map_err(|_| AsgError::parse_index_error(&value.span))?; let mut expected_tuple = vec![None; index + 1]; expected_tuple[index] = expected_type; @@ -95,7 +95,6 @@ impl<'a> FromAst<'a, leo_ast::TupleAccessExpression> for TupleAccessExpression<' .map(|x| x.to_string()) .unwrap_or_else(|| "unknown".to_string()), &value.span, - new_backtrace(), ) .into()); } diff --git a/asg/src/expression/tuple_init.rs b/asg/src/expression/tuple_init.rs index b0a6791206..317020f80a 100644 --- a/asg/src/expression/tuple_init.rs +++ b/asg/src/expression/tuple_init.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -90,7 +90,6 @@ impl<'a> FromAst<'a, leo_ast::TupleInitExpression> for TupleInitExpression<'a> { "tuple", x.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()), &value.span, - new_backtrace(), ) .into()); } @@ -104,7 +103,6 @@ impl<'a> FromAst<'a, leo_ast::TupleInitExpression> for TupleInitExpression<'a> { format!("tuple of length {}", tuple_types.len()), format!("tuple of length {}", value.elements.len()), &value.span, - new_backtrace(), ) .into()); } diff --git a/asg/src/expression/unary.rs b/asg/src/expression/unary.rs index 612a3c59e8..a9da91eec6 100644 --- a/asg/src/expression/unary.rs +++ b/asg/src/expression/unary.rs @@ -16,7 +16,7 @@ use crate::{ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Type}; pub use leo_ast::UnaryOperation; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -95,7 +95,7 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> { UnaryOperation::Not => match expected_type.map(|x| x.full()).flatten() { Some(Type::Boolean) | None => Some(Type::Boolean), Some(type_) => { - return Err(AsgError::unexpected_type(type_, Type::Boolean, &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(type_, Type::Boolean, &value.span).into()); } }, UnaryOperation::Negate => match expected_type.map(|x| x.full()).flatten() { @@ -104,20 +104,14 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> { Some(Type::Field) => Some(Type::Field), None => None, Some(type_) => { - return Err(AsgError::unexpected_type( - type_, - "integer, group, field", - &value.span, - new_backtrace(), - ) - .into()); + return Err(AsgError::unexpected_type(type_, "integer, group, field", &value.span).into()); } }, UnaryOperation::BitNot => match expected_type.map(|x| x.full()).flatten() { Some(type_ @ Type::Integer(_)) => Some(type_), None => None, Some(type_) => { - return Err(AsgError::unexpected_type(type_, "integer", &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(type_, "integer", &value.span).into()); } }, }; @@ -132,7 +126,7 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> { }) .unwrap_or(false); if is_expr_unsigned { - return Err(AsgError::unsigned_negation(&value.span, new_backtrace()).into()); + return Err(AsgError::unsigned_negation(&value.span).into()); } } Ok(UnaryExpression { diff --git a/asg/src/expression/variable_ref.rs b/asg/src/expression/variable_ref.rs index 46af2ab766..4df4849a35 100644 --- a/asg/src/expression/variable_ref.rs +++ b/asg/src/expression/variable_ref.rs @@ -29,7 +29,7 @@ use crate::{ Variable, }; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -143,7 +143,6 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> { return Err(AsgError::illegal_input_variable_reference( "attempted to reference input when none is in scope", &value.span, - new_backtrace(), ) .into()); } @@ -158,7 +157,7 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> { value: ConstValue::Address(value.name.clone()), }))); } - return Err(AsgError::unresolved_reference(&value.name, &value.span, new_backtrace()).into()); + return Err(AsgError::unresolved_reference(&value.name, &value.span).into()); } } }; @@ -173,9 +172,9 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> { if let Some(expected_type) = expected_type { let type_ = expression .get_type() - .ok_or_else(|| AsgError::unresolved_reference(&value.name, &value.span, new_backtrace()))?; + .ok_or_else(|| AsgError::unresolved_reference(&value.name, &value.span))?; if !expected_type.matches(&type_) { - return Err(AsgError::unexpected_type(expected_type, type_, &value.span, new_backtrace()).into()); + return Err(AsgError::unexpected_type(expected_type, type_, &value.span).into()); } } diff --git a/asg/src/program/circuit.rs b/asg/src/program/circuit.rs index cdc29f7981..36fa24902e 100644 --- a/asg/src/program/circuit.rs +++ b/asg/src/program/circuit.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{Function, Identifier, Node, Scope, Type}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use indexmap::IndexMap; use std::cell::RefCell; @@ -71,13 +71,9 @@ impl<'a> Circuit<'a> { for member in value.members.iter() { if let leo_ast::CircuitMember::CircuitVariable(name, type_) = member { if members.contains_key(name.name.as_ref()) { - return Err(AsgError::redefined_circuit_member( - &value.circuit_name.name, - &name.name, - &name.span, - new_backtrace(), - ) - .into()); + return Err( + AsgError::redefined_circuit_member(&value.circuit_name.name, &name.name, &name.span).into(), + ); } members.insert( name.name.to_string(), @@ -104,14 +100,13 @@ impl<'a> Circuit<'a> { &value.circuit_name.name, &function.identifier.name, &function.identifier.span, - new_backtrace(), ) .into()); } let asg_function = Function::init(new_scope, function)?; asg_function.circuit.replace(Some(circuit)); if asg_function.is_test() { - return Err(AsgError::circuit_test_function(&function.identifier.span, new_backtrace()).into()); + return Err(AsgError::circuit_test_function(&function.identifier.span).into()); } members.insert( function.identifier.name.to_string(), diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index c7215fd1c0..3297f5be8c 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -29,7 +29,7 @@ use crate::{ use indexmap::IndexMap; pub use leo_ast::Annotation; use leo_ast::FunctionInput; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::{Cell, RefCell}; @@ -107,7 +107,7 @@ impl<'a> Function<'a> { } } if qualifier != FunctionQualifier::Static && scope.circuit_self.get().is_none() { - return Err(AsgError::invalid_self_in_global(&value.span, new_backtrace()).into()); + return Err(AsgError::invalid_self_in_global(&value.span).into()); } let function = scope.context.alloc_function(Function { id: scope.context.get_id(), @@ -151,16 +151,12 @@ impl<'a> Function<'a> { let main_block = BlockStatement::from_ast(self.scope, &value.block, None)?; let mut director = MonoidalDirector::new(ReturnPathReducer::new()); if !director.reduce_block(&main_block).0 && !self.output.is_unit() { - return Err( - AsgError::function_missing_return(&self.name.borrow().name, &value.span, new_backtrace()).into(), - ); + return Err(AsgError::function_missing_return(&self.name.borrow().name, &value.span).into()); } #[allow(clippy::never_loop)] // TODO @Protryon: How should we return multiple errors? for (span, error) in director.reducer().errors { - return Err( - AsgError::function_return_validation(&self.name.borrow().name, error, &span, new_backtrace()).into(), - ); + return Err(AsgError::function_return_validation(&self.name.borrow().name, error, &span).into()); } self.body diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index 8f118ba117..76a01fe028 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -26,7 +26,7 @@ pub use function::*; use crate::{node::FromAst, ArenaNode, AsgContext, DefinitionStatement, ImportResolver, Input, Scope, Statement}; use leo_ast::{Identifier, PackageAccess, PackageOrPackages}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use indexmap::IndexMap; use std::cell::{Cell, RefCell}; @@ -164,7 +164,7 @@ impl<'a> Program<'a> { )? { Some(x) => x, None => { - return Err(AsgError::unresolved_import(pretty_package, &Span::default(), new_backtrace()).into()); + return Err(AsgError::unresolved_import(pretty_package, &Span::default()).into()); } }; @@ -196,12 +196,7 @@ impl<'a> Program<'a> { } else if let Some(global_const) = resolved_package.global_consts.get(&name) { imported_global_consts.insert(name.clone(), *global_const); } else { - return Err(AsgError::unresolved_import( - format!("{}.{}", pretty_package, name), - &span, - new_backtrace(), - ) - .into()); + return Err(AsgError::unresolved_import(format!("{}.{}", pretty_package, name), &span).into()); } } ImportSymbol::Alias(name, alias) => { @@ -212,12 +207,7 @@ impl<'a> Program<'a> { } else if let Some(global_const) = resolved_package.global_consts.get(&name) { imported_global_consts.insert(alias.clone(), *global_const); } else { - return Err(AsgError::unresolved_import( - format!("{}.{}", pretty_package, name), - &span, - new_backtrace(), - ) - .into()); + return Err(AsgError::unresolved_import(format!("{}.{}", pretty_package, name), &span).into()); } } } @@ -308,7 +298,7 @@ impl<'a> Program<'a> { let name = name.name.to_string(); if functions.contains_key(&name) { - return Err(AsgError::duplicate_function_definition(name, &function.span, new_backtrace()).into()); + return Err(AsgError::duplicate_function_definition(name, &function.span).into()); } functions.insert(name, asg_function); diff --git a/asg/src/scope.rs b/asg/src/scope.rs index ec1bc3b9bc..ea83b3c019 100644 --- a/asg/src/scope.rs +++ b/asg/src/scope.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{AsgContext, Circuit, DefinitionStatement, Function, Input, Type, Variable}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use indexmap::IndexMap; use std::cell::{Cell, RefCell}; @@ -189,7 +189,7 @@ impl<'a> Scope<'a> { let dimension = dimension .value .parse::() - .map_err(|_| AsgError::parse_index_error(span, new_backtrace()))?; + .map_err(|_| AsgError::parse_index_error(span))?; item = Box::new(Type::Array(item, dimension)); } *item @@ -202,15 +202,15 @@ impl<'a> Scope<'a> { ), Circuit(name) if name.name.as_ref() == "Self" => Type::Circuit( self.resolve_circuit_self() - .ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span, new_backtrace()))?, + .ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span))?, ), SelfType => Type::Circuit( self.resolve_circuit_self() - .ok_or_else(|| AsgError::reference_self_outside_circuit(span, new_backtrace()))?, + .ok_or_else(|| AsgError::reference_self_outside_circuit(span))?, ), Circuit(name) => Type::Circuit( self.resolve_circuit(&name.name) - .ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span, new_backtrace()))?, + .ok_or_else(|| AsgError::unresolved_circuit(&name.name, &name.span))?, ), }) } diff --git a/asg/src/statement/assign.rs b/asg/src/statement/assign.rs index 7a25c93ceb..76e76df82b 100644 --- a/asg/src/statement/assign.rs +++ b/asg/src/statement/assign.rs @@ -32,7 +32,7 @@ use crate::{ }; pub use leo_ast::AssignOperation; use leo_ast::AssigneeAccess as AstAssigneeAccess; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::Cell; @@ -78,18 +78,17 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { return Err(AsgError::illegal_input_variable_reference( "attempted to reference input when none is in scope", &statement.span, - new_backtrace(), ) .into()); } } else { scope .resolve_variable(name) - .ok_or_else(|| AsgError::unresolved_reference(name, span, new_backtrace()))? + .ok_or_else(|| AsgError::unresolved_reference(name, span))? }; if !variable.borrow().mutable { - return Err(AsgError::immutable_assignment(name, &statement.span, new_backtrace()).into()); + return Err(AsgError::immutable_assignment(name, &statement.span).into()); } let mut target_type: Option = Some(variable.borrow().type_.clone().into()); @@ -124,23 +123,13 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { ) { let left = match left { ConstValue::Int(x) => x.to_usize().ok_or_else(|| { - AsgError::invalid_assign_index( - name, - x.to_string(), - &statement.span, - new_backtrace(), - ) + AsgError::invalid_assign_index(name, x.to_string(), &statement.span) })?, _ => unimplemented!(), }; let right = match right { ConstValue::Int(x) => x.to_usize().ok_or_else(|| { - AsgError::invalid_assign_index( - name, - x.to_string(), - &statement.span, - new_backtrace(), - ) + AsgError::invalid_assign_index(name, x.to_string(), &statement.span) })?, _ => unimplemented!(), }; @@ -152,13 +141,12 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { left, right, &statement.span, - new_backtrace(), ) .into()); } } } - _ => return Err(AsgError::index_into_non_array(name, &statement.span, new_backtrace()).into()), + _ => return Err(AsgError::index_into_non_array(name, &statement.span).into()), } AssignAccess::ArrayRange(Cell::new(left), Cell::new(right)) @@ -166,7 +154,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { AstAssigneeAccess::ArrayIndex(index) => { target_type = match target_type.clone() { Some(PartialType::Array(item, _)) => item.map(|x| *x), - _ => return Err(AsgError::index_into_non_array(name, &statement.span, new_backtrace()).into()), + _ => return Err(AsgError::index_into_non_array(name, &statement.span).into()), }; AssignAccess::ArrayIndex(Cell::new(<&Expression<'a>>::from_ast( scope, @@ -178,12 +166,13 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { let index = index .value .parse::() - .map_err(|_| AsgError::parse_index_error(span, new_backtrace()))?; + .map_err(|_| AsgError::parse_index_error(span))?; target_type = match target_type { - Some(PartialType::Tuple(types)) => types.get(index).cloned().ok_or_else(|| { - AsgError::tuple_index_out_of_bounds(index, &statement.span, new_backtrace()) - })?, - _ => return Err(AsgError::index_into_non_tuple(name, &statement.span, new_backtrace()).into()), + Some(PartialType::Tuple(types)) => types + .get(index) + .cloned() + .ok_or_else(|| AsgError::tuple_index_out_of_bounds(index, &statement.span))?, + _ => return Err(AsgError::index_into_non_tuple(name, &statement.span).into()), }; AssignAccess::Tuple(index) } @@ -198,19 +187,13 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { &circuit.name.borrow().name, &name.name, &statement.span, - new_backtrace(), ) })?; let x = match &member { CircuitMember::Variable(type_) => type_.clone(), CircuitMember::Function(_) => { - return Err(AsgError::illegal_function_assign( - &name.name, - &statement.span, - new_backtrace(), - ) - .into()); + return Err(AsgError::illegal_function_assign(&name.name, &statement.span).into()); } }; Some(x.partial()) @@ -219,7 +202,6 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { return Err(AsgError::index_into_non_tuple( &statement.assignee.identifier.name, &statement.span, - new_backtrace(), ) .into()); } diff --git a/asg/src/statement/definition.rs b/asg/src/statement/definition.rs index b32db5816c..6a5f222ed3 100644 --- a/asg/src/statement/definition.rs +++ b/asg/src/statement/definition.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{Expression, ExpressionNode, FromAst, InnerVariable, Node, PartialType, Scope, Statement, Type, Variable}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::{Cell, RefCell}; @@ -71,7 +71,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> { .collect::>() .join(" ,"); - return Err(AsgError::invalid_const_assign(var_names, &statement.span, new_backtrace()).into()); + return Err(AsgError::invalid_const_assign(var_names, &statement.span).into()); } let type_ = type_.or_else(|| value.get_type()); @@ -83,7 +83,6 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> { return Err(AsgError::illegal_ast_structure( "cannot have 0 variable names in destructuring tuple", &statement.span, - new_backtrace(), ) .into()); } @@ -101,7 +100,6 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> { format!("{}-ary tuple", statement.variable_names.len()), type_.map(|x| x.to_string()).unwrap_or_else(|| "unknown".to_string()), &statement.span, - new_backtrace(), ) .into()); } @@ -112,9 +110,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> { variables.push(&*scope.context.alloc_variable(RefCell::new(InnerVariable { id: scope.context.get_id(), name: variable.identifier.clone(), - type_: type_.ok_or_else(|| { - AsgError::unresolved_type(&variable.identifier.name, &statement.span, new_backtrace()) - })?, + type_: type_.ok_or_else(|| AsgError::unresolved_type(&variable.identifier.name, &statement.span))?, mutable: variable.mutable, const_: false, declaration: crate::VariableDeclaration::Definition, @@ -127,7 +123,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> { let mut variables = scope.variables.borrow_mut(); let var_name = variable.borrow().name.name.to_string(); if variables.contains_key(&var_name) { - return Err(AsgError::duplicate_variable_definition(var_name, &statement.span, new_backtrace()).into()); + return Err(AsgError::duplicate_variable_definition(var_name, &statement.span).into()); } variables.insert(var_name, *variable); diff --git a/asg/src/statement/iteration.rs b/asg/src/statement/iteration.rs index 2177943a5d..27de5b4deb 100644 --- a/asg/src/statement/iteration.rs +++ b/asg/src/statement/iteration.rs @@ -17,7 +17,7 @@ use leo_ast::IntegerType; use crate::{Expression, ExpressionNode, FromAst, InnerVariable, Node, PartialType, Scope, Statement, Variable}; -use leo_errors::{new_backtrace, AsgError, Result, Span}; +use leo_errors::{AsgError, Result, Span}; use std::cell::{Cell, RefCell}; @@ -50,14 +50,10 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> { // Return an error if start or stop is not constant. if !start.is_consty() { - return Err( - AsgError::unexpected_nonconst(&start.span().cloned().unwrap_or_default(), new_backtrace()).into(), - ); + return Err(AsgError::unexpected_nonconst(&start.span().cloned().unwrap_or_default()).into()); } if !stop.is_consty() { - return Err( - AsgError::unexpected_nonconst(&stop.span().cloned().unwrap_or_default(), new_backtrace()).into(), - ); + return Err(AsgError::unexpected_nonconst(&stop.span().cloned().unwrap_or_default()).into()); } let variable = scope.context.alloc_variable(RefCell::new(InnerVariable { @@ -65,7 +61,7 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> { name: statement.variable.clone(), type_: start .get_type() - .ok_or_else(|| AsgError::unresolved_type(&statement.variable.name, &statement.span, new_backtrace()))?, + .ok_or_else(|| AsgError::unresolved_type(&statement.variable.name, &statement.span))?, mutable: false, const_: true, declaration: crate::VariableDeclaration::IterationDefinition, diff --git a/ast/src/lib.rs b/ast/src/lib.rs index b7272eed87..eceb10e614 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -62,7 +62,7 @@ pub use self::types::*; mod node; pub use node::*; -use leo_errors::{new_backtrace, AstError, Result}; +use leo_errors::{AstError, Result}; /// The abstract syntax tree (AST) for a Leo program. /// @@ -98,31 +98,27 @@ impl Ast { /// Serializes the ast into a JSON string. pub fn to_json_string(&self) -> Result { - Ok(serde_json::to_string_pretty(&self.ast) - .map_err(|e| AstError::failed_to_convert_ast_to_json_string(&e, new_backtrace()))?) + Ok(serde_json::to_string_pretty(&self.ast).map_err(|e| AstError::failed_to_convert_ast_to_json_string(&e))?) } /// Serializes the ast into a JSON file. pub fn to_json_file(&self, mut path: std::path::PathBuf, file_name: &str) -> Result<()> { path.push(file_name); - let file = std::fs::File::create(&path) - .map_err(|e| AstError::failed_to_create_ast_json_file(&path, &e, new_backtrace()))?; + let file = std::fs::File::create(&path).map_err(|e| AstError::failed_to_create_ast_json_file(&path, &e))?; let writer = std::io::BufWriter::new(file); Ok(serde_json::to_writer_pretty(writer, &self.ast) - .map_err(|e| AstError::failed_to_write_ast_to_json_file(&path, &e, new_backtrace()))?) + .map_err(|e| AstError::failed_to_write_ast_to_json_file(&path, &e))?) } /// Deserializes the JSON string into a ast. pub fn from_json_string(json: &str) -> Result { - let ast: Program = - serde_json::from_str(json).map_err(|e| AstError::failed_to_read_json_string_to_ast(&e, new_backtrace()))?; + let ast: Program = serde_json::from_str(json).map_err(|e| AstError::failed_to_read_json_string_to_ast(&e))?; Ok(Self { ast }) } /// Deserializes the JSON string into a ast from a file. pub fn from_json_file(path: std::path::PathBuf) -> Result { - let data = std::fs::read_to_string(&path) - .map_err(|e| AstError::failed_to_read_json_file(&path, &e, new_backtrace()))?; + let data = std::fs::read_to_string(&path).map_err(|e| AstError::failed_to_read_json_file(&path, &e))?; Self::from_json_string(&data) } } diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 459020cb31..b958cc4b72 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::*; -use leo_errors::{new_backtrace, AstError, Result, Span}; +use leo_errors::{AstError, Result, Span}; /// Replace Self when it is in a enclosing circuit type. /// Error when Self is outside an enclosing circuit type. @@ -469,7 +469,7 @@ impl ReconstructingReducer for Canonicalizer { match new { Type::Array(type_, mut dimensions) => { if dimensions.is_zero() { - return Err(AstError::invalid_array_dimension_size(span, new_backtrace()).into()); + return Err(AstError::invalid_array_dimension_size(span).into()); } let mut next = Type::Array(type_, ArrayDimensions(vec![dimensions.remove_last().unwrap()])); @@ -486,16 +486,14 @@ impl ReconstructingReducer for Canonicalizer { Ok(array) } - Type::SelfType if !self.in_circuit => { - Err(AstError::big_self_outside_of_circuit(span, new_backtrace()).into()) - } + Type::SelfType if !self.in_circuit => Err(AstError::big_self_outside_of_circuit(span).into()), _ => Ok(new.clone()), } } fn reduce_string(&mut self, string: &[Char], span: &Span) -> Result { if string.is_empty() { - return Err(AstError::empty_string(span, new_backtrace()).into()); + return Err(AstError::empty_string(span).into()); } let mut elements = Vec::new(); @@ -554,7 +552,7 @@ impl ReconstructingReducer for Canonicalizer { element: Expression, ) -> Result { if array_init.dimensions.is_zero() { - return Err(AstError::invalid_array_dimension_size(&array_init.span, new_backtrace()).into()); + return Err(AstError::invalid_array_dimension_size(&array_init.span).into()); } let element = Box::new(element); diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 6d44194915..15601cddb5 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -19,7 +19,7 @@ use crate::*; use indexmap::IndexMap; -use leo_errors::{new_backtrace, AstError, Result, Span}; +use leo_errors::{AstError, Result, Span}; pub struct ReconstructingDirector { reducer: R, @@ -386,7 +386,7 @@ impl ReconstructingDirector { match &console_function_call.function { ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted), ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted), - _ => return Err(AstError::impossible_console_assert_call(&args.span, new_backtrace()).into()), + _ => return Err(AstError::impossible_console_assert_call(&args.span).into()), } } }; diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index f3767c8fe0..ccbcd87ecf 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -27,7 +27,7 @@ use crate::{ pub use leo_asg::{new_context, AsgContext as Context, AsgContext}; use leo_asg::{Asg, AsgPass, Program as AsgProgram}; use leo_ast::{Input, MainInput, Program as AstProgram}; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; use leo_parser::parse_ast; @@ -226,7 +226,7 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { pub fn parse_program(&mut self) -> Result<()> { // Load the program file. let content = fs::read_to_string(&self.main_file_path) - .map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e, new_backtrace()))?; + .map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e))?; self.parse_program_from_string(&content) } @@ -324,7 +324,7 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { pub fn checksum(&self) -> Result { // Read in the main file as string let unparsed_file = fs::read_to_string(&self.main_file_path) - .map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e, new_backtrace()))?; + .map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e))?; // Hash the file contents let mut hasher = Sha256::new(); diff --git a/compiler/src/console/assert.rs b/compiler/src/console/assert.rs index f17f1e0398..5ec8b5d001 100644 --- a/compiler/src/console/assert.rs +++ b/compiler/src/console/assert.rs @@ -18,7 +18,7 @@ use crate::{get_indicator_value, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Expression; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::boolean::Boolean; @@ -45,14 +45,13 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let result_option = match assert_expression { ConstrainedValue::Boolean(boolean) => boolean.get_value(), _ => { - return Err(CompilerError::console_assertion_must_be_boolean(span, new_backtrace()).into()); + return Err(CompilerError::console_assertion_must_be_boolean(span).into()); } }; - let result_bool = - result_option.ok_or_else(|| CompilerError::console_assertion_depends_on_input(span, new_backtrace()))?; + let result_bool = result_option.ok_or_else(|| CompilerError::console_assertion_depends_on_input(span))?; if !result_bool { - return Err(CompilerError::console_assertion_failed(span, new_backtrace()).into()); + return Err(CompilerError::console_assertion_failed(span).into()); } Ok(()) diff --git a/compiler/src/console/format.rs b/compiler/src/console/format.rs index a3ee97b32a..560bb4444f 100644 --- a/compiler/src/console/format.rs +++ b/compiler/src/console/format.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, GroupType}; use leo_asg::{CharValue, ConsoleArgs}; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -55,7 +55,6 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { arg_index + 1, args.parameters.len(), &args.span, - new_backtrace(), ) .into()); } @@ -69,20 +68,12 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { substring.push('}'); escape_right_bracket = true; } else { - return Err(CompilerError::console_fmt_expected_escaped_right_brace( - &args.span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::console_fmt_expected_escaped_right_brace(&args.span).into()); } } } _ if in_container => { - return Err(CompilerError::console_fmt_expected_left_or_right_brace( - &args.span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::console_fmt_expected_left_or_right_brace(&args.span).into()); } _ => substring.push(*scalar), }, @@ -100,7 +91,6 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { arg_index, args.parameters.len(), &args.span, - new_backtrace(), ) .into()); } diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 35aef9401d..b81ad10a69 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -19,7 +19,7 @@ use crate::{ConstrainedProgram, GroupType, Output, OutputFile}; use leo_asg::Program; use leo_ast::Input; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; @@ -48,7 +48,7 @@ pub fn generate_constraints<'a, F: PrimeField, G: GroupType, CS: ConstraintSy let result = resolved_program.enforce_main_function(cs, function, input)?; Ok(result) } - _ => Err(CompilerError::no_main_function(new_backtrace()).into()), + _ => Err(CompilerError::no_main_function().into()), } } @@ -103,11 +103,11 @@ pub fn generate_test_constraints<'a, F: PrimeField, G: GroupType>( { Some(pair) => pair.to_owned(), None => { - return Err(CompilerError::invalid_test_context(file_name, new_backtrace()).into()); + return Err(CompilerError::invalid_test_context(file_name).into()); } } } - None => default.ok_or_else(|| CompilerError::no_test_input(new_backtrace()))?, + None => default.ok_or_else(|| CompilerError::no_test_input())?, }; // parse input files to abstract syntax trees diff --git a/compiler/src/expression/arithmetic/add.rs b/compiler/src/expression/arithmetic/add.rs index 79807b2019..187a6377f8 100644 --- a/compiler/src/expression/arithmetic/add.rs +++ b/compiler/src/expression/arithmetic/add.rs @@ -17,7 +17,7 @@ //! Enforces an arithmetic `+` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -39,9 +39,7 @@ pub fn enforce_add<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( Ok(ConstrainedValue::Group(point_1.add(cs, &point_2, span)?)) } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} + {}", val_1, val_2), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} + {}", val_1, val_2), span).into()); } } } diff --git a/compiler/src/expression/arithmetic/bit_not.rs b/compiler/src/expression/arithmetic/bit_not.rs index 8e97afdb88..639fb5aac1 100644 --- a/compiler/src/expression/arithmetic/bit_not.rs +++ b/compiler/src/expression/arithmetic/bit_not.rs @@ -17,7 +17,7 @@ //! Enforces a logical `!` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; @@ -25,5 +25,5 @@ pub fn evaluate_bit_not<'a, F: PrimeField, G: GroupType>( value: ConstrainedValue<'a, F, G>, span: &Span, ) -> Result> { - return Err(CompilerError::cannot_evaluate_expression(format!("!{}", value), span, new_backtrace()).into()); + return Err(CompilerError::cannot_evaluate_expression(format!("!{}", value), span).into()); } diff --git a/compiler/src/expression/arithmetic/div.rs b/compiler/src/expression/arithmetic/div.rs index 9e2a6be9a6..b7020fa73a 100644 --- a/compiler/src/expression/arithmetic/div.rs +++ b/compiler/src/expression/arithmetic/div.rs @@ -17,7 +17,7 @@ //! Enforces an arithmetic `/` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -36,9 +36,7 @@ pub fn enforce_div<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( Ok(ConstrainedValue::Field(field_1.div(cs, &field_2, span)?)) } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} / {}", val_1, val_2,), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} / {}", val_1, val_2,), span).into()); } } } diff --git a/compiler/src/expression/arithmetic/mul.rs b/compiler/src/expression/arithmetic/mul.rs index 1a6921c6aa..3ccb38dda6 100644 --- a/compiler/src/expression/arithmetic/mul.rs +++ b/compiler/src/expression/arithmetic/mul.rs @@ -17,7 +17,7 @@ //! Enforces an arithmetic `*` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -36,9 +36,7 @@ pub fn enforce_mul<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( Ok(ConstrainedValue::Field(field_1.mul(cs, &field_2, span)?)) } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} * {}", val_1, val_2), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} * {}", val_1, val_2), span).into()); } } } diff --git a/compiler/src/expression/arithmetic/negate.rs b/compiler/src/expression/arithmetic/negate.rs index db99bbb06d..165f99ec73 100644 --- a/compiler/src/expression/arithmetic/negate.rs +++ b/compiler/src/expression/arithmetic/negate.rs @@ -17,7 +17,7 @@ //! Enforces a unary negate `-` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -31,6 +31,6 @@ pub fn enforce_negate<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem Ok(ConstrainedValue::Integer(integer.negate(cs, span)?)), ConstrainedValue::Field(field) => Ok(ConstrainedValue::Field(field.negate(cs, span)?)), ConstrainedValue::Group(group) => Ok(ConstrainedValue::Group(group.negate(cs, span)?)), - value => return Err(CompilerError::incompatible_types(format!("-{}", value), span, new_backtrace()).into()), + value => return Err(CompilerError::incompatible_types(format!("-{}", value), span).into()), } } diff --git a/compiler/src/expression/arithmetic/pow.rs b/compiler/src/expression/arithmetic/pow.rs index b7c1a77a45..6202b98277 100644 --- a/compiler/src/expression/arithmetic/pow.rs +++ b/compiler/src/expression/arithmetic/pow.rs @@ -17,7 +17,7 @@ //! Enforces an arithmetic `**` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -33,9 +33,7 @@ pub fn enforce_pow<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( Ok(ConstrainedValue::Integer(num_1.pow(cs, num_2, span)?)) } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} ** {}", val_1, val_2,), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} ** {}", val_1, val_2,), span).into()); } } } diff --git a/compiler/src/expression/arithmetic/sub.rs b/compiler/src/expression/arithmetic/sub.rs index 4b96642c06..5c2a4b3b8a 100644 --- a/compiler/src/expression/arithmetic/sub.rs +++ b/compiler/src/expression/arithmetic/sub.rs @@ -17,7 +17,7 @@ //! Enforces an arithmetic `-` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -39,9 +39,7 @@ pub fn enforce_sub<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( Ok(ConstrainedValue::Group(point_1.sub(cs, &point_2, span)?)) } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} - {}", val_1, val_2), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} - {}", val_1, val_2), span).into()); } } } diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index 05845fb5e6..340d412561 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -26,7 +26,7 @@ use crate::{ GroupType, }; use leo_asg::{ConstInt, Expression}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::{ @@ -62,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let mut unique_namespace = cs.ns(|| namespace_string); bounds_check .enforce_equal(&mut unique_namespace, &Boolean::Constant(true)) - .map_err(|e| CompilerError::cannot_enforce_expression("array bounds check", e, span, new_backtrace()))?; + .map_err(|e| CompilerError::cannot_enforce_expression("array bounds check", e, span))?; Ok(()) } @@ -76,25 +76,25 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { ) -> Result> { let mut array = match self.enforce_expression(cs, array)? { ConstrainedValue::Array(array) => array, - value => return Err(CompilerError::undefined_array(value.to_string(), span, new_backtrace()).into()), + value => return Err(CompilerError::undefined_array(value.to_string(), span).into()), }; let index_resolved = self.enforce_index(cs, index, span)?; if let Some(resolved) = index_resolved.to_usize() { if resolved >= array.len() { - return Err(CompilerError::array_index_out_of_bounds(resolved, span, new_backtrace()).into()); + return Err(CompilerError::array_index_out_of_bounds(resolved, span).into()); } Ok(array[resolved].to_owned()) } else { if array.is_empty() { - return Err(CompilerError::array_index_out_of_bounds(0, span, new_backtrace()).into()); + return Err(CompilerError::array_index_out_of_bounds(0, span).into()); } { let array_len: u32 = array .len() .try_into() - .map_err(|_| CompilerError::array_length_out_of_bounds(span, new_backtrace()))?; + .map_err(|_| CompilerError::array_length_out_of_bounds(span))?; self.array_bounds_check(cs, &index_resolved, array_len, span)?; } @@ -105,19 +105,17 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let index_bounded = i .try_into() - .map_err(|_| CompilerError::array_index_out_of_legal_bounds(span, new_backtrace()))?; + .map_err(|_| CompilerError::array_index_out_of_legal_bounds(span))?; let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type()); let index_comparison = index_resolved .evaluate_equal(eq_namespace, &Integer::new(&const_index)) - .map_err(|_| CompilerError::cannot_evaluate_expression("==", span, new_backtrace()))?; + .map_err(|_| CompilerError::cannot_evaluate_expression("==", span))?; let unique_namespace = cs.ns(|| format!("select array access {} {}:{}", i, span.line_start, span.col_start)); let value = ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &item, ¤t_value) - .map_err(|e| { - CompilerError::cannot_enforce_expression("conditional select", e, span, new_backtrace()) - })?; + .map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, span))?; current_value = value; } Ok(current_value) @@ -136,7 +134,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { ) -> Result> { let array = match self.enforce_expression(cs, array)? { ConstrainedValue::Array(array) => array, - value => return Err(CompilerError::undefined_array(value, span, new_backtrace()).into()), + value => return Err(CompilerError::undefined_array(value, span).into()), }; let from_resolved = match left { @@ -149,7 +147,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let index_bounded: u32 = array .len() .try_into() - .map_err(|_| CompilerError::array_length_out_of_bounds(span, new_backtrace()))?; + .map_err(|_| CompilerError::array_length_out_of_bounds(span))?; Integer::new(&ConstInt::U32(index_bounded)) } // Array slice ends at array length }; @@ -161,10 +159,10 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { }; Ok(if let Some((left, right)) = const_dimensions { if right - left != length { - return Err(CompilerError::array_invalid_slice_length(span, new_backtrace()).into()); + return Err(CompilerError::array_invalid_slice_length(span).into()); } if right > array.len() { - return Err(CompilerError::array_index_out_of_bounds(right, span, new_backtrace()).into()); + return Err(CompilerError::array_index_out_of_bounds(right, span).into()); } ConstrainedValue::Array(array[left..right].to_owned()) } else { @@ -186,9 +184,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let mut unique_namespace = cs.ns(|| namespace_string); calc_len .enforce_equal(&mut unique_namespace, &Integer::new(&ConstInt::U32(length as u32))) - .map_err(|e| { - CompilerError::cannot_enforce_expression("array length check", e, span, new_backtrace()) - })?; + .map_err(|e| CompilerError::cannot_enforce_expression("array length check", e, span))?; } { let bounds_check = evaluate_le::( @@ -208,9 +204,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let mut unique_namespace = cs.ns(|| namespace_string); bounds_check .enforce_equal(&mut unique_namespace, &Boolean::Constant(true)) - .map_err(|e| { - CompilerError::cannot_enforce_expression("array bounds check", e, span, new_backtrace()) - })?; + .map_err(|e| CompilerError::cannot_enforce_expression("array bounds check", e, span))?; } let mut windows = array.windows(length); let mut result = ConstrainedValue::Array(vec![]); @@ -239,9 +233,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let unique_namespace = unique_namespace.ns(|| format!("array index {} {}:{}", i, span.line_start, span.col_start)); result = ConstrainedValue::conditionally_select(unique_namespace, &equality, &array_value, &result) - .map_err(|e| { - CompilerError::cannot_enforce_expression("conditional select", e, span, new_backtrace()) - })?; + .map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, span))?; } result }) diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index 32ff507471..e8c3979c39 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -20,7 +20,7 @@ use std::cell::Cell; use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Expression; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -52,9 +52,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if let Some(dimension) = expected_dimension { // Return an error if the expected dimension != the actual dimension. if dimension != result.len() { - return Err( - CompilerError::unexpected_array_length(dimension, result.len(), span, new_backtrace()).into(), - ); + return Err(CompilerError::unexpected_array_length(dimension, result.len(), span).into()); } } diff --git a/compiler/src/expression/array/index.rs b/compiler/src/expression/array/index.rs index dce7c376b4..8873325eb8 100644 --- a/compiler/src/expression/array/index.rs +++ b/compiler/src/expression/array/index.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType, Integer}; use leo_asg::Expression; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -32,7 +32,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { ) -> Result { match self.enforce_expression(cs, index)? { ConstrainedValue::Integer(number) => Ok(number), - value => Err(CompilerError::invalid_index_expression(value, span, new_backtrace()).into()), + value => Err(CompilerError::invalid_index_expression(value, span).into()), } } } diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index e5fb0bf066..58c0aa9a08 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::{CircuitAccessExpression, Node}; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -43,27 +43,18 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { expr.circuit.get().name.borrow(), &expr.member.name, &expr.member.span, - new_backtrace(), ) .into()); } } value => { - return Err(CompilerError::undefined_circuit( - value, - &target.span().cloned().unwrap_or_default(), - new_backtrace(), - ) - .into()); + return Err( + CompilerError::undefined_circuit(value, &target.span().cloned().unwrap_or_default()).into(), + ); } } } else { - Err(CompilerError::invalid_circuit_static_member_access( - &expr.member.name, - &expr.member.span, - new_backtrace(), - ) - .into()) + Err(CompilerError::invalid_circuit_static_member_access(&expr.member.name, &expr.member.span).into()) } } } diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index e02b72cb49..7732d9b938 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -22,7 +22,7 @@ use crate::{ GroupType, }; use leo_asg::{CircuitInitExpression, CircuitMember}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -50,7 +50,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { resolved_members.push(ConstrainedCircuitMember(name.clone(), variable_value)); } _ => { - return Err(CompilerError::expected_circuit_member(name, span, new_backtrace()).into()); + return Err(CompilerError::expected_circuit_member(name, span).into()); } } } diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index c1fe131fef..661aef7335 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Expression; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::select::CondSelectGadget; @@ -38,12 +38,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let conditional_value = match self.enforce_expression(cs, conditional)? { ConstrainedValue::Boolean(resolved) => resolved, value => { - return Err(CompilerError::conditional_boolean_expression_fails_to_resolve_to_bool( - value, - span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::conditional_boolean_expression_fails_to_resolve_to_bool(value, span).into()); } }; @@ -60,7 +55,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { Ok( ConstrainedValue::conditionally_select(unique_namespace, &conditional_value, &first_value, &second_value) - .map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, span, new_backtrace()))?, + .map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, span))?, ) } } diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index e7acefb64d..50c1526eff 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -17,7 +17,7 @@ //! Enforces a logical `&&` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::boolean::Boolean; @@ -37,10 +37,10 @@ pub fn enforce_and<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( &left_bool, &right_bool, ) - .map_err(|e| CompilerError::cannot_enforce_expression("&&", e, span, new_backtrace()))?; + .map_err(|e| CompilerError::cannot_enforce_expression("&&", e, span))?; return Ok(ConstrainedValue::Boolean(result)); } - Err(CompilerError::cannot_evaluate_expression(name, span, new_backtrace()).into()) + Err(CompilerError::cannot_evaluate_expression(name, span).into()) } diff --git a/compiler/src/expression/logical/not.rs b/compiler/src/expression/logical/not.rs index c2b55a9e23..8ebc132037 100644 --- a/compiler/src/expression/logical/not.rs +++ b/compiler/src/expression/logical/not.rs @@ -17,7 +17,7 @@ //! Enforces a logical `!` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; @@ -28,7 +28,7 @@ pub fn evaluate_not<'a, F: PrimeField, G: GroupType>( match value { ConstrainedValue::Boolean(boolean) => Ok(ConstrainedValue::Boolean(boolean.not())), value => { - return Err(CompilerError::cannot_evaluate_expression(format!("!{}", value), span, new_backtrace()).into()); + return Err(CompilerError::cannot_evaluate_expression(format!("!{}", value), span).into()); } } } diff --git a/compiler/src/expression/logical/or.rs b/compiler/src/expression/logical/or.rs index b8385b4139..f8ab3a9f84 100644 --- a/compiler/src/expression/logical/or.rs +++ b/compiler/src/expression/logical/or.rs @@ -17,7 +17,7 @@ //! Enforces a logical `||` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::boolean::Boolean; @@ -37,10 +37,10 @@ pub fn enforce_or<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( &left_bool, &right_bool, ) - .map_err(|e| CompilerError::cannot_enforce_expression("||", e, span, new_backtrace()))?; + .map_err(|e| CompilerError::cannot_enforce_expression("||", e, span))?; return Ok(ConstrainedValue::Boolean(result)); } - Err(CompilerError::cannot_evaluate_expression(name, span, new_backtrace()).into()) + Err(CompilerError::cannot_evaluate_expression(name, span).into()) } diff --git a/compiler/src/expression/relational/eq.rs b/compiler/src/expression/relational/eq.rs index e9793126a4..3fea711e53 100644 --- a/compiler/src/expression/relational/eq.rs +++ b/compiler/src/expression/relational/eq.rs @@ -17,7 +17,7 @@ //! Enforces a relational `==` operator in a resolved Leo program. use crate::{enforce_and, value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::{boolean::Boolean, traits::eq::EvaluateEqGadget}; @@ -75,14 +75,11 @@ pub fn evaluate_eq<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( return Ok(current); } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} == {}", val_1, val_2,), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} == {}", val_1, val_2,), span).into()); } }; - let boolean = - constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("==", span, new_backtrace()))?; + let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("==", span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index 08bb351893..958588dce9 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -17,7 +17,7 @@ //! Enforces a relational `>=` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::bits::ComparatorGadget; @@ -35,14 +35,11 @@ pub fn evaluate_ge<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( num_1.greater_than_or_equal(unique_namespace, &num_2) } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} >= {}", val_1, val_2), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} >= {}", val_1, val_2), span).into()); } }; - let boolean = - constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression(">=", span, new_backtrace()))?; + let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression(">=", span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index fff3aed20a..ab3f06868c 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -17,7 +17,7 @@ //! Enforces a relational `>` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::bits::ComparatorGadget; @@ -35,14 +35,11 @@ pub fn evaluate_gt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( num_1.greater_than(unique_namespace, &num_2) } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} > {}", val_1, val_2), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} > {}", val_1, val_2), span).into()); } }; - let boolean = - constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression(">", span, new_backtrace()))?; + let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression(">", span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 31afe1bea6..e1f1e57131 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -17,7 +17,7 @@ //! Enforces a relational `<=` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::bits::ComparatorGadget; @@ -35,14 +35,11 @@ pub fn evaluate_le<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( num_1.less_than_or_equal(unique_namespace, &num_2) } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} <= {}", val_1, val_2), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} <= {}", val_1, val_2), span).into()); } }; - let boolean = - constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("<=", span, new_backtrace()))?; + let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("<=", span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 4c6fa1d654..839ea7fb7a 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -17,7 +17,7 @@ //! Enforces a relational `<` operator in a resolved Leo program. use crate::{value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::bits::EvaluateLtGadget; @@ -35,14 +35,11 @@ pub fn evaluate_lt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( num_1.less_than(unique_namespace, &num_2) } (val_1, val_2) => { - return Err( - CompilerError::incompatible_types(format!("{} < {}", val_1, val_2), span, new_backtrace()).into(), - ); + return Err(CompilerError::incompatible_types(format!("{} < {}", val_1, val_2), span).into()); } }; - let boolean = - constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("<", span, new_backtrace()))?; + let boolean = constraint_result.map_err(|_| CompilerError::cannot_evaluate_expression("<", span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/tuple/access.rs b/compiler/src/expression/tuple/access.rs index 0a7bd262e4..59a823ae3b 100644 --- a/compiler/src/expression/tuple/access.rs +++ b/compiler/src/expression/tuple/access.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Expression; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -35,13 +35,13 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { // Get the tuple values. let tuple = match self.enforce_expression(cs, tuple)? { ConstrainedValue::Tuple(tuple) => tuple, - value => return Err(CompilerError::undefined_array(value, span, new_backtrace()).into()), + value => return Err(CompilerError::undefined_array(value, span).into()), }; // Check for out of bounds access. if index > tuple.len() - 1 { // probably safe to be a panic here - return Err(CompilerError::tuple_index_out_of_bounds(index, span, new_backtrace()).into()); + return Err(CompilerError::tuple_index_out_of_bounds(index, span).into()); } Ok(tuple[index].to_owned()) diff --git a/compiler/src/expression/variable_ref/variable_ref.rs b/compiler/src/expression/variable_ref/variable_ref.rs index 721b8fc1f2..a27f3d13e6 100644 --- a/compiler/src/expression/variable_ref/variable_ref.rs +++ b/compiler/src/expression/variable_ref/variable_ref.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::VariableRef; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use snarkvm_fields::PrimeField; @@ -32,12 +32,9 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let result_value = if let Some(value) = self.get(variable.id) { value.clone() } else { - return Err(CompilerError::undefined_identifier( - &variable.name.clone().name, - &span.unwrap_or_default(), - new_backtrace(), - ) - .into()); + return Err( + CompilerError::undefined_identifier(&variable.name.clone().name, &span.unwrap_or_default()).into(), + ); // todo: probably can be a panic here instead }; diff --git a/compiler/src/function/function.rs b/compiler/src/function/function.rs index 9f16619976..4bbf4fa87f 100644 --- a/compiler/src/function/function.rs +++ b/compiler/src/function/function.rs @@ -19,7 +19,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::{Expression, Function, FunctionQualifier}; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use std::cell::Cell; use snarkvm_fields::PrimeField; @@ -52,7 +52,6 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { &function.name.borrow().name.to_string(), "arguments length invalid", &function.span.clone().unwrap_or_default(), - new_backtrace(), ) .into()); } diff --git a/compiler/src/function/input/array.rs b/compiler/src/function/input/array.rs index b79e3c295a..47da5b93f8 100644 --- a/compiler/src/function/input/array.rs +++ b/compiler/src/function/input/array.rs @@ -20,7 +20,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Type; use leo_ast::InputValue; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -41,13 +41,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { match input_value { Some(InputValue::Array(arr)) => { if array_len != arr.len() { - return Err(CompilerError::invalid_input_array_dimensions( - arr.len(), - array_len, - span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::invalid_input_array_dimensions(arr.len(), array_len, span).into()); } // Allocate each value in the current row @@ -72,9 +66,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } } _ => { - return Err( - CompilerError::invalid_function_input_array(input_value.unwrap(), span, new_backtrace()).into(), - ); + return Err(CompilerError::invalid_function_input_array(input_value.unwrap(), span).into()); } } diff --git a/compiler/src/function/input/input_section.rs b/compiler/src/function/input/input_section.rs index 2641f885f5..72b1d7856a 100644 --- a/compiler/src/function/input/input_section.rs +++ b/compiler/src/function/input/input_section.rs @@ -17,7 +17,7 @@ use crate::{ConstrainedCircuitMember, ConstrainedProgram, ConstrainedValue, GroupType}; use leo_asg::{Circuit, CircuitMember}; use leo_ast::{Identifier, InputValue, Parameter}; -use leo_errors::{new_backtrace, AsgError, Result}; +use leo_errors::{AsgError, Result}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -43,9 +43,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { }; let declared_type = self.asg.scope.resolve_ast_type(¶meter.type_, ¶meter.span)?; if !expected_type.is_assignable_from(&declared_type) { - return Err( - AsgError::unexpected_type(expected_type, declared_type, &identifier.span, new_backtrace()).into(), - ); + return Err(AsgError::unexpected_type(expected_type, declared_type, &identifier.span).into()); } let member_name = parameter.variable.clone(); let member_value = self.allocate_main_function_input( diff --git a/compiler/src/function/input/main_function_input.rs b/compiler/src/function/input/main_function_input.rs index d77e7eb148..72050fb856 100644 --- a/compiler/src/function/input/main_function_input.rs +++ b/compiler/src/function/input/main_function_input.rs @@ -33,7 +33,7 @@ use crate::{ }; use leo_asg::{ConstInt, Type}; use leo_ast::{Char, InputValue}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::boolean::Boolean; @@ -78,8 +78,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { input_option: Option, span: &Span, ) -> Result> { - let input = - input_option.ok_or_else(|| CompilerError::function_input_not_found("main", name, span, new_backtrace()))?; + let input = input_option.ok_or_else(|| CompilerError::function_input_not_found("main", name, span))?; match (type_, input) { (Type::Address, InputValue::Address(addr)) => Ok(ConstrainedValue::Address(Address::constant(addr, span)?)), @@ -109,25 +108,15 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let parsed_type = parsed.get_int_type(); let input_type = input_type.into(); if std::mem::discriminant(&parsed_type) != std::mem::discriminant(&input_type) { - return Err(CompilerError::integer_value_integer_type_mismatch( - input_type, - parsed_type, - span, - new_backtrace(), - ) - .into()); + return Err( + CompilerError::integer_value_integer_type_mismatch(input_type, parsed_type, span).into(), + ); } Ok(ConstrainedValue::Integer(Integer::new(&parsed))) } (Type::Array(type_, arr_len), InputValue::Array(values)) => { if *arr_len != values.len() { - return Err(CompilerError::invalid_input_array_dimensions( - *arr_len, - values.len(), - span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::invalid_input_array_dimensions(*arr_len, values.len(), span).into()); } Ok(ConstrainedValue::Array( @@ -139,13 +128,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } (Type::Tuple(types), InputValue::Tuple(values)) => { if values.len() != types.len() { - return Err(CompilerError::input_tuple_size_mismatch( - types.len(), - values.len(), - span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::input_tuple_size_mismatch(types.len(), values.len(), span).into()); } Ok(ConstrainedValue::Tuple( @@ -161,9 +144,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { (Type::Circuit(_), _) => unimplemented!("main function input not implemented for type {}", type_), // Should not happen. // Return an error if the input type and input value do not match. - (_, input) => { - Err(CompilerError::input_variable_type_mismatch(type_, input, name, span, new_backtrace()).into()) - } + (_, input) => Err(CompilerError::input_variable_type_mismatch(type_, input, name, span).into()), } } } diff --git a/compiler/src/function/input/tuple.rs b/compiler/src/function/input/tuple.rs index 7fcaabdd21..8bd4b8e220 100644 --- a/compiler/src/function/input/tuple.rs +++ b/compiler/src/function/input/tuple.rs @@ -20,7 +20,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Type; use leo_ast::InputValue; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -39,13 +39,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { match input_value { Some(InputValue::Tuple(values)) => { if values.len() != types.len() { - return Err(CompilerError::input_tuple_size_mismatch( - types.len(), - values.len(), - span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::input_tuple_size_mismatch(types.len(), values.len(), span).into()); } // Allocate each value in the tuple. @@ -64,9 +58,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } } _ => { - return Err( - CompilerError::invalid_function_input_tuple(input_value.unwrap(), span, new_backtrace()).into(), - ); + return Err(CompilerError::invalid_function_input_tuple(input_value.unwrap(), span).into()); } } diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index 3792754f94..7aefd335ff 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -20,7 +20,7 @@ use crate::{program::ConstrainedProgram, GroupType, Output}; use leo_asg::{Expression, Function, FunctionQualifier}; use leo_ast::Input; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use std::cell::Cell; use snarkvm_fields::PrimeField; @@ -66,12 +66,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { ) { // If variable is in both [main] and [constants] sections - error. (_, Some(_), Some(_)) => { - return Err(CompilerError::double_input_declaration( - name, - &input_variable.name.span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::double_input_declaration(name, &input_variable.name.span).into()); } // If input option is found in [main] section and input is not const. (false, Some(input_option), _) => self.allocate_main_function_input( @@ -91,21 +86,15 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { )?, // Function argument is const, input is not. (true, Some(_), None) => { - return Err(CompilerError::expected_const_input_variable( - name, - &input_variable.name.span, - new_backtrace(), - ) - .into()); + return Err( + CompilerError::expected_const_input_variable(name, &input_variable.name.span).into(), + ); } // Input is const, function argument is not. (false, None, Some(_)) => { - return Err(CompilerError::expected_non_const_input_variable( - name, - &input_variable.name.span, - new_backtrace(), - ) - .into()); + return Err( + CompilerError::expected_non_const_input_variable(name, &input_variable.name.span).into(), + ); } // When not found - Error out. (_, _, _) => { @@ -113,7 +102,6 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { function.name.borrow().name.to_string(), name, &input_variable.name.span, - new_backtrace(), ) .into()); } diff --git a/compiler/src/function/result/result.rs b/compiler/src/function/result/result.rs index 8779684ba1..6bd779fa95 100644 --- a/compiler/src/function/result/result.rs +++ b/compiler/src/function/result/result.rs @@ -19,7 +19,7 @@ use crate::{get_indicator_value, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Type; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::{boolean::Boolean, traits::select::CondSelectGadget}; @@ -55,7 +55,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if get_indicator_value(&indicator) { // Error if we already have a return value. if return_value.is_some() { - return Err(CompilerError::statement_multiple_returns(span, new_backtrace()).into()); + return Err(CompilerError::statement_multiple_returns(span).into()); } else { // Set the function return value. return_value = Some(result); @@ -79,7 +79,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { &result, value, ) - .map_err(|_| CompilerError::statement_select_fail(result, value, span, new_backtrace()))?, + .map_err(|_| CompilerError::statement_select_fail(result, value, span))?, ); } else { return_value = Some(result); // we ignore indicator for default -- questionable @@ -89,9 +89,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if expected_return.is_unit() { Ok(ConstrainedValue::Tuple(vec![])) } else { - Ok(return_value.ok_or_else(|| { - CompilerError::statement_no_returns(expected_return.to_string(), span, new_backtrace()) - })?) + Ok(return_value.ok_or_else(|| CompilerError::statement_no_returns(expected_return.to_string(), span))?) } } } diff --git a/compiler/src/output/mod.rs b/compiler/src/output/mod.rs index 60871c5955..e56173a8a2 100644 --- a/compiler/src/output/mod.rs +++ b/compiler/src/output/mod.rs @@ -25,7 +25,7 @@ pub use self::output_bytes::*; use crate::{Char, CharType, ConstrainedValue, GroupType, REGISTERS_VARIABLE_NAME}; use leo_asg::Program; use leo_ast::{Parameter, Registers}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; @@ -106,7 +106,7 @@ impl Output { // Return an error if we do not have enough return registers if register_values.len() < return_values.len() { - return Err(CompilerError::output_not_enough_registers(span, new_backtrace()).into()); + return Err(CompilerError::output_not_enough_registers(span).into()); } let mut registers = BTreeMap::new(); @@ -119,13 +119,7 @@ impl Output { let return_value_type = value.to_type(span)?; if !register_type.is_assignable_from(&return_value_type) { - return Err(CompilerError::output_mismatched_types( - register_type, - return_value_type, - span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::output_mismatched_types(register_type, return_value_type, span).into()); } let value = match value { diff --git a/compiler/src/output/output_bytes.rs b/compiler/src/output/output_bytes.rs index 452eece86e..7ca118a3f3 100644 --- a/compiler/src/output/output_bytes.rs +++ b/compiler/src/output/output_bytes.rs @@ -17,7 +17,7 @@ use crate::{ConstrainedValue, GroupType, REGISTERS_VARIABLE_NAME}; use leo_asg::Program; use leo_ast::{Parameter, Registers}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; @@ -55,7 +55,7 @@ impl OutputBytes { // Return an error if we do not have enough return registers if register_values.len() < return_values.len() { - return Err(CompilerError::output_not_enough_registers(span, new_backtrace()).into()); + return Err(CompilerError::output_not_enough_registers(span).into()); } // Manually construct result string @@ -73,13 +73,7 @@ impl OutputBytes { let return_value_type = value.to_type(span)?; if !register_type.is_assignable_from(&return_value_type) { - return Err(CompilerError::output_mismatched_types( - register_type, - return_value_type, - span, - new_backtrace(), - ) - .into()); + return Err(CompilerError::output_mismatched_types(register_type, return_value_type, span).into()); } let value = value.to_string(); diff --git a/compiler/src/output/output_file.rs b/compiler/src/output/output_file.rs index 76cd9f5f20..d0c3229bf4 100644 --- a/compiler/src/output/output_file.rs +++ b/compiler/src/output/output_file.rs @@ -16,7 +16,7 @@ //! The `program.out` file. -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use std::{ borrow::Cow, @@ -46,11 +46,11 @@ impl OutputFile { pub fn write(&self, path: &Path, bytes: &[u8]) -> Result<()> { // create output file let path = self.setup_file_path(path); - let mut file = File::create(&path).map_err(|e| CompilerError::output_file_io_error(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| CompilerError::output_file_io_error(e))?; Ok(file .write_all(bytes) - .map_err(|e| CompilerError::output_file_io_error(e, new_backtrace()))?) + .map_err(|e| CompilerError::output_file_io_error(e))?) } /// Removes the output file at the given path if it exists. Returns `true` on success, @@ -61,7 +61,7 @@ impl OutputFile { return Ok(false); } - fs::remove_file(&path).map_err(|_| CompilerError::output_file_cannot_remove(path, new_backtrace()))?; + fs::remove_file(&path).map_err(|_| CompilerError::output_file_cannot_remove(path))?; Ok(true) } diff --git a/compiler/src/phases/reducing_director.rs b/compiler/src/phases/reducing_director.rs index faad243de0..c7082c7f72 100644 --- a/compiler/src/phases/reducing_director.rs +++ b/compiler/src/phases/reducing_director.rs @@ -97,7 +97,7 @@ use leo_ast::{ UnaryExpression as AstUnaryExpression, ValueExpression, }; -use leo_errors::{new_backtrace, AstError, Result, Span}; +use leo_errors::{AstError, Result, Span}; use tendril::StrTendril; pub trait CombinerOptions { @@ -542,7 +542,7 @@ impl CombineAstAsgDirector { if let AsgStatement::Block(asg_block) = asg.result.get() { block = self.reduce_block(&ast.block, asg_block)?; } else { - return Err(AstError::asg_statement_not_block(asg.span.as_ref().unwrap(), new_backtrace()).into()); + return Err(AstError::asg_statement_not_block(asg.span.as_ref().unwrap()).into()); } let next = match (ast.next.as_ref(), asg.next.get()) { (Some(ast_next), Some(asg_next)) => Some(self.reduce_statement(ast_next, asg_next)?), @@ -580,9 +580,7 @@ impl CombineAstAsgDirector { AstConsoleFunction::Error(_) => AstConsoleFunction::Error(args), AstConsoleFunction::Log(_) => AstConsoleFunction::Log(args), _ => { - return Err( - AstError::impossible_console_assert_call(&ast_console_args.span, new_backtrace()).into(), - ); + return Err(AstError::impossible_console_assert_call(&ast_console_args.span).into()); } } } @@ -650,7 +648,7 @@ impl CombineAstAsgDirector { if let AsgStatement::Block(asg_block) = asg.body.get() { block = self.reduce_block(&ast.block, asg_block)?; } else { - return Err(AstError::asg_statement_not_block(asg.span.as_ref().unwrap(), new_backtrace()).into()); + return Err(AstError::asg_statement_not_block(asg.span.as_ref().unwrap()).into()); } self.ast_reducer diff --git a/compiler/src/prelude/blake2s.rs b/compiler/src/prelude/blake2s.rs index 378f2a19e2..be2be97514 100644 --- a/compiler/src/prelude/blake2s.rs +++ b/compiler/src/prelude/blake2s.rs @@ -17,7 +17,7 @@ use super::CoreCircuit; use crate::{ConstrainedValue, GroupType, Integer}; use leo_asg::Function; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::{ @@ -62,15 +62,13 @@ impl<'a, F: PrimeField, G: GroupType> CoreCircuit<'a, F, G> for Blake2s { let input = unwrap_argument(arguments.remove(1)); let seed = unwrap_argument(arguments.remove(0)); - let digest = - Blake2sGadget::check_evaluation_gadget(cs.ns(|| "blake2s hash"), &seed[..], &input[..]).map_err(|e| { - CompilerError::cannot_enforce_expression("Blake2s check evaluation gadget", e, span, new_backtrace()) - })?; + let digest = Blake2sGadget::check_evaluation_gadget(cs.ns(|| "blake2s hash"), &seed[..], &input[..]) + .map_err(|e| CompilerError::cannot_enforce_expression("Blake2s check evaluation gadget", e, span))?; Ok(ConstrainedValue::Array( digest .to_bytes(cs) - .map_err(|e| CompilerError::cannot_enforce_expression("Vec ToBytes", e, span, new_backtrace()))? + .map_err(|e| CompilerError::cannot_enforce_expression("Vec ToBytes", e, span))? .into_iter() .map(Integer::U8) .map(ConstrainedValue::Integer) diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index 5ee60a3ad1..8fbf0af1e8 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -18,7 +18,7 @@ use crate::{arithmetic::*, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::{AssignOperation, AssignStatement}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::{boolean::Boolean, traits::select::CondSelectGadget}; @@ -59,7 +59,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { _ => unimplemented!("unimplemented assign operator"), }; let selected_value = ConstrainedValue::conditionally_select(cs.ns(|| scope), condition, &new_value, target) - .map_err(|_| CompilerError::statement_select_fail(new_value, target.clone(), span, new_backtrace()))?; + .map_err(|_| CompilerError::statement_select_fail(new_value, target.clone(), span))?; *target = selected_value; Ok(()) diff --git a/compiler/src/statement/assign/assignee/array_index.rs b/compiler/src/statement/assign/assignee/array_index.rs index c3532dba3a..a08064e7d3 100644 --- a/compiler/src/statement/assign/assignee/array_index.rs +++ b/compiler/src/statement/assign/assignee/array_index.rs @@ -20,7 +20,7 @@ use std::convert::TryInto; use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType, Integer}; use leo_asg::{ConstInt, Expression, Node}; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::{eq::EvaluateEqGadget, select::CondSelectGadget}; @@ -43,13 +43,10 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { ConstrainedValue::Array(input) => { if let Some(index) = index_resolved.to_usize() { if index >= input.len() { - Err(CompilerError::statement_array_assign_index_bounds( - index, - input.len(), - &context.span, - new_backtrace(), + Err( + CompilerError::statement_array_assign_index_bounds(index, input.len(), &context.span) + .into(), ) - .into()) } else { let target = input.get_mut(index).unwrap(); if context.remaining_accesses.is_empty() { @@ -65,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let array_len: u32 = input .len() .try_into() - .map_err(|_| CompilerError::array_length_out_of_bounds(&span, new_backtrace()))?; + .map_err(|_| CompilerError::array_length_out_of_bounds(&span))?; self.array_bounds_check(cs, &index_resolved, array_len, &span)?; } @@ -78,11 +75,11 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let index_bounded = i .try_into() - .map_err(|_| CompilerError::array_index_out_of_legal_bounds(&span, new_backtrace()))?; + .map_err(|_| CompilerError::array_index_out_of_legal_bounds(&span))?; let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type()); let index_comparison = index_resolved .evaluate_equal(eq_namespace, &Integer::new(&const_index)) - .map_err(|_| CompilerError::cannot_evaluate_expression("==", &span, new_backtrace()))?; + .map_err(|_| CompilerError::cannot_evaluate_expression("==", &span))?; let mut unique_namespace = cs.ns(|| { format!( @@ -115,32 +112,21 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { &temp_item, item, ) - .map_err(|e| { - CompilerError::cannot_enforce_expression( - "conditional select", - e, - &span, - new_backtrace(), - ) - })?; + .map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, &span))?; *item = value; } Ok(()) } } - _ => Err(CompilerError::statement_array_assign_interior_index(&context.span, new_backtrace()).into()), + _ => Err(CompilerError::statement_array_assign_interior_index(&context.span).into()), } } else if context.from_range && input_len != 0 { context.from_range = false; if let Some(index) = index_resolved.to_usize() { if index >= input_len { - return Err(CompilerError::statement_array_assign_index_bounds( - index, - input_len, - &context.span, - new_backtrace(), - ) - .into()); + return Err( + CompilerError::statement_array_assign_index_bounds(index, input_len, &context.span).into(), + ); } let target = context.input.remove(index); @@ -158,7 +144,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { .input .len() .try_into() - .map_err(|_| CompilerError::array_length_out_of_bounds(&span, new_backtrace()))?; + .map_err(|_| CompilerError::array_length_out_of_bounds(&span))?; self.array_bounds_check(cs, &index_resolved, array_len, &span)?; } @@ -171,11 +157,11 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let index_bounded = i .try_into() - .map_err(|_| CompilerError::array_index_out_of_legal_bounds(&span, new_backtrace()))?; + .map_err(|_| CompilerError::array_index_out_of_legal_bounds(&span))?; let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type()); let index_comparison = index_resolved .evaluate_equal(eq_namespace, &Integer::new(&const_index)) - .map_err(|_| CompilerError::cannot_evaluate_expression("==", &span, new_backtrace()))?; + .map_err(|_| CompilerError::cannot_evaluate_expression("==", &span))?; let mut unique_namespace = cs.ns(|| { format!( @@ -204,15 +190,13 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { }; let value = ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &temp_item, item) - .map_err(|e| { - CompilerError::cannot_enforce_expression("conditional select", e, &span, new_backtrace()) - })?; + .map_err(|e| CompilerError::cannot_enforce_expression("conditional select", e, &span))?; **item = value; } Ok(()) } } else { - Err(CompilerError::statement_array_assign_interior_index(&context.span, new_backtrace()).into()) + Err(CompilerError::statement_array_assign_interior_index(&context.span).into()) } } } diff --git a/compiler/src/statement/assign/assignee/array_range_index.rs b/compiler/src/statement/assign/assignee/array_range_index.rs index 66f7c833b4..aa5234d707 100644 --- a/compiler/src/statement/assign/assignee/array_range_index.rs +++ b/compiler/src/statement/assign/assignee/array_range_index.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Expression; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -38,7 +38,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { .transpose()? .map(|x| { x.to_usize() - .ok_or_else(|| CompilerError::statement_array_assign_index_const(&context.span, new_backtrace())) + .ok_or_else(|| CompilerError::statement_array_assign_index_const(&context.span)) }) .transpose()?; let stop_index = stop @@ -46,7 +46,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { .transpose()? .map(|x| { x.to_usize() - .ok_or_else(|| CompilerError::statement_array_assign_index_const(&context.span, new_backtrace())) + .ok_or_else(|| CompilerError::statement_array_assign_index_const(&context.span)) }) .transpose()?; let start_index = start_index.unwrap_or(0); @@ -75,7 +75,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } Ok(()) } - _ => Err(CompilerError::statement_array_assign_index(&context.span, new_backtrace()).into()), + _ => Err(CompilerError::statement_array_assign_index(&context.span).into()), } } else { // range of a range diff --git a/compiler/src/statement/assign/assignee/member.rs b/compiler/src/statement/assign/assignee/member.rs index 7f73029a31..ac4fef1bcf 100644 --- a/compiler/src/statement/assign/assignee/member.rs +++ b/compiler/src/statement/assign/assignee/member.rs @@ -16,7 +16,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Identifier; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -31,7 +31,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { name: &Identifier, ) -> Result<()> { if context.input.len() != 1 { - return Err(CompilerError::statement_array_assign_interior_index(&context.span, new_backtrace()).into()); + return Err(CompilerError::statement_array_assign_interior_index(&context.span).into()); } match context.input.remove(0) { ConstrainedValue::CircuitExpression(_variable, members) => { @@ -45,15 +45,12 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } None => { // Throw an error if the circuit variable does not exist in the circuit - Err( - CompilerError::statement_undefined_circuit_variable(name, &context.span, new_backtrace()) - .into(), - ) + Err(CompilerError::statement_undefined_circuit_variable(name, &context.span).into()) } } } // Throw an error if the circuit definition does not exist in the file - x => Err(CompilerError::undefined_circuit(x, &context.span, new_backtrace()).into()), + x => Err(CompilerError::undefined_circuit(x, &context.span).into()), } } } diff --git a/compiler/src/statement/assign/assignee/mod.rs b/compiler/src/statement/assign/assignee/mod.rs index ade94837d5..d35280892c 100644 --- a/compiler/src/statement/assign/assignee/mod.rs +++ b/compiler/src/statement/assign/assignee/mod.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::{AssignAccess, AssignOperation, AssignStatement}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::boolean::Boolean; @@ -111,14 +111,11 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub(crate) fn check_range_index(start_index: usize, stop_index: usize, len: usize, span: &Span) -> Result<()> { if stop_index < start_index { - Err( - CompilerError::statement_array_assign_range_order(start_index, stop_index, len, span, new_backtrace()) - .into(), - ) + Err(CompilerError::statement_array_assign_range_order(start_index, stop_index, len, span).into()) } else if start_index > len { - Err(CompilerError::statement_array_assign_index_bounds(start_index, len, span, new_backtrace()).into()) + Err(CompilerError::statement_array_assign_index_bounds(start_index, len, span).into()) } else if stop_index > len { - Err(CompilerError::statement_array_assign_index_bounds(stop_index, len, span, new_backtrace()).into()) + Err(CompilerError::statement_array_assign_index_bounds(stop_index, len, span).into()) } else { Ok(()) } diff --git a/compiler/src/statement/assign/assignee/tuple.rs b/compiler/src/statement/assign/assignee/tuple.rs index 2a56d9122c..7cf32c1edd 100644 --- a/compiler/src/statement/assign/assignee/tuple.rs +++ b/compiler/src/statement/assign/assignee/tuple.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -30,24 +30,18 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { index: usize, ) -> Result<()> { if context.input.len() != 1 { - return Err(CompilerError::statement_array_assign_interior_index(&context.span, new_backtrace()).into()); + return Err(CompilerError::statement_array_assign_interior_index(&context.span).into()); } match context.input.remove(0) { ConstrainedValue::Tuple(old) => { if index > old.len() { - Err(CompilerError::statement_tuple_assign_index_bounds( - index, - old.len(), - &context.span, - new_backtrace(), - ) - .into()) + Err(CompilerError::statement_tuple_assign_index_bounds(index, old.len(), &context.span).into()) } else { context.input = vec![&mut old[index]]; self.resolve_target_access(cs, context) } } - _ => Err(CompilerError::statement_tuple_assign_index(&context.span, new_backtrace()).into()), + _ => Err(CompilerError::statement_tuple_assign_index(&context.span).into()), } } } diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index de04f77092..c37a4a336d 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -24,7 +24,7 @@ use crate::{ StatementResult, }; use leo_asg::ConditionalStatement; -use leo_errors::{new_backtrace, CompilerError}; +use leo_errors::CompilerError; use snarkvm_fields::PrimeField; use snarkvm_gadgets::boolean::Boolean; @@ -60,7 +60,6 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { return Err(CompilerError::conditional_boolean_expression_fails_to_resolve_to_bool( value.to_string(), &span, - new_backtrace(), ) .into()); } @@ -78,7 +77,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { outer_indicator, &inner_indicator, ) - .map_err(|_| CompilerError::statement_indicator_calculation(branch_1_name, &span, new_backtrace()))?; + .map_err(|_| CompilerError::statement_indicator_calculation(branch_1_name, &span))?; let mut results = vec![]; @@ -99,7 +98,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { outer_indicator, &inner_indicator, ) - .map_err(|_| CompilerError::statement_indicator_calculation(branch_2_name, &span, new_backtrace()))?; + .map_err(|_| CompilerError::statement_indicator_calculation(branch_2_name, &span))?; // Evaluate branch 2 let mut branch_2_result = match statement.next.get() { diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 369ed7374d..586ff67e42 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, ConstrainedValue, GroupType}; use leo_asg::{DefinitionStatement, Variable}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; @@ -35,7 +35,6 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { values.len(), variable_names.len(), span, - new_backtrace(), ) .into()); } @@ -67,7 +66,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { // ConstrainedValue::Return(values) => values, ConstrainedValue::Tuple(values) => values, value => { - return Err(CompilerError::statement_multiple_definition(value, &span, new_backtrace()).into()); + return Err(CompilerError::statement_multiple_definition(value, &span).into()); } }; diff --git a/compiler/src/statement/iteration/iteration.rs b/compiler/src/statement/iteration/iteration.rs index 229a2962bc..801811e4be 100644 --- a/compiler/src/statement/iteration/iteration.rs +++ b/compiler/src/statement/iteration/iteration.rs @@ -26,7 +26,7 @@ use crate::{ StatementResult, }; use leo_asg::IterationStatement; -use leo_errors::{new_backtrace, CompilerError}; +use leo_errors::CompilerError; use snarkvm_fields::PrimeField; use snarkvm_gadgets::{boolean::Boolean, integers::uint::UInt32}; @@ -47,11 +47,11 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let from = self .enforce_index(cs, statement.start.get(), &span)? .to_usize() - .ok_or_else(|| CompilerError::statement_loop_index_const(&span, new_backtrace()))?; + .ok_or_else(|| CompilerError::statement_loop_index_const(&span))?; let to = self .enforce_index(cs, statement.stop.get(), &span)? .to_usize() - .ok_or_else(|| CompilerError::statement_loop_index_const(&span, new_backtrace()))?; + .ok_or_else(|| CompilerError::statement_loop_index_const(&span))?; let iter: Box> = match (from < to, statement.inclusive) { (true, true) => Box::new(from..=to), diff --git a/compiler/src/statement/statement.rs b/compiler/src/statement/statement.rs index 970600ad62..81bc267226 100644 --- a/compiler/src/statement/statement.rs +++ b/compiler/src/statement/statement.rs @@ -18,7 +18,7 @@ use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::{Node, Statement}; -use leo_errors::{new_backtrace, CompilerError, Result}; +use leo_errors::{CompilerError, Result}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::boolean::Boolean; @@ -82,11 +82,9 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } } _ => { - return Err(CompilerError::statement_unassigned( - &statement.span.clone().unwrap_or_default(), - new_backtrace(), - ) - .into()); + return Err( + CompilerError::statement_unassigned(&statement.span.clone().unwrap_or_default()).into(), + ); } } } diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index 9d6bfc1d17..4c59110e40 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -16,7 +16,7 @@ use crate::{ConstrainedValue, GroupType, IntegerTrait}; use leo_ast::InputValue; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_dpc::{account::Address as AleoAddress, testnet1::instantiated::Components}; use snarkvm_fields::PrimeField; @@ -42,8 +42,8 @@ pub struct Address { impl Address { pub(crate) fn constant(address: String, span: &Span) -> Result { - let address = AleoAddress::from_str(&address) - .map_err(|e| CompilerError::address_value_account_error(e, span, new_backtrace()))?; + let address = + AleoAddress::from_str(&address).map_err(|e| CompilerError::address_value_account_error(e, span))?; let mut address_bytes = vec![]; address.write_le(&mut address_bytes).unwrap(); @@ -72,7 +72,7 @@ impl Address { if let InputValue::Address(string) = input { Some(string) } else { - return Err(CompilerError::address_value_invalid_address(name, span, new_backtrace()).into()); + return Err(CompilerError::address_value_invalid_address(name, span).into()); } } None => None, @@ -82,7 +82,7 @@ impl Address { cs.ns(|| format!("`{}: address` {}:{}", name, span.line_start, span.col_start)), || address_value.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| CompilerError::address_value_missing_address(span, new_backtrace()))?; + .map_err(|_| CompilerError::address_value_missing_address(span))?; Ok(ConstrainedValue::Address(address)) } diff --git a/compiler/src/value/boolean/input.rs b/compiler/src/value/boolean/input.rs index cc20523092..bcba6e7616 100644 --- a/compiler/src/value/boolean/input.rs +++ b/compiler/src/value/boolean/input.rs @@ -18,7 +18,7 @@ use crate::{value::ConstrainedValue, GroupType}; use leo_ast::InputValue; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::{boolean::Boolean, traits::alloc::AllocGadget}; @@ -34,7 +34,7 @@ pub(crate) fn allocate_bool>( cs.ns(|| format!("`{}: bool` {}:{}", name, span.line_start, span.col_start)), || option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| CompilerError::boolean_value_missing_boolean(format!("{}: bool", name), span, new_backtrace()))?) + .map_err(|_| CompilerError::boolean_value_missing_boolean(format!("{}: bool", name), span))?) } pub(crate) fn bool_from_input<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( @@ -49,7 +49,7 @@ pub(crate) fn bool_from_input<'a, F: PrimeField, G: GroupType, CS: Constraint if let InputValue::Boolean(bool) = input { Some(bool) } else { - return Err(CompilerError::boolean_value_invalid_boolean(name, span, new_backtrace()).into()); + return Err(CompilerError::boolean_value_invalid_boolean(name, span).into()); } } None => None, diff --git a/compiler/src/value/char/char.rs b/compiler/src/value/char/char.rs index 65bf190ff7..25668bb8f7 100644 --- a/compiler/src/value/char/char.rs +++ b/compiler/src/value/char/char.rs @@ -21,7 +21,7 @@ use crate::{ }; use leo_ast::InputValue; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::{ @@ -155,7 +155,7 @@ pub(crate) fn char_from_input<'a, F: PrimeField, G: GroupType, CS: Constraint } } } else { - return Err(CompilerError::char_value_invalid_char(input, span, new_backtrace()).into()); + return Err(CompilerError::char_value_invalid_char(input, span).into()); } } None => (CharType::Scalar(0 as char), None), diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index 6008f1a13f..0dbef30991 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -17,7 +17,7 @@ //! A data type that represents a field value use crate::number_string_typing; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::{ @@ -50,14 +50,16 @@ impl FieldType { let number_info = number_string_typing(&string); let value = match number_info { - (number, neg) if neg => -F::from_str(&number) - .map_err(|_| CompilerError::field_value_invalid_field(string.clone(), span, new_backtrace()))?, - (number, _) => F::from_str(&number) - .map_err(|_| CompilerError::field_value_invalid_field(string.clone(), span, new_backtrace()))?, + (number, neg) if neg => { + -F::from_str(&number).map_err(|_| CompilerError::field_value_invalid_field(string.clone(), span))? + } + (number, _) => { + F::from_str(&number).map_err(|_| CompilerError::field_value_invalid_field(string.clone(), span))? + } }; let value = FpGadget::alloc_constant(cs, || Ok(value)) - .map_err(|_| CompilerError::field_value_invalid_field(string, span, new_backtrace()))?; + .map_err(|_| CompilerError::field_value_invalid_field(string, span))?; Ok(FieldType(value)) } @@ -67,7 +69,7 @@ impl FieldType { let result = self .0 .negate(cs) - .map_err(|e| CompilerError::field_value_negate_operation(e, span, new_backtrace()))?; + .map_err(|e| CompilerError::field_value_negate_operation(e, span))?; Ok(FieldType(result)) } @@ -77,7 +79,7 @@ impl FieldType { let value = self .0 .add(cs, &other.0) - .map_err(|e| CompilerError::field_value_binary_operation("+", e, span, new_backtrace()))?; + .map_err(|e| CompilerError::field_value_binary_operation("+", e, span))?; Ok(FieldType(value)) } @@ -87,7 +89,7 @@ impl FieldType { let value = self .0 .sub(cs, &other.0) - .map_err(|e| CompilerError::field_value_binary_operation("-", e, span, new_backtrace()))?; + .map_err(|e| CompilerError::field_value_binary_operation("-", e, span))?; Ok(FieldType(value)) } @@ -97,7 +99,7 @@ impl FieldType { let value = self .0 .mul(cs, &other.0) - .map_err(|e| CompilerError::field_value_binary_operation("*", e, span, new_backtrace()))?; + .map_err(|e| CompilerError::field_value_binary_operation("*", e, span))?; Ok(FieldType(value)) } @@ -107,7 +109,7 @@ impl FieldType { let value = self .0 .inverse(cs) - .map_err(|e| CompilerError::field_value_binary_operation("inv", e, span, new_backtrace()))?; + .map_err(|e| CompilerError::field_value_binary_operation("inv", e, span))?; Ok(FieldType(value)) } diff --git a/compiler/src/value/field/input.rs b/compiler/src/value/field/input.rs index eb3dceb5a1..350b659f71 100644 --- a/compiler/src/value/field/input.rs +++ b/compiler/src/value/field/input.rs @@ -18,7 +18,7 @@ use crate::{number_string_typing, value::ConstrainedValue, FieldType, GroupType}; use leo_ast::InputValue; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::alloc::AllocGadget; @@ -40,22 +40,16 @@ pub(crate) fn allocate_field>( || Some(number).ok_or(SynthesisError::AssignmentMissing), ) .map(|value| value.negate(cs, span)) - .map_err(|_| { - CompilerError::field_value_missing_field(format!("{}: field", name), span, new_backtrace()) - })?, + .map_err(|_| CompilerError::field_value_missing_field(format!("{}: field", name), span))?, (number, _) => Ok(FieldType::alloc( cs.ns(|| format!("`{}: field` {}:{}", name, span.line_start, span.col_start)), || Some(number).ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| { - CompilerError::field_value_missing_field(format!("{}: field", name), span, new_backtrace()) - })?), + .map_err(|_| CompilerError::field_value_missing_field(format!("{}: field", name), span))?), } } None => { - return Err( - CompilerError::field_value_missing_field(format!("{}: field", name), span, new_backtrace()).into(), - ); + return Err(CompilerError::field_value_missing_field(format!("{}: field", name), span).into()); } } } @@ -72,7 +66,7 @@ pub(crate) fn field_from_input<'a, F: PrimeField, G: GroupType, CS: Constrain if let InputValue::Field(string) = input { Some(string) } else { - return Err(CompilerError::field_value_invalid_field(input, span, new_backtrace()).into()); + return Err(CompilerError::field_value_invalid_field(input, span).into()); } } None => None, diff --git a/compiler/src/value/group/input.rs b/compiler/src/value/group/input.rs index 77181ac26e..839db2b52d 100644 --- a/compiler/src/value/group/input.rs +++ b/compiler/src/value/group/input.rs @@ -19,7 +19,7 @@ use crate::{ConstrainedValue, GroupType}; use leo_asg::GroupValue; use leo_ast::InputValue; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; @@ -34,7 +34,7 @@ pub(crate) fn allocate_group, CS: ConstraintSyste cs.ns(|| format!("`{}: group` {}:{}", name, span.line_start, span.col_start)), || option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| CompilerError::group_value_missing_group(format!("{}: group", name), span, new_backtrace()))?) + .map_err(|_| CompilerError::group_value_missing_group(format!("{}: group", name), span))?) } pub(crate) fn group_from_input<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( @@ -49,7 +49,7 @@ pub(crate) fn group_from_input<'a, F: PrimeField, G: GroupType, CS: Constrain if let InputValue::Group(string) = input { Some(string) } else { - return Err(CompilerError::group_value_missing_group(input, span, new_backtrace()).into()); + return Err(CompilerError::group_value_missing_group(input, span).into()); } } None => None, diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 15107fb394..041332b42b 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -16,7 +16,7 @@ use crate::{number_string_typing, GroupType}; use leo_asg::{GroupCoordinate, GroupValue}; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_curves::{ edwards_bls12::{EdwardsAffine, EdwardsParameters, Fq}, @@ -63,7 +63,7 @@ impl GroupType for EdwardsGroupType { Ok(self .allocated(cs.ns(|| format!("allocate affine point {}:{}", span.line_start, span.col_start))) .map(|ebg| EdwardsGroupType::Allocated(Box::new(ebg))) - .map_err(|e| CompilerError::group_value_synthesis_error(e, span, new_backtrace()))?) + .map_err(|e| CompilerError::group_value_synthesis_error(e, span))?) } fn negate>(&self, cs: CS, span: &Span) -> Result { @@ -71,7 +71,7 @@ impl GroupType for EdwardsGroupType { EdwardsGroupType::Constant(group) => Ok(EdwardsGroupType::Constant(group.neg())), EdwardsGroupType::Allocated(group) => { let result = , Fq>>::negate(group, cs) - .map_err(|e| CompilerError::group_value_negate_operation(e, span, new_backtrace()))?; + .map_err(|e| CompilerError::group_value_negate_operation(e, span))?; Ok(EdwardsGroupType::Allocated(Box::new(result))) } @@ -90,7 +90,7 @@ impl GroupType for EdwardsGroupType { cs, other_value, ) - .map_err(|e| CompilerError::group_value_binary_operation("+", e, span, new_backtrace()))?; + .map_err(|e| CompilerError::group_value_binary_operation("+", e, span))?; Ok(EdwardsGroupType::Allocated(Box::new(result))) } @@ -100,7 +100,7 @@ impl GroupType for EdwardsGroupType { Ok(EdwardsGroupType::Allocated(Box::new( allocated_value .add_constant(cs, constant_value) - .map_err(|e| CompilerError::group_value_binary_operation("+", e, span, new_backtrace()))?, + .map_err(|e| CompilerError::group_value_binary_operation("+", e, span))?, ))) } } @@ -118,7 +118,7 @@ impl GroupType for EdwardsGroupType { cs, other_value, ) - .map_err(|e| CompilerError::group_value_binary_operation("-", e, span, new_backtrace()))?; + .map_err(|e| CompilerError::group_value_binary_operation("-", e, span))?; Ok(EdwardsGroupType::Allocated(Box::new(result))) } @@ -128,7 +128,7 @@ impl GroupType for EdwardsGroupType { Ok(EdwardsGroupType::Allocated(Box::new( allocated_value .sub_constant(cs, constant_value) - .map_err(|e| CompilerError::group_value_binary_operation("-", e, span, new_backtrace()))?, + .map_err(|e| CompilerError::group_value_binary_operation("-", e, span))?, ))) } } @@ -151,10 +151,12 @@ impl EdwardsGroupType { } else { let one = edwards_affine_one(); let number_value = match number_info { - (number, neg) if neg => -Fp256::from_str(&number) - .map_err(|_| CompilerError::group_value_n_group(number, span, new_backtrace()))?, - (number, _) => Fp256::from_str(&number) - .map_err(|_| CompilerError::group_value_n_group(number, span, new_backtrace()))?, + (number, neg) if neg => { + -Fp256::from_str(&number).map_err(|_| CompilerError::group_value_n_group(number, span))? + } + (number, _) => { + Fp256::from_str(&number).map_err(|_| CompilerError::group_value_n_group(number, span))? + } }; let result: EdwardsAffine = one.mul(number_value); @@ -202,9 +204,7 @@ impl EdwardsGroupType { } // Invalid (x, y) => { - return Err( - CompilerError::group_value_invalid_group(format!("({}, {})", x, y), span, new_backtrace()).into(), - ); + return Err(CompilerError::group_value_invalid_group(format!("({}, {})", x, y), span).into()); } } } @@ -216,16 +216,16 @@ impl EdwardsGroupType { element_span: &Span, ) -> Result { let x = match x_info { - (x_str, neg) if neg => -Fq::from_str(&x_str) - .map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span, new_backtrace()))?, - (x_str, _) => Fq::from_str(&x_str) - .map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span, new_backtrace()))?, + (x_str, neg) if neg => { + -Fq::from_str(&x_str).map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span))? + } + (x_str, _) => Fq::from_str(&x_str).map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span))?, }; match greatest { // Sign provided Some(greatest) => Ok(EdwardsAffine::from_x_coordinate(x, greatest) - .ok_or_else(|| CompilerError::group_value_x_recover(element_span, new_backtrace()))?), + .ok_or_else(|| CompilerError::group_value_x_recover(element_span))?), // Sign inferred None => { // Attempt to recover with a sign_low bit. @@ -239,7 +239,7 @@ impl EdwardsGroupType { } // Otherwise return error. - Err(CompilerError::group_value_x_recover(element_span, new_backtrace()).into()) + Err(CompilerError::group_value_x_recover(element_span).into()) } } } @@ -251,16 +251,16 @@ impl EdwardsGroupType { element_span: &Span, ) -> Result { let y = match y_info { - (y_str, neg) if neg => -Fq::from_str(&y_str) - .map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span, new_backtrace()))?, - (y_str, _) => Fq::from_str(&y_str) - .map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span, new_backtrace()))?, + (y_str, neg) if neg => { + -Fq::from_str(&y_str).map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span))? + } + (y_str, _) => Fq::from_str(&y_str).map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span))?, }; match greatest { // Sign provided Some(greatest) => Ok(EdwardsAffine::from_y_coordinate(y, greatest) - .ok_or_else(|| CompilerError::group_value_y_recover(element_span, new_backtrace()))?), + .ok_or_else(|| CompilerError::group_value_y_recover(element_span))?), // Sign inferred None => { // Attempt to recover with a sign_low bit. @@ -274,7 +274,7 @@ impl EdwardsGroupType { } // Otherwise return error. - Err(CompilerError::group_value_y_recover(element_span, new_backtrace()).into()) + Err(CompilerError::group_value_y_recover(element_span).into()) } } } @@ -287,17 +287,17 @@ impl EdwardsGroupType { element_span: &Span, ) -> Result { let x = match x_info { - (x_str, neg) if neg => -Fq::from_str(&x_str) - .map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span, new_backtrace()))?, - (x_str, _) => Fq::from_str(&x_str) - .map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span, new_backtrace()))?, + (x_str, neg) if neg => { + -Fq::from_str(&x_str).map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span))? + } + (x_str, _) => Fq::from_str(&x_str).map_err(|_| CompilerError::group_value_x_invalid(x_str, x_span))?, }; let y = match y_info { - (y_str, neg) if neg => -Fq::from_str(&y_str) - .map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span, new_backtrace()))?, - (y_str, _) => Fq::from_str(&y_str) - .map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span, new_backtrace()))?, + (y_str, neg) if neg => { + -Fq::from_str(&y_str).map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span))? + } + (y_str, _) => Fq::from_str(&y_str).map_err(|_| CompilerError::group_value_y_invalid(y_str, y_span))?, }; let element = EdwardsAffine::new(x, y); @@ -305,7 +305,7 @@ impl EdwardsGroupType { if element.is_on_curve() { Ok(element) } else { - Err(CompilerError::group_value_not_on_curve(element, element_span, new_backtrace()).into()) + Err(CompilerError::group_value_not_on_curve(element, element_span).into()) } } diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index 5f7c276fa4..e379213e21 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -18,7 +18,7 @@ use crate::IntegerTrait; use leo_asg::{ConstInt, IntegerType}; use leo_ast::InputValue; -use leo_errors::{new_backtrace, CompilerError, Result, Span}; +use leo_errors::{CompilerError, Result, Span}; use snarkvm_fields::{Field, PrimeField}; use snarkvm_gadgets::{ @@ -161,17 +161,13 @@ impl Integer { if let InputValue::Integer(type_, number) = input { let asg_type = IntegerType::from(type_); if std::mem::discriminant(&asg_type) != std::mem::discriminant(integer_type) { - return Err(CompilerError::integer_value_integer_type_mismatch( - integer_type, - asg_type, - span, - new_backtrace(), - ) - .into()); + return Err( + CompilerError::integer_value_integer_type_mismatch(integer_type, asg_type, span).into(), + ); } Some(number) } else { - return Err(CompilerError::integer_value_invalid_integer(input, span, new_backtrace()).into()); + return Err(CompilerError::integer_value_invalid_integer(input, span).into()); } } None => None, @@ -187,7 +183,7 @@ impl Integer { let result = match_signed_integer!(a, span => a.neg(cs.ns(|| unique_namespace))); - Ok(result.ok_or_else(|| CompilerError::integer_value_negate_operation(span, new_backtrace()))?) + Ok(result.ok_or_else(|| CompilerError::integer_value_negate_operation(span))?) } pub fn add>(self, cs: &mut CS, other: Self, span: &Span) -> Result { @@ -198,7 +194,7 @@ impl Integer { let result = match_integers_span!((a, b), span => a.add(cs.ns(|| unique_namespace), &b)); - Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("+", span, new_backtrace()))?) + Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("+", span))?) } pub fn sub>(self, cs: &mut CS, other: Self, span: &Span) -> Result { @@ -209,7 +205,7 @@ impl Integer { let result = match_integers_span!((a, b), span => a.sub(cs.ns(|| unique_namespace), &b)); - Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("-", span, new_backtrace()))?) + Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("-", span))?) } pub fn mul>(self, cs: &mut CS, other: Self, span: &Span) -> Result { @@ -220,7 +216,7 @@ impl Integer { let result = match_integers_span!((a, b), span => a.mul(cs.ns(|| unique_namespace), &b)); - Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("*", span, new_backtrace()))?) + Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("*", span))?) } pub fn div>(self, cs: &mut CS, other: Self, span: &Span) -> Result { @@ -231,7 +227,7 @@ impl Integer { let result = match_integers_span!((a, b), span => a.div(cs.ns(|| unique_namespace), &b)); - Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("÷", span, new_backtrace()))?) + Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("÷", span))?) } pub fn pow>(self, cs: &mut CS, other: Self, span: &Span) -> Result { @@ -242,7 +238,7 @@ impl Integer { let result = match_integers_span!((a, b), span => a.pow(cs.ns(|| unique_namespace), &b)); - Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("**", span, new_backtrace()))?) + Ok(result.ok_or_else(|| CompilerError::integer_value_binary_operation("**", span))?) } } diff --git a/compiler/src/value/integer/macros.rs b/compiler/src/value/integer/macros.rs index 9ebf29ccd6..67ae416946 100644 --- a/compiler/src/value/integer/macros.rs +++ b/compiler/src/value/integer/macros.rs @@ -55,31 +55,21 @@ macro_rules! match_unsigned_integer { macro_rules! match_signed_integer { ($integer: ident, $span: ident => $expression: expr) => { match $integer { - Integer::I8($integer) => { - Some(Integer::I8($expression.map_err(|e| { - CompilerError::integer_value_signed(e, $span, new_backtrace()) - })?)) - } - Integer::I16($integer) => { - Some(Integer::I16($expression.map_err(|e| { - CompilerError::integer_value_signed(e, $span, new_backtrace()) - })?)) - } - Integer::I32($integer) => { - Some(Integer::I32($expression.map_err(|e| { - CompilerError::integer_value_signed(e, $span, new_backtrace()) - })?)) - } - Integer::I64($integer) => { - Some(Integer::I64($expression.map_err(|e| { - CompilerError::integer_value_signed(e, $span, new_backtrace()) - })?)) - } - Integer::I128($integer) => { - Some(Integer::I128($expression.map_err(|e| { - CompilerError::integer_value_signed(e, $span, new_backtrace()) - })?)) - } + Integer::I8($integer) => Some(Integer::I8( + $expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?, + )), + Integer::I16($integer) => Some(Integer::I16( + $expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?, + )), + Integer::I32($integer) => Some(Integer::I32( + $expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?, + )), + Integer::I64($integer) => Some(Integer::I64( + $expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?, + )), + Integer::I128($integer) => Some(Integer::I128( + $expression.map_err(|e| CompilerError::integer_value_signed(e, $span))?, + )), _ => None, } @@ -110,57 +100,37 @@ macro_rules! match_integers { macro_rules! match_integers_span { (($a: ident, $b: ident), $span: ident => $expression:expr) => { match ($a, $b) { - (Integer::U8($a), Integer::U8($b)) => { - Some(Integer::U8($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } - (Integer::U16($a), Integer::U16($b)) => { - Some(Integer::U16($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } - (Integer::U32($a), Integer::U32($b)) => { - Some(Integer::U32($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } - (Integer::U64($a), Integer::U64($b)) => { - Some(Integer::U64($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } - (Integer::U128($a), Integer::U128($b)) => { - Some(Integer::U128($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } + (Integer::U8($a), Integer::U8($b)) => Some(Integer::U8( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), + (Integer::U16($a), Integer::U16($b)) => Some(Integer::U16( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), + (Integer::U32($a), Integer::U32($b)) => Some(Integer::U32( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), + (Integer::U64($a), Integer::U64($b)) => Some(Integer::U64( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), + (Integer::U128($a), Integer::U128($b)) => Some(Integer::U128( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), - (Integer::I8($a), Integer::I8($b)) => { - Some(Integer::I8($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } - (Integer::I16($a), Integer::I16($b)) => { - Some(Integer::I16($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } - (Integer::I32($a), Integer::I32($b)) => { - Some(Integer::I32($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } - (Integer::I64($a), Integer::I64($b)) => { - Some(Integer::I64($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } - (Integer::I128($a), Integer::I128($b)) => { - Some(Integer::I128($expression.map_err(|e| { - CompilerError::integer_value_unsigned(e, $span, new_backtrace()) - })?)) - } + (Integer::I8($a), Integer::I8($b)) => Some(Integer::I8( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), + (Integer::I16($a), Integer::I16($b)) => Some(Integer::I16( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), + (Integer::I32($a), Integer::I32($b)) => Some(Integer::I32( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), + (Integer::I64($a), Integer::I64($b)) => Some(Integer::I64( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), + (Integer::I128($a), Integer::I128($b)) => Some(Integer::I128( + $expression.map_err(|e| CompilerError::integer_value_unsigned(e, $span))?, + )), (_, _) => None, } }; @@ -171,7 +141,7 @@ macro_rules! allocate_type { let option = $option .map(|s| { s.parse::<$rust_ty>() - .map_err(|_| CompilerError::integer_value_invalid_integer(s, $span, new_backtrace())) + .map_err(|_| CompilerError::integer_value_invalid_integer(s, $span)) }) .transpose()?; @@ -191,7 +161,6 @@ macro_rules! allocate_type { CompilerError::integer_value_missing_integer( format!("{}: {}", $name.to_string(), stringify!($rust_ty)), $span, - new_backtrace(), ) })?; diff --git a/errors/Cargo.toml b/errors/Cargo.toml index c3d2f3a048..2340f9ee2a 100644 --- a/errors/Cargo.toml +++ b/errors/Cargo.toml @@ -17,6 +17,9 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] license = "GPL-3.0" edition = "2018" +[dependencies] +color-backtrace = "0.5.1" + [dependencies.leo-input] path = "../input" version = "1.5.3" diff --git a/errors/src/asg/asg_errors.rs b/errors/src/asg/asg_errors.rs index 2112faafba..ec726a4ce7 100644 --- a/errors/src/asg/asg_errors.rs +++ b/errors/src/asg/asg_errors.rs @@ -20,7 +20,7 @@ use std::fmt::{Debug, Display}; create_errors!( AsgError, - exit_code_mask: 0u32, + exit_code_mask: 0i32, error_code_prefix: "ASG", @formatted diff --git a/errors/src/ast/ast_errors.rs b/errors/src/ast/ast_errors.rs index ede0122169..7da8866b37 100644 --- a/errors/src/ast/ast_errors.rs +++ b/errors/src/ast/ast_errors.rs @@ -19,7 +19,7 @@ use std::{error::Error as ErrorArg, fmt::Debug}; create_errors!( AstError, - exit_code_mask: 1000u32, + exit_code_mask: 1000i32, error_code_prefix: "AST", @backtraced diff --git a/errors/src/cli/cli_errors.rs b/errors/src/cli/cli_errors.rs index e42937e072..87ecee90d1 100644 --- a/errors/src/cli/cli_errors.rs +++ b/errors/src/cli/cli_errors.rs @@ -22,7 +22,7 @@ use std::{ create_errors!( CliError, - exit_code_mask: 7000u32, + exit_code_mask: 7000i32, error_code_prefix: "CLI", @backtraced @@ -321,20 +321,20 @@ create_errors!( ); impl CliError { - pub fn remove_token_and_username(error: std::io::Error, backtrace: Backtrace) -> Self { + pub fn remove_token_and_username(error: std::io::Error) -> Self { use std::io::ErrorKind; match error.kind() { ErrorKind::NotFound => { // tracing::info!("you are not logged in"); - Self::not_logged_in(backtrace) + Self::not_logged_in() } ErrorKind::PermissionDenied => { // tracing::error!("permission denied - check file permission in .leo folder"); - Self::logout_permision_denied(backtrace) + Self::logout_permision_denied() } _ => { // tracing::error!("something went wrong, can't access the file"); - Self::cannot_access_logout_file(backtrace) + Self::cannot_access_logout_file() } } } diff --git a/errors/src/common/backtraced.rs b/errors/src/common/backtraced.rs index 1ab4c7e2f9..f7ab92b1e9 100644 --- a/errors/src/common/backtraced.rs +++ b/errors/src/common/backtraced.rs @@ -17,6 +17,7 @@ use std::fmt; use backtrace::Backtrace; +use color_backtrace::BacktracePrinter; use derivative::Derivative; pub const INDENT: &str = " "; @@ -34,8 +35,8 @@ pub const INDENT: &str = " "; pub struct BacktracedError { pub message: String, pub help: Option, - pub exit_code: u32, - pub code_identifier: u32, + pub exit_code: i32, + pub code_identifier: i8, pub error_type: String, #[derivative(PartialEq = "ignore")] #[derivative(Hash = "ignore")] @@ -46,8 +47,8 @@ impl BacktracedError { pub fn new_from_backtrace( message: S, help: Option, - exit_code: u32, - code_identifier: u32, + exit_code: i32, + code_identifier: i8, error_type: String, backtrace: Backtrace, ) -> Self @@ -64,8 +65,18 @@ impl BacktracedError { } } - pub fn exit_code(&self) -> u32 { - 0 + pub fn exit_code(&self) -> i32 { + let mut code: i32; + if self.code_identifier > 99 { + code = self.code_identifier as i32 * 111_000; + } else if self.code_identifier as i32 > 9 { + code = self.code_identifier as i32 * 11_000; + } else { + code = self.code_identifier as i32 * 1_000; + } + code += self.exit_code; + + code } } @@ -87,8 +98,29 @@ impl fmt::Display for BacktracedError { write!(f, "{indent } = {help}", indent = INDENT, help = help)?; } - if std::env::var("LEO_BACKTRACE").unwrap_or_default().trim() == "1" { - write!(f, "stack backtrace:\n{:?}", self.backtrace)?; + let leo_backtrace = std::env::var("LEO_BACKTRACE").unwrap_or_default().trim().to_owned(); + match leo_backtrace.as_ref() { + "1" => { + dbg!("1"); + let mut printer = BacktracePrinter::default(); + printer = printer.verbosity(Verbosity::Medium); + printer = printer.lib_verbosity(Verbosity::Medium); + let trace = printer + .format_trace_to_string(&self.backtrace.backtrace) + .map_err(|_| fmt::Error)?; + write!(f, "{}", trace)?; + } + "full" => { + dbg!("full"); + let mut printer = BacktracePrinter::default(); + printer = printer.verbosity(Verbosity::Full); + printer = printer.lib_verbosity(Verbosity::Full); + let trace = printer + .format_trace_to_string(&self.backtrace.backtrace) + .map_err(|_| fmt::Error)?; + write!(f, "{}", trace)?; + } + _ => {} } Ok(()) diff --git a/errors/src/common/formatted.rs b/errors/src/common/formatted.rs index 623b668443..252981e1ff 100644 --- a/errors/src/common/formatted.rs +++ b/errors/src/common/formatted.rs @@ -19,6 +19,7 @@ use crate::{BacktracedError, Span}; use std::{fmt, sync::Arc}; use backtrace::Backtrace; +use color_backtrace::{BacktracePrinter, Verbosity}; pub const INDENT: &str = " "; @@ -45,8 +46,8 @@ impl FormattedError { pub fn new_from_span( message: S, help: Option, - exit_code: u32, - code_identifier: u32, + exit_code: i32, + code_identifier: i8, error_type: String, span: &Span, backtrace: Backtrace, @@ -72,8 +73,8 @@ impl FormattedError { } } - pub fn exit_code(&self) -> u32 { - 0 + pub fn exit_code(&self) -> i32 { + self.backtrace.exit_code() } } @@ -138,8 +139,29 @@ impl fmt::Display for FormattedError { write!(f, "{indent } = {help}", indent = INDENT, help = help)?; } - if std::env::var("LEO_BACKTRACE").unwrap_or_default().trim() == "1" { - write!(f, "stack backtrace:\n{:?}", self.backtrace.backtrace)?; + let leo_backtrace = std::env::var("LEO_BACKTRACE").unwrap_or_default().trim().to_owned(); + match leo_backtrace.as_ref() { + "1" => { + dbg!("1"); + let mut printer = BacktracePrinter::default(); + printer = printer.verbosity(Verbosity::Medium); + printer = printer.lib_verbosity(Verbosity::Medium); + let trace = printer + .format_trace_to_string(&self.backtrace.backtrace) + .map_err(|_| fmt::Error)?; + write!(f, "{}", trace)?; + } + "full" => { + dbg!("full"); + let mut printer = BacktracePrinter::default(); + printer = printer.verbosity(Verbosity::Full); + printer = printer.lib_verbosity(Verbosity::Full); + let trace = printer + .format_trace_to_string(&self.backtrace.backtrace) + .map_err(|_| fmt::Error)?; + write!(f, "{}", trace)?; + } + _ => {} } Ok(()) diff --git a/errors/src/common/macros.rs b/errors/src/common/macros.rs index 9c39eb96a5..c9b7affe27 100644 --- a/errors/src/common/macros.rs +++ b/errors/src/common/macros.rs @@ -18,11 +18,11 @@ macro_rules! create_errors { (@step $_code:expr,) => {}; ($error_type:ident, exit_code_mask: $exit_code_mask:expr, error_code_prefix: $error_code_prefix:expr, $(@$formatted_or_backtraced_list:ident $names:ident { args: ($($arg_names:ident: $arg_types:ty$(,)?)*), msg: $messages:expr, help: $helps:expr, })*) => { + #[allow(unused_imports)] use crate::{BacktracedError, ErrorCode, FormattedError, LeoErrorCode, Span}; use backtrace::Backtrace; - #[derive(Debug, Error)] pub enum $error_type { #[error(transparent)] @@ -36,7 +36,7 @@ macro_rules! create_errors { impl ErrorCode for $error_type { #[inline(always)] - fn exit_code(&self) -> u32 { + fn exit_code(&self) -> i32 { match self { Self::FormattedError(formatted) => { formatted.exit_code() @@ -49,7 +49,7 @@ macro_rules! create_errors { } #[inline(always)] - fn exit_code_mask() -> u32 { + fn exit_code_mask() -> i32 { $exit_code_mask } @@ -57,53 +57,44 @@ macro_rules! create_errors { fn error_type() -> String { $error_code_prefix.to_string() } - - fn new_from_backtrace(message: S, help: Option, exit_code: u32, backtrace: Backtrace) -> Self - where - S: ToString { - BacktracedError::new_from_backtrace( - message, - help, - exit_code + Self::exit_code_mask(), - Self::code_identifier(), - Self::error_type(), - backtrace, - ).into() - } - - fn new_from_span(message: S, help: Option, exit_code: u32, span: &Span, backtrace: Backtrace) -> Self - where S: ToString { - FormattedError::new_from_span( - message, - help, - exit_code + Self::exit_code_mask(), - Self::code_identifier(), - Self::error_type(), - span, - backtrace, - ).into() - } } impl $error_type { - create_errors!(@step 0u32, $(($formatted_or_backtraced_list, $names($($arg_names: $arg_types,)*), $messages, $helps),)*); + create_errors!(@step 0i32, $(($formatted_or_backtraced_list, $names($($arg_names: $arg_types,)*), $messages, $helps),)*); } }; (@step $code:expr, (formatted, $error_name:ident($($arg_names:ident: $arg_types:ty,)*), $message:expr, $help:expr), $(($formatted_or_backtraced_tail:ident, $names:ident($($tail_arg_names:ident: $tail_arg_types:ty,)*), $messages:expr, $helps:expr),)*) => { - pub fn $error_name($($arg_names: $arg_types,)* span: &Span, backtrace: Backtrace) -> Self { - - Self::new_from_span($message, $help, $code, span, backtrace) + pub fn $error_name($($arg_names: $arg_types,)* span: &Span) -> Self { + Self::FormattedError( + FormattedError::new_from_span( + $message, + $help, + $code + Self::exit_code_mask(), + Self::code_identifier(), + Self::error_type(), + span, + Backtrace::new(), + ) + ) } - create_errors!(@step $code + 1u32, $(($formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*); + create_errors!(@step $code + 1i32, $(($formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*); }; (@step $code:expr, (backtraced, $error_name:ident($($arg_names:ident: $arg_types:ty,)*), $message:expr, $help:expr), $(($formatted_or_backtraced_tail:ident, $names:ident($($tail_arg_names:ident: $tail_arg_types:ty,)*), $messages:expr, $helps:expr),)*) => { - pub fn $error_name($($arg_names: $arg_types,)* backtrace: Backtrace) -> Self { - - Self::new_from_backtrace($message, $help, $code, backtrace) + pub fn $error_name($($arg_names: $arg_types,)*) -> Self { + Self::BacktracedError( + BacktracedError::new_from_backtrace( + $message, + $help, + $code + Self::exit_code_mask(), + Self::code_identifier(), + Self::error_type(), + Backtrace::new(), + ) + ) } - create_errors!(@step $code + 1u32, $(($formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*); + create_errors!(@step $code + 1i32, $(($formatted_or_backtraced_tail, $names($($tail_arg_names: $tail_arg_types,)*), $messages, $helps),)*); }; } diff --git a/errors/src/common/traits.rs b/errors/src/common/traits.rs index a08d9b11cc..2bd237fa8a 100644 --- a/errors/src/common/traits.rs +++ b/errors/src/common/traits.rs @@ -14,29 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Span; - -use backtrace::Backtrace; - pub trait ErrorCode: Sized { - fn exit_code(&self) -> u32; + fn exit_code(&self) -> i32; - fn exit_code_mask() -> u32; + fn exit_code_mask() -> i32; fn error_type() -> String; - - fn new_from_backtrace(message: S, help: Option, exit_code: u32, backtrace: Backtrace) -> Self - where - S: ToString; - - fn new_from_span(message: S, help: Option, exit_code: u32, span: &Span, backtrace: Backtrace) -> Self - where - S: ToString; } pub trait LeoErrorCode: ErrorCode { #[inline(always)] - fn code_identifier() -> u32 { + fn code_identifier() -> i8 { 37 } } diff --git a/errors/src/compiler/compiler_errors.rs b/errors/src/compiler/compiler_errors.rs index 4c2fab4791..d25a1e1406 100644 --- a/errors/src/compiler/compiler_errors.rs +++ b/errors/src/compiler/compiler_errors.rs @@ -23,7 +23,7 @@ use std::{ create_errors!( CompilerError, - exit_code_mask: 2000u32, + exit_code_mask: 2000i32, error_code_prefix: "CMP", @backtraced diff --git a/errors/src/import/import_errors.rs b/errors/src/import/import_errors.rs index 8ee09bd3a9..5a0bfb0d0b 100644 --- a/errors/src/import/import_errors.rs +++ b/errors/src/import/import_errors.rs @@ -23,7 +23,7 @@ use std::{ create_errors!( ImportError, - exit_code_mask: 3000u32, + exit_code_mask: 3000i32, error_code_prefix: "IMP", // An imported package has the same name as an imported core_package. diff --git a/errors/src/lib.rs b/errors/src/lib.rs index 01859de714..b82a0542b0 100644 --- a/errors/src/lib.rs +++ b/errors/src/lib.rs @@ -50,8 +50,6 @@ extern crate thiserror; use leo_input::InputParserError; -use backtrace::Backtrace; - #[derive(Debug, Error)] pub enum LeoError { #[error(transparent)] @@ -86,7 +84,7 @@ pub enum LeoError { } impl LeoError { - pub fn exit_code(&self) -> u32 { + pub fn exit_code(&self) -> i32 { use LeoError::*; match self { @@ -106,11 +104,6 @@ impl LeoError { pub type Result = core::result::Result; -#[inline(always)] -pub fn new_backtrace() -> Backtrace { - Backtrace::new() -} - // #[test] // fn test_error() { // let err = FormattedError { diff --git a/errors/src/package/package_errors.rs b/errors/src/package/package_errors.rs index 423dc7beda..d4c7caf83c 100644 --- a/errors/src/package/package_errors.rs +++ b/errors/src/package/package_errors.rs @@ -23,7 +23,7 @@ use std::{ create_errors!( PackageError, - exit_code_mask: 4000u32, + exit_code_mask: 4000i32, error_code_prefix: "PAK", @backtraced diff --git a/errors/src/parser/parser_errors.rs b/errors/src/parser/parser_errors.rs index f9d954e27d..bed0482804 100644 --- a/errors/src/parser/parser_errors.rs +++ b/errors/src/parser/parser_errors.rs @@ -20,7 +20,7 @@ use std::fmt::Display; create_errors!( ParserError, - exit_code_mask: 5000u32, + exit_code_mask: 5000i32, error_code_prefix: "PAR", @formatted diff --git a/errors/src/state/state_errors.rs b/errors/src/state/state_errors.rs index a58d6f454e..d5695fb2cc 100644 --- a/errors/src/state/state_errors.rs +++ b/errors/src/state/state_errors.rs @@ -18,6 +18,6 @@ use crate::create_errors; create_errors!( StateError, - exit_code_mask: 6000u32, - error_code_prefix: "S", + exit_code_mask: 6000i32, + error_code_prefix: "STA", ); diff --git a/imports/src/parser/import_parser.rs b/imports/src/parser/import_parser.rs index 0f49b70d5b..022b79e381 100644 --- a/imports/src/parser/import_parser.rs +++ b/imports/src/parser/import_parser.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use leo_asg::{AsgContext, ImportResolver, Program}; -use leo_errors::{new_backtrace, ImportError, LeoError, Result, Span}; +use leo_errors::{ImportError, LeoError, Result, Span}; use indexmap::{IndexMap, IndexSet}; use std::path::PathBuf; @@ -50,7 +50,7 @@ impl<'a> ImportResolver<'a> for ImportParser<'a> { ) -> Result>> { let full_path = package_segments.join("."); if self.partial_imports.contains(&full_path) { - return Err(ImportError::recursive_imports(full_path, span, new_backtrace()).into()); + return Err(ImportError::recursive_imports(full_path, span).into()); } if let Some(program) = self.imports.get(&full_path) { return Ok(Some(program.clone())); diff --git a/imports/src/parser/parse_package.rs b/imports/src/parser/parse_package.rs index f76456c8f7..3f2079598b 100644 --- a/imports/src/parser/parse_package.rs +++ b/imports/src/parser/parse_package.rs @@ -16,7 +16,7 @@ use crate::ImportParser; use leo_asg::{AsgContext, Program}; -use leo_errors::{new_backtrace, ImportError, Result, Span}; +use leo_errors::{ImportError, Result, Span}; use std::{fs, fs::DirEntry, path::PathBuf}; @@ -83,9 +83,9 @@ impl<'a> ImportParser<'a> { // Get a vector of all packages in the source directory. let entries = fs::read_dir(path) - .map_err(|error| ImportError::directory_error(error, &error_path, span, new_backtrace()))? + .map_err(|error| ImportError::directory_error(error, &error_path, span))? .collect::, std::io::Error>>() - .map_err(|error| ImportError::directory_error(error, &error_path, span, new_backtrace()))?; + .map_err(|error| ImportError::directory_error(error, &error_path, span))?; // Check if the imported package name is in the source directory. let matched_source_entry = entries.into_iter().find(|entry| { @@ -100,9 +100,9 @@ impl<'a> ImportParser<'a> { if imports_directory.exists() { // Get a vector of all packages in the imports directory. let entries = fs::read_dir(imports_directory) - .map_err(|error| ImportError::directory_error(error, &error_path, span, new_backtrace()))? + .map_err(|error| ImportError::directory_error(error, &error_path, span))? .collect::, std::io::Error>>() - .map_err(|error| ImportError::directory_error(error, error_path, span, new_backtrace()))?; + .map_err(|error| ImportError::directory_error(error, error_path, span))?; // Check if the imported package name is in the imports directory. let matched_import_entry = entries @@ -111,16 +111,16 @@ impl<'a> ImportParser<'a> { // Check if the package name was found in both the source and imports directory. match (matched_source_entry, matched_import_entry) { - (Some(_), Some(_)) => Err(ImportError::conflicting_imports(package_name, span, new_backtrace()).into()), + (Some(_), Some(_)) => Err(ImportError::conflicting_imports(package_name, span).into()), (Some(source_entry), None) => self.parse_package_access(context, &source_entry, &segments[1..], span), (None, Some(import_entry)) => self.parse_package_access(context, &import_entry, &segments[1..], span), - (None, None) => Err(ImportError::unknown_package(package_name, span, new_backtrace()).into()), + (None, None) => Err(ImportError::unknown_package(package_name, span).into()), } } else { // Enforce local package access with no found imports directory match matched_source_entry { Some(source_entry) => self.parse_package_access(context, &source_entry, &segments[1..], span), - None => Err(ImportError::unknown_package(package_name, span, new_backtrace()).into()), + None => Err(ImportError::unknown_package(package_name, span).into()), } } } diff --git a/imports/src/parser/parse_symbol.rs b/imports/src/parser/parse_symbol.rs index 95e1961e10..aa7f52a9fe 100644 --- a/imports/src/parser/parse_symbol.rs +++ b/imports/src/parser/parse_symbol.rs @@ -16,7 +16,7 @@ use crate::ImportParser; use leo_ast::Program; -use leo_errors::{new_backtrace, ImportError, Result, Span}; +use leo_errors::{ImportError, Result, Span}; use std::fs::DirEntry; @@ -32,26 +32,26 @@ impl<'a> ImportParser<'a> { // Get the package file type. let file_type = package .file_type() - .map_err(|error| ImportError::directory_error(error, package.path(), span, new_backtrace()))?; + .map_err(|error| ImportError::directory_error(error, package.path(), span))?; let file_name = package .file_name() .into_string() - .map_err(|_| ImportError::convert_os_string(span, new_backtrace()))?; + .map_err(|_| ImportError::convert_os_string(span))?; let mut file_path = package.path(); if file_type.is_dir() { file_path.push(MAIN_FILE); if !file_path.exists() { - return Err(ImportError::expected_main_file(file_path.as_path(), span, new_backtrace()).into()); + return Err(ImportError::expected_main_file(file_path.as_path(), span).into()); } } let file_path_str = file_path.to_str().unwrap_or_default(); // Build the package abstract syntax tree. - let program_string = &std::fs::read_to_string(&file_path) - .map_err(|x| ImportError::io_error(file_path_str, x, span, new_backtrace()))?; + let program_string = + &std::fs::read_to_string(&file_path).map_err(|x| ImportError::io_error(file_path_str, x, span))?; let mut program = leo_parser::parse(file_path_str, program_string)?; program.name = file_name; let mut ast = leo_ast::Ast::new(program); diff --git a/leo/api.rs b/leo/api.rs index 58a5f019ee..d90d51427e 100644 --- a/leo/api.rs +++ b/leo/api.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_errors::{new_backtrace, CliError, LeoError, Result}; +use leo_errors::{CliError, LeoError, Result}; use reqwest::{ blocking::{multipart::Form, Client, Response}, @@ -63,7 +63,7 @@ pub trait Route { /// Transform specific status codes into correct errors for this route. /// For example 404 on package fetch should mean that 'Package is not found' fn status_to_err(&self, _status: StatusCode) -> LeoError { - CliError::unidentified_api(new_backtrace()).into() + CliError::unidentified_api().into() } } @@ -131,9 +131,7 @@ impl Api { }; // only one error is possible here - let res = res - .send() - .map_err(|_| CliError::unable_to_connect_aleo_pm(new_backtrace()))?; + let res = res.send().map_err(|_| CliError::unable_to_connect_aleo_pm())?; // where magic begins route.process(res) @@ -173,12 +171,12 @@ impl Route for Fetch { fn status_to_err(&self, status: StatusCode) -> LeoError { match status { - StatusCode::BAD_REQUEST => CliError::package_not_found(new_backtrace()).into(), + StatusCode::BAD_REQUEST => CliError::package_not_found().into(), // TODO: we should return 404 on not found author/package // and return BAD_REQUEST if data format is incorrect or some of the arguments // were not passed - StatusCode::NOT_FOUND => CliError::package_not_found(new_backtrace()).into(), - _ => CliError::unkown_api_error(status, new_backtrace()).into(), + StatusCode::NOT_FOUND => CliError::package_not_found().into(), + _ => CliError::unkown_api_error(status).into(), } } } @@ -209,10 +207,10 @@ impl Route for Login { fn status_to_err(&self, status: StatusCode) -> LeoError { match status { - StatusCode::BAD_REQUEST => CliError::account_not_found(new_backtrace()).into(), + StatusCode::BAD_REQUEST => CliError::account_not_found().into(), // TODO: NOT_FOUND here should be replaced, this error code has no relation to what this route is doing - StatusCode::NOT_FOUND => CliError::incorrect_password(new_backtrace()).into(), - _ => CliError::unkown_api_error(status, new_backtrace()).into(), + StatusCode::NOT_FOUND => CliError::incorrect_password().into(), + _ => CliError::unkown_api_error(status).into(), } } } @@ -251,20 +249,16 @@ impl Route for Publish { let status = res.status(); if status == StatusCode::OK { - let body: PublishResponse = res - .json() - .map_err(|e| CliError::reqwest_json_error(e, new_backtrace()))?; + let body: PublishResponse = res.json().map_err(|e| CliError::reqwest_json_error(e))?; Ok(body.package_id) } else { - let res: HashMap = res - .json() - .map_err(|e| CliError::reqwest_json_error(e, new_backtrace()))?; + let res: HashMap = res.json().map_err(|e| CliError::reqwest_json_error(e))?; Err(match status { - StatusCode::BAD_REQUEST => CliError::bad_request(res.get("message").unwrap(), new_backtrace()).into(), - StatusCode::UNAUTHORIZED => CliError::not_logged_in(new_backtrace()).into(), - StatusCode::FAILED_DEPENDENCY => CliError::already_published(new_backtrace()).into(), - StatusCode::INTERNAL_SERVER_ERROR => CliError::internal_server_error(new_backtrace()).into(), - _ => CliError::unkown_api_error(status, new_backtrace()).into(), + StatusCode::BAD_REQUEST => CliError::bad_request(res.get("message").unwrap()).into(), + StatusCode::UNAUTHORIZED => CliError::not_logged_in().into(), + StatusCode::FAILED_DEPENDENCY => CliError::already_published().into(), + StatusCode::INTERNAL_SERVER_ERROR => CliError::internal_server_error().into(), + _ => CliError::unkown_api_error(status).into(), }) } } @@ -294,9 +288,7 @@ impl Route for Profile { // this may be extended for more precise error handling let status = res.status(); if status == StatusCode::OK { - let body: ProfileResponse = res - .json() - .map_err(|e| CliError::reqwest_json_error(e, new_backtrace()))?; + let body: ProfileResponse = res.json().map_err(|e| CliError::reqwest_json_error(e))?; return Ok(Some(body.username)); } diff --git a/leo/commands/build.rs b/leo/commands/build.rs index b2ab71d5dc..6bde3c74fa 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -21,7 +21,7 @@ use leo_compiler::{ AstSnapshotOptions, CompilerOptions, }; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use leo_package::{ inputs::*, outputs::{ChecksumFile, CircuitFile, OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, @@ -145,7 +145,7 @@ impl Command for Build { // Compile the main.leo file along with constraints if !MainFile::exists_at(&package_path) { - return Err(CliError::package_main_file_not_found(new_backtrace()).into()); + return Err(CliError::package_main_file_not_found().into()); } // Create the output directory diff --git a/leo/commands/init.rs b/leo/commands/init.rs index 3b89ae9cb1..c82a4c9bd7 100644 --- a/leo/commands/init.rs +++ b/leo/commands/init.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{commands::Command, config::*, context::Context}; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use leo_package::LeoPackage; use structopt::StructOpt; @@ -44,17 +44,17 @@ impl Command for Init { // Check that the current package directory path exists. if !path.exists() { - return Err(CliError::package_directory_does_not_exist(new_backtrace()).into()); + return Err(CliError::package_directory_does_not_exist().into()); } // Check that the given package name is valid. let package_name = path .file_stem() - .ok_or_else(|| CliError::invalid_project_name(new_backtrace()))? + .ok_or_else(|| CliError::invalid_project_name())? .to_string_lossy() .to_string(); if !LeoPackage::is_package_name_valid(&package_name) { - return Err(CliError::invalid_package_name(&package_name, new_backtrace()).into()); + return Err(CliError::invalid_package_name(&package_name).into()); } let username = read_username().ok(); diff --git a/leo/commands/new.rs b/leo/commands/new.rs index 3bdd717654..c08df08375 100644 --- a/leo/commands/new.rs +++ b/leo/commands/new.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{commands::Command, config::*, context::Context}; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use leo_package::LeoPackage; use std::fs; @@ -46,7 +46,7 @@ impl Command for New { // Check that the given package name is valid. let package_name = self.name; if !LeoPackage::is_package_name_valid(&package_name) { - return Err(CliError::invalid_project_name(new_backtrace()).into()); + return Err(CliError::invalid_project_name().into()); } let username = read_username().ok(); @@ -57,11 +57,11 @@ impl Command for New { // Verify the package directory path does not exist yet. if path.exists() { - return Err(CliError::package_directory_already_exists(&path, new_backtrace()).into()); + return Err(CliError::package_directory_already_exists(&path).into()); } // Create the package directory - fs::create_dir_all(&path).map_err(|err| CliError::package_could_not_create_directory(err, new_backtrace()))?; + fs::create_dir_all(&path).map_err(|err| CliError::package_could_not_create_directory(err))?; LeoPackage::initialize(&package_name, &path, username)?; diff --git a/leo/commands/package/add.rs b/leo/commands/package/add.rs index 9308859eff..9cdef736b9 100644 --- a/leo/commands/package/add.rs +++ b/leo/commands/package/add.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{api::Fetch, commands::Command, context::Context}; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use leo_package::imports::{ImportsDirectory, IMPORTS_DIRECTORY_NAME}; use std::{ @@ -64,12 +64,12 @@ impl Add { if v.len() == 2 { Ok((v[0].to_string(), v[1].to_string())) } else { - Err(CliError::incorrect_command_argument(new_backtrace()).into()) + Err(CliError::incorrect_command_argument().into()) } } else if let (Some(author), Some(package)) = (&self.author, &self.package) { Ok((author.clone(), package.clone())) } else { - Err(CliError::incorrect_command_argument(new_backtrace()).into()) + Err(CliError::incorrect_command_argument().into()) } } } @@ -88,13 +88,11 @@ impl Command for Add { fn apply(self, context: Context, _: Self::Input) -> Result { // Check that a manifest exists for the current package. - context - .manifest() - .map_err(|_| CliError::mainifest_file_not_found(new_backtrace()))?; + context.manifest().map_err(|_| CliError::mainifest_file_not_found())?; let (author, package_name) = self .try_read_arguments() - .map_err(|e| CliError::cli_bytes_conversion_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_bytes_conversion_error(e))?; // Attempt to fetch the package. let reader = { @@ -107,7 +105,7 @@ impl Command for Add { .api .run_route(fetch)? .bytes() - .map_err(|e| CliError::cli_bytes_conversion_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_bytes_conversion_error(e))?; std::io::Cursor::new(bytes) }; @@ -117,15 +115,13 @@ impl Command for Add { ImportsDirectory::create(&path)?; path.push(IMPORTS_DIRECTORY_NAME); path.push(package_name); - create_dir_all(&path).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + create_dir_all(&path).map_err(|e| CliError::cli_io_error(e))?; }; // Proceed to unzip and parse the fetched bytes. - let mut zip_archive = zip::ZipArchive::new(reader).map_err(|e| CliError::cli_zip_error(e, new_backtrace()))?; + let mut zip_archive = zip::ZipArchive::new(reader).map_err(|e| CliError::cli_zip_error(e))?; for i in 0..zip_archive.len() { - let file = zip_archive - .by_index(i) - .map_err(|e| CliError::cli_zip_error(e, new_backtrace()))?; + let file = zip_archive.by_index(i).map_err(|e| CliError::cli_zip_error(e))?; let file_name = file.name(); @@ -133,16 +129,16 @@ impl Command for Add { file_path.push(file_name); if file_name.ends_with('/') { - create_dir_all(file_path).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + create_dir_all(file_path).map_err(|e| CliError::cli_io_error(e))?; } else { if let Some(parent_directory) = path.parent() { - create_dir_all(parent_directory).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + create_dir_all(parent_directory).map_err(|e| CliError::cli_io_error(e))?; } - let mut created = File::create(file_path).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + let mut created = File::create(file_path).map_err(|e| CliError::cli_io_error(e))?; created .write_all(&file.bytes().map(|e| e.unwrap()).collect::>()) - .map_err(|e| CliError::cli_bytes_conversion_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_bytes_conversion_error(e))?; } } diff --git a/leo/commands/package/clone.rs b/leo/commands/package/clone.rs index 4f6005b272..a6d71490eb 100644 --- a/leo/commands/package/clone.rs +++ b/leo/commands/package/clone.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{api::Fetch, commands::Command, context::Context}; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use std::{ borrow::Cow, @@ -68,12 +68,12 @@ impl Clone { if v.len() == 2 { Ok((v[0].to_string(), v[1].to_string())) } else { - Err(CliError::incorrect_command_argument(new_backtrace()).into()) + Err(CliError::incorrect_command_argument().into()) } } else if let (Some(author), Some(package)) = (&self.author, &self.package) { Ok((author.clone(), package.clone())) } else { - Err(CliError::incorrect_command_argument(new_backtrace()).into()) + Err(CliError::incorrect_command_argument().into()) } } @@ -87,7 +87,7 @@ impl Clone { path.to_mut().push(directory_name); } - Ok(fs::create_dir_all(&path).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?) + Ok(fs::create_dir_all(&path).map_err(|e| CliError::cli_io_error(e))?) } } @@ -117,7 +117,7 @@ impl Command for Clone { .api .run_route(fetch)? .bytes() - .map_err(|e| CliError::cli_bytes_conversion_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_bytes_conversion_error(e))?; std::io::Cursor::new(bytes) }; @@ -127,12 +127,10 @@ impl Command for Clone { Self::create_directory(&path, &package_name)?; // Proceed to unzip and parse the fetched bytes. - let mut zip_archive = zip::ZipArchive::new(reader).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + let mut zip_archive = zip::ZipArchive::new(reader).map_err(|e| CliError::cli_io_error(e))?; for i in 0..zip_archive.len() { - let file = zip_archive - .by_index(i) - .map_err(|e| CliError::cli_zip_error(e, new_backtrace()))?; + let file = zip_archive.by_index(i).map_err(|e| CliError::cli_zip_error(e))?; let file_name = file.name(); @@ -140,16 +138,16 @@ impl Command for Clone { file_path.push(file_name); if file_name.ends_with('/') { - fs::create_dir_all(file_path).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + fs::create_dir_all(file_path).map_err(|e| CliError::cli_io_error(e))?; } else { if let Some(parent_directory) = path.parent() { - fs::create_dir_all(parent_directory).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + fs::create_dir_all(parent_directory).map_err(|e| CliError::cli_io_error(e))?; } - let mut created = File::create(file_path).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + let mut created = File::create(file_path).map_err(|e| CliError::cli_io_error(e))?; created .write_all(&file.bytes().map(|e| e.unwrap()).collect::>()) - .map_err(|e| CliError::cli_bytes_conversion_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_bytes_conversion_error(e))?; } } diff --git a/leo/commands/package/login.rs b/leo/commands/package/login.rs index 0d674b57d4..7c31fe4f74 100644 --- a/leo/commands/package/login.rs +++ b/leo/commands/package/login.rs @@ -20,7 +20,7 @@ use crate::{ config::*, context::Context, }; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use std::collections::HashMap; use structopt::StructOpt; @@ -72,13 +72,11 @@ impl Command for Login { }; let res = api.run_route(login)?; - let mut res: HashMap = res - .json() - .map_err(|e| CliError::reqwest_json_error(e, new_backtrace()))?; + let mut res: HashMap = res.json().map_err(|e| CliError::reqwest_json_error(e))?; let tok_opt = res.remove("token"); if tok_opt.is_none() { - return Err(CliError::unable_to_get_token(new_backtrace()).into()); + return Err(CliError::unable_to_get_token().into()); }; (tok_opt.unwrap(), email_username) @@ -92,7 +90,7 @@ impl Command for Login { match api.run_route(ProfileRoute {})? { Some(username) => (token, username), - None => return Err(CliError::supplied_token_is_incorrect(new_backtrace()).into()), + None => return Err(CliError::supplied_token_is_incorrect().into()), } } @@ -109,10 +107,10 @@ impl Command for Login { (token, username) } else { remove_token_and_username()?; - return Err(CliError::stored_credentials_expired(new_backtrace()).into()); + return Err(CliError::stored_credentials_expired().into()); } } - None => return Err(CliError::no_credentials_provided(new_backtrace()).into()), + None => return Err(CliError::no_credentials_provided().into()), } } }; diff --git a/leo/commands/package/publish.rs b/leo/commands/package/publish.rs index 491009fe02..52c9dffab8 100644 --- a/leo/commands/package/publish.rs +++ b/leo/commands/package/publish.rs @@ -16,7 +16,7 @@ use super::build::Build; use crate::{api::Publish as PublishRoute, commands::Command, context::Context}; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use leo_package::{ outputs::OutputsDirectory, root::{ZipFile, AUTHOR_PLACEHOLDER}, @@ -49,7 +49,7 @@ impl Command for Publish { let package_name = manifest.get_package_name(); if KEYWORD_TOKENS.iter().any(|keyword| keyword.to_string() == package_name) { - return Err(CliError::package_cannot_be_named_after_a_keyword(new_backtrace()).into()); + return Err(CliError::package_cannot_be_named_after_a_keyword().into()); } let package_version = manifest.get_package_version(); @@ -59,9 +59,9 @@ impl Command for Publish { manifest.get_package_license(), manifest.get_package_remote(), ) { - (None, _, _) => return Err(CliError::no_package_description(new_backtrace()).into()), - (_, None, _) => return Err(CliError::missing_package_license(new_backtrace()).into()), - (_, _, None) => return Err(CliError::missing_package_remote(new_backtrace()).into()), + (None, _, _) => return Err(CliError::no_package_description().into()), + (_, None, _) => return Err(CliError::missing_package_license().into()), + (_, _, None) => return Err(CliError::missing_package_remote().into()), (_, _, _) => (), }; @@ -70,7 +70,7 @@ impl Command for Publish { // Prevent most common error before accessing API. if username == AUTHOR_PLACEHOLDER { - return Err(CliError::package_author_is_not_set(new_backtrace()).into()); + return Err(CliError::package_author_is_not_set().into()); } // Create the output directory. diff --git a/leo/commands/prove.rs b/leo/commands/prove.rs index 2a174dedd4..86f85c1450 100644 --- a/leo/commands/prove.rs +++ b/leo/commands/prove.rs @@ -16,7 +16,7 @@ use super::{build::BuildOptions, setup::Setup}; use crate::{commands::Command, context::Context}; -use leo_errors::{new_backtrace, CliError, Result, SnarkVMError}; +use leo_errors::{CliError, Result, SnarkVMError}; use leo_package::outputs::ProofFile; use snarkvm_algorithms::{ snark::groth16::{Groth16, PreparedVerifyingKey, Proof}, @@ -74,7 +74,7 @@ impl Command for Prove { let mut proof = vec![]; program_proof .write_le(&mut proof) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; ProofFile::new(&package_name).write_to(&path, &proof)?; Ok((program_proof, prepared_verifying_key)) diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index 1265161377..5996bb1f3b 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -17,7 +17,7 @@ use super::build::{Build, BuildOptions}; use crate::{commands::Command, context::Context}; use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType}; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use leo_package::outputs::{ProvingKeyFile, VerificationKeyFile}; use snarkvm_algorithms::{ @@ -80,7 +80,7 @@ impl Command for Setup { let rng = &mut thread_rng(); let (proving_key, prepared_verifying_key) = Groth16::, Vec>::setup(&program, rng) - .map_err(|_| CliError::unable_to_setup(new_backtrace()))?; + .map_err(|_| CliError::unable_to_setup())?; // TODO (howardwu): Convert parameters to a 'proving key' struct for serialization. // Write the proving key file to the output directory @@ -89,7 +89,7 @@ impl Command for Setup { let mut proving_key_bytes = vec![]; proving_key .write_le(&mut proving_key_bytes) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; let _ = proving_key_file.write_to(&path, &proving_key_bytes)?; tracing::info!("Complete"); @@ -100,7 +100,7 @@ impl Command for Setup { proving_key .vk .write_le(&mut verification_key) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; let _ = verification_key_file.write_to(&path, &verification_key)?; tracing::info!("Complete"); @@ -116,16 +116,16 @@ impl Command for Setup { } let proving_key_bytes = ProvingKeyFile::new(&package_name).read_from(&path)?; let proving_key = ProvingKey::::read(proving_key_bytes.as_slice(), !self.skip_key_check) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; tracing::info!("Complete"); // Read the verification key file from the output directory tracing::info!("Loading verification key..."); let verifying_key_bytes = VerificationKeyFile::new(&package_name) .read_from(&path) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; let verifying_key = VerifyingKey::::read(verifying_key_bytes.as_slice()) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; // Derive the prepared verifying key file from the verifying key let prepared_verifying_key = PreparedVerifyingKey::::from(verifying_key); diff --git a/leo/commands/test.rs b/leo/commands/test.rs index cef2eda865..773ac53488 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -20,7 +20,7 @@ use leo_compiler::{ compiler::{thread_leaked_context, Compiler}, group::targets::edwards_bls12::EdwardsGroupType, }; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use leo_package::{ inputs::*, outputs::{OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, @@ -80,7 +80,7 @@ impl Command for Test { // when no main file and no files marked - error } else { - return Err(CliError::program_file_does_not_exist(package_path.to_string_lossy(), new_backtrace()).into()); + return Err(CliError::program_file_does_not_exist(package_path.to_string_lossy()).into()); } // Construct the path to the output directory; diff --git a/leo/commands/update.rs b/leo/commands/update.rs index e0431512c6..f5a9a2991b 100644 --- a/leo/commands/update.rs +++ b/leo/commands/update.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{commands::Command, config::Config, context::Context, updater::Updater}; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use structopt::StructOpt; use tracing::span::Span; @@ -61,8 +61,7 @@ impl Command for Update { fn apply(self, _: Context, _: Self::Input) -> Result { // If --list is passed, list all available versions and return. if self.list { - return Ok(Updater::show_available_releases() - .map_err(|e| CliError::could_not_fetch_versions(e, new_backtrace()))?); + return Ok(Updater::show_available_releases().map_err(|e| CliError::could_not_fetch_versions(e))?); } // Handles enabling and disabling automatic updates in the config file. diff --git a/leo/commands/watch.rs b/leo/commands/watch.rs index ae5756e76a..889ad6d1d0 100644 --- a/leo/commands/watch.rs +++ b/leo/commands/watch.rs @@ -16,7 +16,7 @@ use super::build::{Build, BuildOptions}; use crate::{commands::Command, context::Context}; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use std::{sync::mpsc::channel, time::Duration}; @@ -56,7 +56,7 @@ impl Command for Watch { watcher .watch(LEO_SOURCE_DIR, RecursiveMode::Recursive) - .map_err(|e| CliError::unable_to_watch(e, new_backtrace()))?; + .map_err(|e| CliError::unable_to_watch(e))?; tracing::info!("Watching Leo source code"); diff --git a/leo/config.rs b/leo/config.rs index 2ea893abf5..940e4977ac 100644 --- a/leo/config.rs +++ b/leo/config.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use std::{ fs::{ @@ -89,37 +89,34 @@ impl Config { if !Path::exists(&config_path) { // Create a new default `config.toml` file if it doesn't already exist - create_dir_all(&config_dir).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + create_dir_all(&config_dir).map_err(|e| CliError::cli_io_error(e))?; - let default_config_string = toml::to_string(&Config::default()) - .map_err(|e| CliError::failed_to_convert_to_toml(e, new_backtrace()))?; + let default_config_string = + toml::to_string(&Config::default()).map_err(|e| CliError::failed_to_convert_to_toml(e))?; - fs::write(&config_path, default_config_string).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + fs::write(&config_path, default_config_string).map_err(|e| CliError::cli_io_error(e))?; } let toml_string = match fs::read_to_string(&config_path) { Ok(mut toml) => { // If the config is using an incorrect format, rewrite it. if toml::from_str::(&toml).is_err() { - let default_config_string = toml::to_string(&Config::default()) - .map_err(|e| CliError::failed_to_convert_to_toml(e, new_backtrace()))?; - fs::write(&config_path, default_config_string.clone()) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + let default_config_string = + toml::to_string(&Config::default()).map_err(|e| CliError::failed_to_convert_to_toml(e))?; + fs::write(&config_path, default_config_string.clone()).map_err(|e| CliError::cli_io_error(e))?; toml = default_config_string; } toml } Err(_) => { - create_dir_all(&config_dir).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; - toml::to_string(&Config::default()) - .map_err(|e| CliError::failed_to_convert_to_toml(e, new_backtrace()))? + create_dir_all(&config_dir).map_err(|e| CliError::cli_io_error(e))?; + toml::to_string(&Config::default()).map_err(|e| CliError::failed_to_convert_to_toml(e))? } }; // Parse the contents into the `Config` struct - let config: Config = - toml::from_str(&toml_string).map_err(|e| CliError::failed_to_convert_from_toml(e, new_backtrace()))?; + let config: Config = toml::from_str(&toml_string).map_err(|e| CliError::failed_to_convert_from_toml(e))?; Ok(config) } @@ -135,9 +132,9 @@ impl Config { let config_path = LEO_CONFIG_PATH.clone(); fs::write( &config_path, - toml::to_string(&config).map_err(|e| CliError::failed_to_convert_to_toml(e, new_backtrace()))?, + toml::to_string(&config).map_err(|e| CliError::failed_to_convert_to_toml(e))?, ) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; } Ok(()) @@ -149,50 +146,46 @@ pub fn write_token_and_username(token: &str, username: &str) -> Result<()> { // Create Leo config directory if it not exists if !Path::new(&config_dir).exists() { - create_dir_all(&config_dir).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + create_dir_all(&config_dir).map_err(|e| CliError::cli_io_error(e))?; } - let mut credentials = - File::create(&LEO_CREDENTIALS_PATH.to_path_buf()).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + let mut credentials = File::create(&LEO_CREDENTIALS_PATH.to_path_buf()).map_err(|e| CliError::cli_io_error(e))?; credentials .write_all(token.as_bytes()) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; - let mut username_file = - File::create(&LEO_USERNAME_PATH.to_path_buf()).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + let mut username_file = File::create(&LEO_USERNAME_PATH.to_path_buf()).map_err(|e| CliError::cli_io_error(e))?; username_file .write_all(username.as_bytes()) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; Ok(()) } pub fn read_token() -> Result { - let mut credentials = - File::open(&LEO_CREDENTIALS_PATH.to_path_buf()).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + let mut credentials = File::open(&LEO_CREDENTIALS_PATH.to_path_buf()).map_err(|e| CliError::cli_io_error(e))?; let mut buf = String::new(); credentials .read_to_string(&mut buf) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; Ok(buf) } pub fn read_username() -> Result { - let mut username = - File::open(&LEO_USERNAME_PATH.to_path_buf()).map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + let mut username = File::open(&LEO_USERNAME_PATH.to_path_buf()).map_err(|e| CliError::cli_io_error(e))?; let mut buf = String::new(); username .read_to_string(&mut buf) - .map_err(|e| CliError::cli_io_error(e, new_backtrace()))?; + .map_err(|e| CliError::cli_io_error(e))?; Ok(buf) } pub fn remove_token_and_username() -> Result<()> { if let Err(err) = fs::remove_file(&LEO_CREDENTIALS_PATH.to_path_buf()) { - return Err(CliError::remove_token_and_username(err, new_backtrace()).into()); + return Err(CliError::remove_token_and_username(err).into()); } if let Err(err) = fs::remove_file(&LEO_USERNAME_PATH.to_path_buf()) { - return Err(CliError::remove_token_and_username(err, new_backtrace()).into()); + return Err(CliError::remove_token_and_username(err).into()); } Ok(()) } diff --git a/leo/context.rs b/leo/context.rs index 07cb6b47c6..14fba3c141 100644 --- a/leo/context.rs +++ b/leo/context.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{api::Api, config}; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use leo_package::root::Manifest; use std::{convert::TryFrom, env::current_dir, path::PathBuf}; @@ -37,7 +37,7 @@ impl Context { pub fn dir(&self) -> Result { match &self.path { Some(path) => Ok(path.clone()), - None => Ok(current_dir().map_err(|e| CliError::cli_io_error(e, new_backtrace()))?), + None => Ok(current_dir().map_err(|e| CliError::cli_io_error(e))?), } } diff --git a/leo/logger.rs b/leo/logger.rs index 91c72ea7f7..0cb89fa3b6 100644 --- a/leo/logger.rs +++ b/leo/logger.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use std::{fmt, sync::Once}; @@ -214,7 +214,7 @@ where pub fn init_logger(_app_name: &'static str, verbosity: usize) -> Result<()> { // This line enables Windows 10 ANSI coloring API. #[cfg(target_family = "windows")] - ansi_term::enable_ansi_support().map_err(|_| CliError::failed_to_enable_ansi_support(new_backtrace()))?; + ansi_term::enable_ansi_support().map_err(|_| CliError::failed_to_enable_ansi_support())?; use tracing_subscriber::fmt::writer::MakeWriterExt; diff --git a/leo/main.rs b/leo/main.rs index 4de5ef6e20..c0f8e02aed 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -39,6 +39,7 @@ use commands::{ }; use leo_errors::Result; +use color_backtrace; use colored::Colorize; use std::{path::PathBuf, process::exit}; use structopt::{clap::AppSettings, StructOpt}; @@ -182,6 +183,7 @@ enum CommandOpts { } fn main() { + color_backtrace::install(); handle_error(run_with_args(Opt::from_args())) } @@ -244,7 +246,7 @@ fn handle_error(res: Result) -> T { .collect::>() .join("\n") ); - exit(1); + exit(err.exit_code()); } } } diff --git a/leo/updater.rs b/leo/updater.rs index 02919bb639..ff90e12f8a 100644 --- a/leo/updater.rs +++ b/leo/updater.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::config::Config; -use leo_errors::{new_backtrace, CliError, Result}; +use leo_errors::{CliError, Result}; use colored::Colorize; use self_update::{backends::github, version::bump_is_greater, Status}; @@ -34,9 +34,9 @@ impl Updater { .repo_owner(Self::LEO_REPO_OWNER) .repo_name(Self::LEO_REPO_NAME) .build() - .map_err(|e| CliError::self_update_error(e, new_backtrace()))? + .map_err(|e| CliError::self_update_error(e))? .fetch() - .map_err(|e| CliError::self_update_error(e, new_backtrace()))?; + .map_err(|e| CliError::self_update_error(e))?; let mut output = "\nList of available versions\n".to_string(); for release in releases { @@ -60,9 +60,9 @@ impl Updater { .no_confirm(true) .show_output(show_output) .build() - .map_err(|e| CliError::self_update_error(e, new_backtrace()))? + .map_err(|e| CliError::self_update_error(e))? .update() - .map_err(|e| CliError::self_update_error(e, new_backtrace()))?; + .map_err(|e| CliError::self_update_error(e))?; Ok(status) } @@ -75,19 +75,17 @@ impl Updater { .bin_name(Self::LEO_BIN_NAME) .current_version(env!("CARGO_PKG_VERSION")) .build() - .map_err(|e| CliError::self_update_error(e, new_backtrace()))?; + .map_err(|e| CliError::self_update_error(e))?; let current_version = updater.current_version(); let latest_release = updater .get_latest_release() - .map_err(|e| CliError::self_update_error(e, new_backtrace()))?; + .map_err(|e| CliError::self_update_error(e))?; - if bump_is_greater(¤t_version, &latest_release.version) - .map_err(|e| CliError::self_update_error(e, new_backtrace()))? - { + if bump_is_greater(¤t_version, &latest_release.version).map_err(|e| CliError::self_update_error(e))? { Ok(latest_release.version) } else { - Err(CliError::old_release_version(current_version, latest_release.version, new_backtrace()).into()) + Err(CliError::old_release_version(current_version, latest_release.version).into()) } } diff --git a/package/src/imports/directory.rs b/package/src/imports/directory.rs index 17a98fd41a..abf58e9cdf 100644 --- a/package/src/imports/directory.rs +++ b/package/src/imports/directory.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use std::{borrow::Cow, fs, path::Path}; @@ -30,7 +30,7 @@ impl ImportsDirectory { path.to_mut().push(IMPORTS_DIRECTORY_NAME); } - fs::create_dir_all(&path).map_err(|e| PackageError::failed_to_create_imports_directory(e, new_backtrace()))?; + fs::create_dir_all(&path).map_err(|e| PackageError::failed_to_create_imports_directory(e))?; Ok(()) } @@ -44,10 +44,10 @@ impl ImportsDirectory { path.to_mut().push(package_name); if !path.exists() || !path.is_dir() { - return Err(PackageError::import_does_not_exist(package_name, new_backtrace()).into()); + return Err(PackageError::import_does_not_exist(package_name).into()); } - fs::remove_dir_all(&path).map_err(|e| PackageError::failed_to_remove_imports_directory(e, new_backtrace()))?; + fs::remove_dir_all(&path).map_err(|e| PackageError::failed_to_remove_imports_directory(e))?; Ok(()) } diff --git a/package/src/inputs/directory.rs b/package/src/inputs/directory.rs index 76e748c8a7..1b1e205bd5 100644 --- a/package/src/inputs/directory.rs +++ b/package/src/inputs/directory.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use std::{ borrow::Cow, @@ -35,7 +35,7 @@ impl InputsDirectory { path.to_mut().push(INPUTS_DIRECTORY_NAME); } - fs::create_dir_all(&path).map_err(|e| PackageError::failed_to_create_inputs_directory(e, new_backtrace()))?; + fs::create_dir_all(&path).map_err(|e| PackageError::failed_to_create_inputs_directory(e))?; Ok(()) } @@ -44,8 +44,7 @@ impl InputsDirectory { let mut path = path.to_owned(); path.push(INPUTS_DIRECTORY_NAME); - let directory = - fs::read_dir(&path).map_err(|e| PackageError::failed_to_read_inputs_directory(e, new_backtrace()))?; + let directory = fs::read_dir(&path).map_err(|e| PackageError::failed_to_read_inputs_directory(e))?; let mut file_paths = Vec::new(); parse_file_paths(directory, &mut file_paths)?; @@ -55,26 +54,20 @@ impl InputsDirectory { fn parse_file_paths(directory: ReadDir, file_paths: &mut Vec) -> Result<()> { for file_entry in directory.into_iter() { - let file_entry = file_entry.map_err(|e| PackageError::failed_to_get_input_file_entry(e, new_backtrace()))?; + let file_entry = file_entry.map_err(|e| PackageError::failed_to_get_input_file_entry(e))?; let file_path = file_entry.path(); // Verify that the entry is structured as a valid file or directory - let file_type = file_entry.file_type().map_err(|e| { - PackageError::failed_to_get_input_file_type(file_path.as_os_str().to_owned(), e, new_backtrace()) - })?; + let file_type = file_entry + .file_type() + .map_err(|e| PackageError::failed_to_get_input_file_type(file_path.as_os_str().to_owned(), e))?; if file_type.is_dir() { - let directory = fs::read_dir(&file_path) - .map_err(|e| PackageError::failed_to_read_inputs_directory(e, new_backtrace()))?; + let directory = fs::read_dir(&file_path).map_err(|e| PackageError::failed_to_read_inputs_directory(e))?; parse_file_paths(directory, file_paths)?; continue; } else if !file_type.is_file() { - return Err(PackageError::invalid_input_file_type( - file_path.as_os_str().to_owned(), - file_type, - new_backtrace(), - ) - .into()); + return Err(PackageError::invalid_input_file_type(file_path.as_os_str().to_owned(), file_type).into()); } file_paths.push(file_path); diff --git a/package/src/inputs/input.rs b/package/src/inputs/input.rs index d0bf718950..531cf88975 100644 --- a/package/src/inputs/input.rs +++ b/package/src/inputs/input.rs @@ -18,7 +18,7 @@ use crate::inputs::INPUTS_DIRECTORY_NAME; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{ @@ -59,17 +59,17 @@ impl InputFile { let path = self.setup_file_path(path); let input = fs::read_to_string(&path) - .map_err(|_| PackageError::failed_to_read_input_file(path.clone().into_owned(), new_backtrace()))?; + .map_err(|_| PackageError::failed_to_read_input_file(path.clone().into_owned()))?; Ok((input, path)) } /// Writes the standard input format to a file. pub fn write_to(self, path: &Path) -> Result<()> { let path = self.setup_file_path(path); - let mut file = File::create(&path).map_err(|e| PackageError::io_error_input_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_input_file(e))?; file.write_all(self.template().as_bytes()) - .map_err(|e| PackageError::io_error_input_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_input_file(e))?; Ok(()) } diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index 7294b5bb28..427349c656 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::inputs::{InputFile, InputsDirectory, StateFile, INPUT_FILE_EXTENSION, STATE_FILE_EXTENSION}; -use leo_errors::{new_backtrace, LeoError, PackageError}; +use leo_errors::{LeoError, PackageError}; use std::{collections::HashMap, convert::TryFrom, path::Path}; @@ -58,13 +58,11 @@ impl TryFrom<&Path> for InputPairs { Some(stem) => match stem.to_str() { Some(file_name) => file_name, None => { - return Err( - PackageError::failed_to_get_input_file_name(file.as_os_str(), new_backtrace()).into(), - ); + return Err(PackageError::failed_to_get_input_file_name(file.as_os_str()).into()); } }, None => { - return Err(PackageError::failed_to_get_input_file_name(file.as_os_str(), new_backtrace()).into()); + return Err(PackageError::failed_to_get_input_file_name(file.as_os_str()).into()); } }; diff --git a/package/src/inputs/state.rs b/package/src/inputs/state.rs index 057d72bd0e..d07cf78da0 100644 --- a/package/src/inputs/state.rs +++ b/package/src/inputs/state.rs @@ -17,7 +17,7 @@ //! The `program.state` file. use crate::inputs::INPUTS_DIRECTORY_NAME; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{ @@ -58,18 +58,18 @@ impl StateFile { let path = self.setup_file_path(path); let input = fs::read_to_string(&path) - .map_err(|_| PackageError::failed_to_read_state_file(path.clone().into_owned(), new_backtrace()))?; + .map_err(|_| PackageError::failed_to_read_state_file(path.clone().into_owned()))?; Ok((input, path)) } /// Writes the standard input format to a file. pub fn write_to(self, path: &Path) -> Result<()> { let path = self.setup_file_path(path); - let mut file = File::create(&path).map_err(|e| PackageError::io_error_state_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_state_file(e))?; Ok(file .write_all(self.template().as_bytes()) - .map_err(|e| PackageError::io_error_state_file(e, new_backtrace()))?) + .map_err(|e| PackageError::io_error_state_file(e))?) } fn template(&self) -> String { diff --git a/package/src/outputs/checksum.rs b/package/src/outputs/checksum.rs index e0b3f10b8d..bd557b3f51 100644 --- a/package/src/outputs/checksum.rs +++ b/package/src/outputs/checksum.rs @@ -17,7 +17,7 @@ //! The build checksum file. use crate::outputs::OUTPUTS_DIRECTORY_NAME; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{ @@ -53,18 +53,18 @@ impl ChecksumFile { pub fn read_from(&self, path: &Path) -> Result { let path = self.setup_file_path(path); - let string = fs::read_to_string(&path) - .map_err(|_| PackageError::failed_to_read_checksum_file(path.into_owned(), new_backtrace()))?; + let string = + fs::read_to_string(&path).map_err(|_| PackageError::failed_to_read_checksum_file(path.into_owned()))?; Ok(string) } /// Writes the given checksum to a file. pub fn write_to(&self, path: &Path, checksum: String) -> Result<()> { let path = self.setup_file_path(path); - let mut file = File::create(&path).map_err(|e| PackageError::io_error_checksum_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_checksum_file(e))?; file.write_all(checksum.as_bytes()) - .map_err(|e| PackageError::io_error_checksum_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_checksum_file(e))?; Ok(()) } @@ -76,8 +76,7 @@ impl ChecksumFile { return Ok(false); } - fs::remove_file(&path) - .map_err(|_| PackageError::failed_to_remove_checksum_file(path.into_owned(), new_backtrace()))?; + fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_checksum_file(path.into_owned()))?; Ok(true) } diff --git a/package/src/outputs/circuit.rs b/package/src/outputs/circuit.rs index eaa2052d4e..9076668aa2 100644 --- a/package/src/outputs/circuit.rs +++ b/package/src/outputs/circuit.rs @@ -17,7 +17,7 @@ //! The serialized circuit output file. use crate::outputs::OUTPUTS_DIRECTORY_NAME; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{ @@ -53,18 +53,18 @@ impl CircuitFile { pub fn read_from(&self, path: &Path) -> Result { let path = self.setup_file_path(path); - let string = fs::read_to_string(&path) - .map_err(|_| PackageError::failed_to_read_circuit_file(path.into_owned(), new_backtrace()))?; + let string = + fs::read_to_string(&path).map_err(|_| PackageError::failed_to_read_circuit_file(path.into_owned()))?; Ok(string) } /// Writes the given serialized circuit to a file. pub fn write_to(&self, path: &Path, circuit: String) -> Result<()> { let path = self.setup_file_path(path); - let mut file = File::create(&path).map_err(|e| PackageError::io_error_circuit_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_circuit_file(e))?; file.write_all(circuit.as_bytes()) - .map_err(|e| PackageError::io_error_circuit_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_circuit_file(e))?; Ok(()) } @@ -76,7 +76,7 @@ impl CircuitFile { return Ok(false); } - fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_circuit_file(path, new_backtrace()))?; + fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_circuit_file(path))?; Ok(true) } diff --git a/package/src/outputs/directory.rs b/package/src/outputs/directory.rs index f370748827..ab72c99e92 100644 --- a/package/src/outputs/directory.rs +++ b/package/src/outputs/directory.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use std::{borrow::Cow, fs, path::Path}; @@ -30,7 +30,7 @@ impl OutputsDirectory { path.to_mut().push(OUTPUTS_DIRECTORY_NAME); } - fs::create_dir_all(&path).map_err(|e| PackageError::failed_to_create_inputs_directory(e, new_backtrace()))?; + fs::create_dir_all(&path).map_err(|e| PackageError::failed_to_create_inputs_directory(e))?; Ok(()) } @@ -42,8 +42,7 @@ impl OutputsDirectory { } if path.exists() { - fs::remove_dir_all(&path) - .map_err(|e| PackageError::failed_to_create_inputs_directory(e, new_backtrace()))?; + fs::remove_dir_all(&path).map_err(|e| PackageError::failed_to_create_inputs_directory(e))?; } Ok(()) diff --git a/package/src/outputs/proof.rs b/package/src/outputs/proof.rs index 94573bec8e..e2c0a08b7c 100644 --- a/package/src/outputs/proof.rs +++ b/package/src/outputs/proof.rs @@ -17,7 +17,7 @@ //! The proof file. use crate::outputs::OUTPUTS_DIRECTORY_NAME; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{ @@ -53,18 +53,18 @@ impl ProofFile { pub fn read_from(&self, path: &Path) -> Result { let path = self.setup_file_path(path); - let string = fs::read_to_string(&path) - .map_err(|_| PackageError::failed_to_read_proof_file(path.into_owned(), new_backtrace()))?; + let string = + fs::read_to_string(&path).map_err(|_| PackageError::failed_to_read_proof_file(path.into_owned()))?; Ok(string) } /// Writes the given proof to a file. pub fn write_to(&self, path: &Path, proof: &[u8]) -> Result<()> { let path = self.setup_file_path(path); - let mut file = File::create(&path).map_err(|e| PackageError::io_error_proof_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_proof_file(e))?; file.write_all(proof) - .map_err(|e| PackageError::io_error_proof_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_proof_file(e))?; tracing::info!("Saving proof... ({:?})", path); Ok(()) @@ -78,7 +78,7 @@ impl ProofFile { return Ok(false); } - fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_proof_file(path, new_backtrace()))?; + fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_proof_file(path))?; Ok(true) } diff --git a/package/src/outputs/proving_key.rs b/package/src/outputs/proving_key.rs index 99900f8cf9..64b920232e 100644 --- a/package/src/outputs/proving_key.rs +++ b/package/src/outputs/proving_key.rs @@ -17,7 +17,7 @@ //! The proving key file. use crate::outputs::OUTPUTS_DIRECTORY_NAME; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{ @@ -57,18 +57,17 @@ impl ProvingKeyFile { pub fn read_from(&self, path: &Path) -> Result> { let path = self.setup_file_path(path); - let bytes = - fs::read(&path).map_err(|_| PackageError::failed_to_read_proving_key_file(path, new_backtrace()))?; + let bytes = fs::read(&path).map_err(|_| PackageError::failed_to_read_proving_key_file(path))?; Ok(bytes) } /// Writes the given proving key to a file. pub fn write_to<'a>(&self, path: &'a Path, proving_key: &[u8]) -> Result> { let path = self.setup_file_path(path); - let mut file = File::create(&path).map_err(|e| PackageError::io_error_proving_key_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_proving_key_file(e))?; file.write_all(proving_key) - .map_err(|e| PackageError::io_error_proving_key_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_proving_key_file(e))?; Ok(path) } @@ -80,7 +79,7 @@ impl ProvingKeyFile { return Ok(false); } - fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_proving_key_file(path, new_backtrace()))?; + fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_proving_key_file(path))?; Ok(true) } diff --git a/package/src/outputs/verification_key.rs b/package/src/outputs/verification_key.rs index fa056c2f4b..5b3ba6f073 100644 --- a/package/src/outputs/verification_key.rs +++ b/package/src/outputs/verification_key.rs @@ -17,7 +17,7 @@ //! The verification key file. use crate::outputs::OUTPUTS_DIRECTORY_NAME; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{ @@ -57,19 +57,18 @@ impl VerificationKeyFile { pub fn read_from(&self, path: &Path) -> Result> { let path = self.setup_file_path(path); - let bytes = fs::read(&path) - .map_err(|_| PackageError::failed_to_read_verification_key_file(path.into_owned(), new_backtrace()))?; + let bytes = + fs::read(&path).map_err(|_| PackageError::failed_to_read_verification_key_file(path.into_owned()))?; Ok(bytes) } /// Writes the given verification key to a file. pub fn write_to<'a>(&self, path: &'a Path, verification_key: &[u8]) -> Result> { let path = self.setup_file_path(path); - let mut file = - File::create(&path).map_err(|e| PackageError::io_error_verification_key_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_verification_key_file(e))?; file.write_all(verification_key) - .map_err(|e| PackageError::io_error_verification_key_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_verification_key_file(e))?; Ok(path) } @@ -81,8 +80,7 @@ impl VerificationKeyFile { return Ok(false); } - fs::remove_file(&path) - .map_err(|_| PackageError::failed_to_remove_verification_key_file(path, new_backtrace()))?; + fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_verification_key_file(path))?; Ok(true) } diff --git a/package/src/package.rs b/package/src/package.rs index 1e78a7ffa2..9cb628421e 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -21,7 +21,7 @@ use crate::{ source::{MainFile, SourceDirectory}, }; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::path::Path; @@ -38,7 +38,7 @@ impl Package { pub fn new(package_name: &str) -> Result { // Check that the package name is valid. if !Self::is_package_name_valid(package_name) { - return Err(PackageError::invalid_package_name(package_name, new_backtrace()).into()); + return Err(PackageError::invalid_package_name(package_name).into()); } Ok(Self { @@ -187,12 +187,7 @@ impl Package { // First, verify that this directory is not already initialized as a Leo package. { if !Self::can_initialize(package_name, path) { - return Err(PackageError::failed_to_initialize_package( - package_name, - path.as_os_str(), - new_backtrace(), - ) - .into()); + return Err(PackageError::failed_to_initialize_package(package_name, path.as_os_str()).into()); } } // Next, initialize this directory as a Leo package. @@ -230,12 +225,7 @@ impl Package { // Next, verify that a valid Leo package has been initialized in this directory { if !Self::is_initialized(package_name, path) { - return Err(PackageError::failed_to_initialize_package( - package_name, - path.as_os_str(), - new_backtrace(), - ) - .into()); + return Err(PackageError::failed_to_initialize_package(package_name, path.as_os_str()).into()); } } diff --git a/package/src/root/gitignore.rs b/package/src/root/gitignore.rs index f01b4d9f24..b324c56df0 100644 --- a/package/src/root/gitignore.rs +++ b/package/src/root/gitignore.rs @@ -16,7 +16,7 @@ //! The `.gitignore` file. -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{borrow::Cow, fs::File, io::Write, path::Path}; @@ -45,9 +45,9 @@ impl Gitignore { path.to_mut().push(GITIGNORE_FILENAME); } - let mut file = File::create(&path).map_err(|e| PackageError::io_error_gitignore_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_gitignore_file(e))?; file.write_all(self.template().as_bytes()) - .map_err(|e| PackageError::io_error_gitignore_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_gitignore_file(e))?; Ok(()) } diff --git a/package/src/root/manifest.rs b/package/src/root/manifest.rs index 02e4a560f0..a18f7ac826 100644 --- a/package/src/root/manifest.rs +++ b/package/src/root/manifest.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::package::Package; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{ @@ -86,11 +86,11 @@ impl Manifest { path.to_mut().push(MANIFEST_FILENAME); } - let mut file = File::create(&path) - .map_err(|e| PackageError::failed_to_create_manifest_file(MANIFEST_FILENAME, e, new_backtrace()))?; + let mut file = + File::create(&path).map_err(|e| PackageError::failed_to_create_manifest_file(MANIFEST_FILENAME, e))?; file.write_all(self.template().as_bytes()) - .map_err(|e| PackageError::io_error_manifest_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_manifest_file(e))?; Ok(()) } @@ -125,18 +125,18 @@ impl TryFrom<&Path> for Manifest { path.to_mut().push(MANIFEST_FILENAME); } - let mut file = File::open(path.clone()) - .map_err(|e| PackageError::failed_to_open_manifest_file(MANIFEST_FILENAME, e, new_backtrace()))?; + let mut file = + File::open(path.clone()).map_err(|e| PackageError::failed_to_open_manifest_file(MANIFEST_FILENAME, e))?; let size = file .metadata() - .map_err(|e| PackageError::failed_to_get_manifest_metadata_file(MANIFEST_FILENAME, e, new_backtrace()))? + .map_err(|e| PackageError::failed_to_get_manifest_metadata_file(MANIFEST_FILENAME, e))? .len() as usize; let mut buffer = String::with_capacity(size); file.read_to_string(&mut buffer) - .map_err(|e| PackageError::failed_to_read_manifest_file(MANIFEST_FILENAME, e, new_backtrace()))?; + .map_err(|e| PackageError::failed_to_read_manifest_file(MANIFEST_FILENAME, e))?; // Determine if the old remote format is being used, and update to new convention @@ -222,15 +222,14 @@ author = "{author}" // Rewrite the toml file if it has been updated if buffer != refactored_toml { - let mut file = File::create(&path) - .map_err(|e| PackageError::failed_to_create_manifest_file(MANIFEST_FILENAME, e, new_backtrace()))?; + let mut file = + File::create(&path).map_err(|e| PackageError::failed_to_create_manifest_file(MANIFEST_FILENAME, e))?; file.write_all(refactored_toml.as_bytes()) - .map_err(|e| PackageError::failed_to_write_manifest_file(MANIFEST_FILENAME, e, new_backtrace()))?; + .map_err(|e| PackageError::failed_to_write_manifest_file(MANIFEST_FILENAME, e))?; } // Read the toml file - toml::from_str(&final_toml) - .map_err(|e| PackageError::failed_to_parse_manifest_file(MANIFEST_FILENAME, e, new_backtrace())) + toml::from_str(&final_toml).map_err(|e| PackageError::failed_to_parse_manifest_file(MANIFEST_FILENAME, e)) } } diff --git a/package/src/root/readme.rs b/package/src/root/readme.rs index 69bd002cdb..3cea5acf5e 100644 --- a/package/src/root/readme.rs +++ b/package/src/root/readme.rs @@ -17,7 +17,7 @@ //! The `README.md` file. -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{borrow::Cow, fs::File, io::Write, path::Path}; @@ -54,10 +54,10 @@ impl README { path.to_mut().push(README_FILENAME); } - let mut file = File::create(&path).map_err(|e| PackageError::io_error_readme_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_readme_file(e))?; file.write_all(self.template().as_bytes()) - .map_err(|e| PackageError::io_error_readme_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_readme_file(e))?; Ok(()) } diff --git a/package/src/root/zip.rs b/package/src/root/zip.rs index 0878501318..c2a131986c 100644 --- a/package/src/root/zip.rs +++ b/package/src/root/zip.rs @@ -30,7 +30,7 @@ use crate::{ root::{MANIFEST_FILENAME, README_FILENAME}, source::{SOURCE_DIRECTORY_NAME, SOURCE_FILE_EXTENSION}, }; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{ @@ -83,7 +83,7 @@ impl ZipFile { // Create zip file let path = self.setup_file_path(src_dir); - let file = File::create(&path).map_err(|e| PackageError::failed_to_create_zip_file(e, new_backtrace()))?; + let file = File::create(&path).map_err(|e| PackageError::failed_to_create_zip_file(e))?; let mut zip = ZipWriter::new(file); let options = FileOptions::default() .compression_method(zip::CompressionMethod::Stored) @@ -108,13 +108,13 @@ impl ZipFile { tracing::info!("Adding file {:?} as {:?}", path, name); #[allow(deprecated)] zip.start_file_from_path(name, options) - .map_err(|e| PackageError::io_error_zip_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_zip_file(e))?; - let mut f = File::open(path).map_err(|e| PackageError::failed_to_open_zip_file(e, new_backtrace()))?; + let mut f = File::open(path).map_err(|e| PackageError::failed_to_open_zip_file(e))?; f.read_to_end(&mut buffer) - .map_err(|e| PackageError::failed_to_read_zip_file(e, new_backtrace()))?; + .map_err(|e| PackageError::failed_to_read_zip_file(e))?; zip.write_all(&*buffer) - .map_err(|e| PackageError::failed_to_write_zip_file(e, new_backtrace()))?; + .map_err(|e| PackageError::failed_to_write_zip_file(e))?; buffer.clear(); } else if !name.as_os_str().is_empty() { @@ -123,12 +123,11 @@ impl ZipFile { tracing::info!("Adding directory {:?} as {:?}", path, name); #[allow(deprecated)] zip.add_directory_from_path(name, options) - .map_err(|e| PackageError::io_error_zip_file(e, new_backtrace()))?; + .map_err(|e| PackageError::io_error_zip_file(e))?; } } - zip.finish() - .map_err(|e| PackageError::io_error_zip_file(e, new_backtrace()))?; + zip.finish().map_err(|e| PackageError::io_error_zip_file(e))?; tracing::info!("Package zip file created successfully {:?}", path); @@ -143,7 +142,7 @@ impl ZipFile { return Ok(false); } - fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_zip_file(path, new_backtrace()))?; + fs::remove_file(&path).map_err(|_| PackageError::failed_to_remove_zip_file(path))?; Ok(true) } diff --git a/package/src/source/directory.rs b/package/src/source/directory.rs index f11d086acf..1d906c1b0e 100644 --- a/package/src/source/directory.rs +++ b/package/src/source/directory.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use std::{ borrow::Cow, @@ -36,7 +36,7 @@ impl SourceDirectory { path.to_mut().push(SOURCE_DIRECTORY_NAME); } - fs::create_dir_all(&path).map_err(|e| PackageError::failed_to_create_source_directory(e, new_backtrace()))?; + fs::create_dir_all(&path).map_err(|e| PackageError::failed_to_create_source_directory(e))?; Ok(()) } @@ -45,37 +45,29 @@ impl SourceDirectory { let mut path = Cow::from(path); path.to_mut().push(SOURCE_DIRECTORY_NAME); - let directory = - fs::read_dir(&path).map_err(|e| PackageError::failed_to_read_inputs_directory(e, new_backtrace()))?; + let directory = fs::read_dir(&path).map_err(|e| PackageError::failed_to_read_inputs_directory(e))?; let mut file_paths = Vec::new(); for file_entry in directory.into_iter() { - let file_entry = - file_entry.map_err(|e| PackageError::failed_to_get_source_file_entry(e, new_backtrace()))?; + let file_entry = file_entry.map_err(|e| PackageError::failed_to_get_source_file_entry(e))?; let file_path = file_entry.path(); // Verify that the entry is structured as a valid file - let file_type = file_entry.file_type().map_err(|e| { - PackageError::failed_to_get_source_file_type(file_path.as_os_str().to_owned(), e, new_backtrace()) - })?; + let file_type = file_entry + .file_type() + .map_err(|e| PackageError::failed_to_get_source_file_type(file_path.as_os_str().to_owned(), e))?; if !file_type.is_file() { - return Err(PackageError::invalid_source_file_type( - file_path.as_os_str().to_owned(), - file_type, - new_backtrace(), - ) - .into()); + return Err(PackageError::invalid_source_file_type(file_path.as_os_str().to_owned(), file_type).into()); } // Verify that the file has the default file extension - let file_extension = file_path.extension().ok_or_else(|| { - PackageError::failed_to_get_source_file_extension(file_path.as_os_str().to_owned(), new_backtrace()) - })?; + let file_extension = file_path + .extension() + .ok_or_else(|| PackageError::failed_to_get_source_file_extension(file_path.as_os_str().to_owned()))?; if file_extension != SOURCE_FILE_EXTENSION.trim_start_matches('.') { return Err(PackageError::invalid_source_file_extension( file_path.as_os_str().to_owned(), file_extension.to_owned(), - new_backtrace(), ) .into()); } diff --git a/package/src/source/main.rs b/package/src/source/main.rs index 7c7ec52ffc..5d7f15bbf0 100644 --- a/package/src/source/main.rs +++ b/package/src/source/main.rs @@ -17,7 +17,7 @@ //! The `main.leo` file. use crate::source::directory::SOURCE_DIRECTORY_NAME; -use leo_errors::{new_backtrace, PackageError, Result}; +use leo_errors::{PackageError, Result}; use serde::Deserialize; use std::{borrow::Cow, fs::File, io::Write, path::Path}; @@ -60,10 +60,10 @@ impl MainFile { path.to_mut().push(MAIN_FILENAME); } - let mut file = File::create(&path).map_err(|e| PackageError::io_error_main_file(e, new_backtrace()))?; + let mut file = File::create(&path).map_err(|e| PackageError::io_error_main_file(e))?; Ok(file .write_all(self.template().as_bytes()) - .map_err(|e| PackageError::io_error_main_file(e, new_backtrace()))?) + .map_err(|e| PackageError::io_error_main_file(e))?) } fn template(&self) -> String { diff --git a/parser/src/parser/context.rs b/parser/src/parser/context.rs index 3e7d1375b6..af64bd9c43 100644 --- a/parser/src/parser/context.rs +++ b/parser/src/parser/context.rs @@ -18,7 +18,7 @@ use std::{borrow::Cow, unimplemented}; use crate::{assert_no_whitespace, tokenizer::*, Token, KEYWORD_TOKENS}; use leo_ast::*; -use leo_errors::{new_backtrace, LeoError, ParserError, Result, Span}; +use leo_errors::{LeoError, ParserError, Result, Span}; use tendril::format_tendril; /// Stores a program in tokenized format plus additional context. @@ -64,7 +64,7 @@ impl ParserContext { /// Returns an unexpected end of function [`SyntaxError`]. /// pub fn eof(&self) -> LeoError { - ParserError::unexpected_eof(&self.end_span, new_backtrace()).into() + ParserError::unexpected_eof(&self.end_span).into() } /// @@ -300,7 +300,7 @@ impl ParserContext { if &token == inner { Ok(self.tokens.pop().unwrap().span) } else { - Err(ParserError::unexpected(inner, token, span, new_backtrace()).into()) + Err(ParserError::unexpected(inner, token, span).into()) } } else { Err(self.eof()) @@ -319,7 +319,6 @@ impl ParserContext { inner, token.iter().map(|x| format!("'{}'", x)).collect::>().join(", "), span, - new_backtrace(), ) .into()); } @@ -362,7 +361,7 @@ impl ParserContext { unimplemented!() } } else { - Err(ParserError::unexpected_str(inner, "ident", span, new_backtrace()).into()) + Err(ParserError::unexpected_str(inner, "ident", span).into()) } } else { Err(self.eof()) diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 1d57d0c3c5..6ba5f20da5 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -16,7 +16,7 @@ use tendril::format_tendril; -use leo_errors::{new_backtrace, ParserError, Result}; +use leo_errors::{ParserError, Result}; use super::*; @@ -461,13 +461,7 @@ impl ParserContext { }); } else { let next = self.peek()?; - return Err(ParserError::unexpected_str( - &next.token, - "int or ident", - &next.span, - new_backtrace(), - ) - .into()); + return Err(ParserError::unexpected_str(&next.token, "int or ident", &next.span).into()); } } Token::LeftParen => { @@ -614,7 +608,7 @@ impl ParserContext { let first = match first { SpreadOrExpression::Spread(first) => { let span = span + first.span(); - return Err(ParserError::spread_in_array_init(&span, new_backtrace()).into()); + return Err(ParserError::spread_in_array_init(&span).into()); } SpreadOrExpression::Expression(x) => x, }; @@ -731,7 +725,7 @@ impl ParserContext { Expression::Identifier(ident) } token => { - return Err(ParserError::unexpected_str(token, "expression", &span, new_backtrace()).into()); + return Err(ParserError::unexpected_str(token, "expression", &span).into()); } }) } diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 2704b8af36..9de6602f17 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -16,7 +16,7 @@ use tendril::format_tendril; -use leo_errors::{new_backtrace, ParserError, Result}; +use leo_errors::{ParserError, Result}; use crate::KEYWORD_TOKENS; @@ -48,7 +48,7 @@ impl ParserContext { functions.insert(id, function); } Token::Ident(ident) if ident.as_ref() == "test" => { - return Err(ParserError::test_function(&token.span, new_backtrace()).into()); + return Err(ParserError::test_function(&token.span).into()); // self.expect(Token::Test)?; // let (id, function) = self.parse_function_declaration()?; // tests.insert(id, TestFunction { @@ -75,7 +75,6 @@ impl ParserContext { .collect::>() .join(", "), &token.span, - new_backtrace(), ) .into()); } @@ -98,7 +97,7 @@ impl ParserContext { let start = self.expect(Token::At)?; let name = self.expect_ident()?; if name.name.as_ref() == "context" { - return Err(ParserError::context_annotation(&name.span, new_backtrace()).into()); + return Err(ParserError::context_annotation(&name.span).into()); } assert_no_whitespace(&start, &name.span, &name.name, "@")?; @@ -118,7 +117,6 @@ impl ParserContext { .collect::>() .join(", "), &end.span, - new_backtrace(), ) .into()); } @@ -132,13 +130,7 @@ impl ParserContext { args.push(int.value); } else { let token = self.peek()?; - return Err(ParserError::unexpected_str( - &token.token, - "ident or int", - &token.span, - new_backtrace(), - ) - .into()); + return Err(ParserError::unexpected_str(&token.token, "ident or int", &token.span).into()); } if self.eat(Token::Comma).is_none() && !comma { end_span = self.expect(Token::RightParen)?; @@ -175,7 +167,7 @@ impl ParserContext { } if out.is_empty() { - return Err(ParserError::invalid_import_list(span, new_backtrace()).into()); + return Err(ParserError::invalid_import_list(span).into()); } Ok(out) @@ -254,7 +246,7 @@ impl ParserContext { // Return an error if the package name contains a keyword. if let Some(token) = KEYWORD_TOKENS.iter().find(|x| x.to_string() == base.name.as_ref()) { - return Err(ParserError::unexpected_str(token, "package name", &base.span, new_backtrace()).into()); + return Err(ParserError::unexpected_str(token, "package name", &base.span).into()); } // Return an error if the package name contains invalid characters. @@ -263,7 +255,7 @@ impl ParserContext { .chars() .all(|x| x.is_ascii_lowercase() || x.is_ascii_digit() || x == '-' || x == '_') { - return Err(ParserError::invalid_package_name(&base.span, new_backtrace()).into()); + return Err(ParserError::invalid_package_name(&base.span).into()); } // Return the package name. @@ -325,14 +317,14 @@ impl ParserContext { let peeked = &self.peek()?; if peeked.token == Token::Semicolon { if commas { - return Err(ParserError::mixed_commas_and_semicolons(&peeked.span, new_backtrace()).into()); + return Err(ParserError::mixed_commas_and_semicolons(&peeked.span).into()); } semi_colons = true; self.expect(Token::Semicolon)?; } else { if semi_colons { - return Err(ParserError::mixed_commas_and_semicolons(&peeked.span, new_backtrace()).into()); + return Err(ParserError::mixed_commas_and_semicolons(&peeked.span).into()); } commas = true; @@ -389,7 +381,6 @@ impl ParserContext { .collect::>() .join(", "), &peeked.span, - new_backtrace(), ) .into()); } @@ -444,7 +435,7 @@ impl ParserContext { } if let Some(mutable) = &mutable { - return Err(ParserError::mut_function_input(&(&mutable.span + &name.span), new_backtrace()).into()); + return Err(ParserError::mut_function_input(&(&mutable.span + &name.span)).into()); } self.expect(Token::Colon)?; diff --git a/parser/src/parser/mod.rs b/parser/src/parser/mod.rs index a7d16a4b54..cf6ae0e5fc 100644 --- a/parser/src/parser/mod.rs +++ b/parser/src/parser/mod.rs @@ -32,14 +32,14 @@ use std::unimplemented; use crate::{tokenizer::*, Token}; use indexmap::IndexMap; use leo_ast::*; -use leo_errors::{new_backtrace, ParserError, Result, Span}; +use leo_errors::{ParserError, Result, Span}; pub(crate) fn assert_no_whitespace(left_span: &Span, right_span: &Span, left: &str, right: &str) -> Result<()> { if left_span.col_stop != right_span.col_start { let mut error_span = left_span + right_span; error_span.col_start = left_span.col_stop - 1; error_span.col_stop = right_span.col_start - 1; - return Err(ParserError::unexpected_whitespace(left, right, &error_span, new_backtrace()).into()); + return Err(ParserError::unexpected_whitespace(left, right, &error_span).into()); } Ok(()) diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index 0f5b404dfa..c452549e62 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -16,7 +16,7 @@ use super::*; -use leo_errors::{new_backtrace, ParserError, Result}; +use leo_errors::{ParserError, Result}; const ASSIGN_TOKENS: &[Token] = &[ Token::Assign, @@ -64,7 +64,7 @@ impl ParserContext { accesses.push(AssigneeAccess::ArrayIndex(*expr.index)); } Expression::Identifier(id) => identifier = id, - _ => return Err(ParserError::invalid_assignment_target(expr.span(), new_backtrace()).into()), + _ => return Err(ParserError::invalid_assignment_target(expr.span()).into()), } Ok(identifier) } @@ -191,13 +191,7 @@ impl ParserContext { match s { Statement::Block(_) | Statement::Conditional(_) => Some(Box::new(s)), s => { - return Err(ParserError::unexpected_statement( - &s, - "Block or Conditional", - s.span(), - new_backtrace(), - ) - .into()); + return Err(ParserError::unexpected_statement(&s, "Block or Conditional", s.span()).into()); } } } else { @@ -251,7 +245,7 @@ impl ParserContext { chars } SpannedToken { token, span } => { - return Err(ParserError::unexpected_str(token, "formatted string", &span, new_backtrace()).into()); + return Err(ParserError::unexpected_str(token, "formatted string", &span).into()); } }; @@ -286,13 +280,7 @@ impl ParserContext { "error" => ConsoleFunction::Error(self.parse_console_args()?), "log" => ConsoleFunction::Log(self.parse_console_args()?), x => { - return Err(ParserError::unexpected_ident( - x, - &["assert", "error", "log"], - &function.span, - new_backtrace(), - ) - .into()); + return Err(ParserError::unexpected_ident(x, &["assert", "error", "log"], &function.span).into()); } }; self.expect(Token::RightParen)?; @@ -311,7 +299,7 @@ impl ParserContext { pub fn parse_variable_name(&mut self, span: &SpannedToken) -> Result { let mutable = self.eat(Token::Mut); if let Some(mutable) = &mutable { - return Err(ParserError::let_mut_statement(&(&mutable.span + &span.span), new_backtrace()).into()); + return Err(ParserError::let_mut_statement(&(&mutable.span + &span.span)).into()); } let name = self.expect_ident()?; diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs index 3cdb1bfcbc..e79cb494f4 100644 --- a/parser/src/parser/type_.rs +++ b/parser/src/parser/type_.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use super::*; -use leo_errors::{new_backtrace, ParserError, Result}; +use leo_errors::{ParserError, Result}; const TYPE_TOKENS: &[Token] = &[ Token::I8, @@ -69,7 +69,7 @@ impl ParserContext { dimensions.push(int); } else { let token = self.peek()?; - return Err(ParserError::unexpected_str(&token.token, "int", &token.span, new_backtrace()).into()); + return Err(ParserError::unexpected_str(&token.token, "int", &token.span).into()); } if self.eat(Token::Comma).is_none() { break; diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index dc072919fc..3ba21cd965 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -28,7 +28,7 @@ pub(crate) use self::token::*; pub(crate) mod lexer; pub(crate) use self::lexer::*; -use leo_errors::{new_backtrace, LeoError, ParserError, Span}; +use leo_errors::{LeoError, ParserError, Span}; use tendril::StrTendril; @@ -70,7 +70,7 @@ pub(crate) fn tokenize(path: &str, input: StrTendril) -> Result { if !check_address(address) { - return Err(ParserError::invalid_address_lit(address, &span, new_backtrace()).into()); + return Err(ParserError::invalid_address_lit(address, &span).into()); } } _ => (), @@ -96,7 +96,6 @@ pub(crate) fn tokenize(path: &str, input: StrTendril) -> Result