mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
add file path to formatted errors
This commit is contained in:
parent
ea81f9bc98
commit
5bc1bc022d
@ -76,7 +76,12 @@ impl<F: Field + PrimeField, G: GroupType<F>> Compiler<F, G> {
|
|||||||
self,
|
self,
|
||||||
cs: &mut CS,
|
cs: &mut CS,
|
||||||
) -> Result<ConstrainedValue<F, G>, CompilerError> {
|
) -> Result<ConstrainedValue<F, G>, CompilerError> {
|
||||||
generate_constraints(cs, self.program, self.program_inputs.get_inputs())
|
let path = self.main_file_path;
|
||||||
|
generate_constraints(cs, self.program, self.program_inputs.get_inputs()).map_err(|mut error| {
|
||||||
|
error.set_path(path);
|
||||||
|
|
||||||
|
error
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile_test_constraints(self, cs: &mut TestConstraintSystem<F>) -> Result<(), CompilerError> {
|
pub fn compile_test_constraints(self, cs: &mut TestConstraintSystem<F>) -> Result<(), CompilerError> {
|
||||||
|
@ -40,9 +40,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
// * -> import all imports, circuits, functions in the current scope
|
// * -> import all imports, circuits, functions in the current scope
|
||||||
if import.is_star() {
|
if import.is_star() {
|
||||||
// recursively evaluate program statements
|
// recursively evaluate program statements
|
||||||
self.resolve_definitions(program).unwrap();
|
self.resolve_definitions(program)
|
||||||
|
|
||||||
Ok(())
|
|
||||||
} else {
|
} else {
|
||||||
let program_name = program.name.clone();
|
let program_name = program.name.clone();
|
||||||
|
|
||||||
@ -67,7 +65,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
|||||||
|
|
||||||
match matched_function {
|
match matched_function {
|
||||||
Some((_function_name, function)) => ConstrainedValue::Function(None, function),
|
Some((_function_name, function)) => ConstrainedValue::Function(None, function),
|
||||||
None => return Err(ImportError::unknown_symbol(symbol, program_name)),
|
None => return Err(ImportError::unknown_symbol(symbol, program_name, file_path)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -27,3 +27,12 @@ pub enum CompilerError {
|
|||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
ParserError(#[from] ParserError),
|
ParserError(#[from] ParserError),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl CompilerError {
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
match self {
|
||||||
|
CompilerError::FunctionError(error) => error.set_path(path),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use leo_types::{Error as FormattedError, Span};
|
use leo_types::{Error as FormattedError, Span};
|
||||||
|
|
||||||
use snarkos_errors::gadgets::SynthesisError;
|
use snarkos_errors::gadgets::SynthesisError;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum BooleanError {
|
pub enum BooleanError {
|
||||||
@ -9,6 +10,12 @@ pub enum BooleanError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BooleanError {
|
impl BooleanError {
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
match self {
|
||||||
|
BooleanError::Error(error) => error.set_path(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_from_span(message: String, span: Span) -> Self {
|
fn new_from_span(message: String, span: Span) -> Self {
|
||||||
BooleanError::Error(FormattedError::new_from_span(message, span))
|
BooleanError::Error(FormattedError::new_from_span(message, span))
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ use crate::errors::{BooleanError, FieldError, FunctionError, GroupError, ValueEr
|
|||||||
use leo_types::{Error as FormattedError, Identifier, IntegerError, Span};
|
use leo_types::{Error as FormattedError, Identifier, IntegerError, Span};
|
||||||
|
|
||||||
use snarkos_errors::gadgets::SynthesisError;
|
use snarkos_errors::gadgets::SynthesisError;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ExpressionError {
|
pub enum ExpressionError {
|
||||||
@ -11,9 +12,6 @@ pub enum ExpressionError {
|
|||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
Error(#[from] FormattedError),
|
Error(#[from] FormattedError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
|
||||||
IntegerError(#[from] IntegerError),
|
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
FieldError(#[from] FieldError),
|
FieldError(#[from] FieldError),
|
||||||
|
|
||||||
@ -23,11 +21,26 @@ pub enum ExpressionError {
|
|||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
GroupError(#[from] GroupError),
|
GroupError(#[from] GroupError),
|
||||||
|
|
||||||
|
#[error("{}", _0)]
|
||||||
|
IntegerError(#[from] IntegerError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
ValueError(#[from] ValueError),
|
ValueError(#[from] ValueError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExpressionError {
|
impl ExpressionError {
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
match self {
|
||||||
|
ExpressionError::BooleanError(error) => error.set_path(path),
|
||||||
|
ExpressionError::Error(error) => error.set_path(path),
|
||||||
|
ExpressionError::FieldError(error) => error.set_path(path),
|
||||||
|
ExpressionError::FunctionError(error) => error.set_path(path),
|
||||||
|
ExpressionError::GroupError(error) => error.set_path(path),
|
||||||
|
ExpressionError::IntegerError(error) => error.set_path(path),
|
||||||
|
ExpressionError::ValueError(error) => error.set_path(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_from_span(message: String, span: Span) -> Self {
|
fn new_from_span(message: String, span: Span) -> Self {
|
||||||
ExpressionError::Error(FormattedError::new_from_span(message, span))
|
ExpressionError::Error(FormattedError::new_from_span(message, span))
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use leo_types::{Error as FormattedError, Span};
|
use leo_types::{Error as FormattedError, Span};
|
||||||
|
|
||||||
use snarkos_errors::gadgets::SynthesisError;
|
use snarkos_errors::gadgets::SynthesisError;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum FieldError {
|
pub enum FieldError {
|
||||||
@ -9,6 +10,12 @@ pub enum FieldError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FieldError {
|
impl FieldError {
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
match self {
|
||||||
|
FieldError::Error(error) => error.set_path(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_from_span(message: String, span: Span) -> Self {
|
fn new_from_span(message: String, span: Span) -> Self {
|
||||||
FieldError::Error(FormattedError::new_from_span(message, span))
|
FieldError::Error(FormattedError::new_from_span(message, span))
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::errors::{BooleanError, ExpressionError, FieldError, GroupError, StatementError, ValueError};
|
use crate::errors::{BooleanError, ExpressionError, FieldError, GroupError, StatementError, ValueError};
|
||||||
use leo_types::{Error as FormattedError, IntegerError, Span};
|
use leo_types::{Error as FormattedError, IntegerError, Span};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum FunctionError {
|
pub enum FunctionError {
|
||||||
@ -29,6 +30,19 @@ pub enum FunctionError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FunctionError {
|
impl FunctionError {
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
match self {
|
||||||
|
FunctionError::BooleanError(error) => error.set_path(path),
|
||||||
|
FunctionError::ExpressionError(error) => error.set_path(path),
|
||||||
|
FunctionError::Error(error) => error.set_path(path),
|
||||||
|
FunctionError::FieldError(error) => error.set_path(path),
|
||||||
|
FunctionError::GroupError(error) => error.set_path(path),
|
||||||
|
FunctionError::IntegerError(error) => error.set_path(path),
|
||||||
|
FunctionError::StatementError(error) => error.set_path(path),
|
||||||
|
FunctionError::ValueError(error) => error.set_path(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_from_span(message: String, span: Span) -> Self {
|
fn new_from_span(message: String, span: Span) -> Self {
|
||||||
FunctionError::Error(FormattedError::new_from_span(message, span))
|
FunctionError::Error(FormattedError::new_from_span(message, span))
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use leo_types::{Error as FormattedError, Span};
|
use leo_types::{Error as FormattedError, Span};
|
||||||
|
|
||||||
use snarkos_errors::gadgets::SynthesisError;
|
use snarkos_errors::gadgets::SynthesisError;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum GroupError {
|
pub enum GroupError {
|
||||||
@ -9,6 +10,12 @@ pub enum GroupError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl GroupError {
|
impl GroupError {
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
match self {
|
||||||
|
GroupError::Error(error) => error.set_path(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_from_span(message: String, span: Span) -> Self {
|
fn new_from_span(message: String, span: Span) -> Self {
|
||||||
GroupError::Error(FormattedError::new_from_span(message, span))
|
GroupError::Error(FormattedError::new_from_span(message, span))
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use leo_ast::ParserError;
|
use leo_ast::ParserError;
|
||||||
use leo_types::{Error as FormattedError, ImportSymbol, Span};
|
use leo_types::{Error as FormattedError, ImportSymbol, Span};
|
||||||
|
|
||||||
use std::io;
|
use std::{io, path::PathBuf};
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ImportError {
|
pub enum ImportError {
|
||||||
@ -23,9 +23,12 @@ impl ImportError {
|
|||||||
Self::new_from_span(message, span)
|
Self::new_from_span(message, span)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn unknown_symbol(symbol: ImportSymbol, file: String) -> Self {
|
pub fn unknown_symbol(symbol: ImportSymbol, file: String, file_path: &PathBuf) -> Self {
|
||||||
let message = format!("cannot find imported symbol `{}` in imported file `{}`", symbol, file);
|
let message = format!("cannot find imported symbol `{}` in imported file `{}`", symbol, file);
|
||||||
|
let mut error = FormattedError::new_from_span(message, symbol.span);
|
||||||
|
|
||||||
Self::new_from_span(message, symbol.span)
|
error.path = Some(format!("{:?}", file_path));
|
||||||
|
|
||||||
|
ImportError::Error(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::errors::{BooleanError, ExpressionError, ValueError};
|
use crate::errors::{BooleanError, ExpressionError, ValueError};
|
||||||
use leo_types::{Error as FormattedError, IntegerError, Span};
|
use leo_types::{Error as FormattedError, IntegerError, Span};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum StatementError {
|
pub enum StatementError {
|
||||||
@ -20,6 +21,16 @@ pub enum StatementError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl StatementError {
|
impl StatementError {
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
match self {
|
||||||
|
StatementError::BooleanError(error) => error.set_path(path),
|
||||||
|
StatementError::Error(error) => error.set_path(path),
|
||||||
|
StatementError::ExpressionError(error) => error.set_path(path),
|
||||||
|
StatementError::IntegerError(error) => error.set_path(path),
|
||||||
|
StatementError::ValueError(error) => error.set_path(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_from_span(message: String, span: Span) -> Self {
|
fn new_from_span(message: String, span: Span) -> Self {
|
||||||
StatementError::Error(FormattedError::new_from_span(message, span))
|
StatementError::Error(FormattedError::new_from_span(message, span))
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::errors::{BooleanError, FieldError, GroupError};
|
use crate::errors::{BooleanError, FieldError, GroupError};
|
||||||
use leo_types::{Error as FormattedError, IntegerError, Span};
|
use leo_types::{Error as FormattedError, IntegerError, Span};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum ValueError {
|
pub enum ValueError {
|
||||||
@ -20,6 +21,16 @@ pub enum ValueError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ValueError {
|
impl ValueError {
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
match self {
|
||||||
|
ValueError::BooleanError(error) => error.set_path(path),
|
||||||
|
ValueError::Error(error) => error.set_path(path),
|
||||||
|
ValueError::FieldError(error) => error.set_path(path),
|
||||||
|
ValueError::GroupError(error) => error.set_path(path),
|
||||||
|
ValueError::IntegerError(error) => error.set_path(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_from_span(message: String, span: Span) -> Self {
|
fn new_from_span(message: String, span: Span) -> Self {
|
||||||
ValueError::Error(FormattedError::new_from_span(message, span))
|
ValueError::Error(FormattedError::new_from_span(message, span))
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ fn output_multi(program: EdwardsTestCompiler) {
|
|||||||
fn fail_array(program: EdwardsTestCompiler) {
|
fn fail_array(program: EdwardsTestCompiler) {
|
||||||
match get_error(program) {
|
match get_error(program) {
|
||||||
CompilerError::FunctionError(FunctionError::Error(_string)) => {}
|
CompilerError::FunctionError(FunctionError::Error(_string)) => {}
|
||||||
error => panic!("Expected invalid array error, got {}", error),
|
error => panic!("Expected function error, found {}", error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ use leo_compiler::{
|
|||||||
|
|
||||||
use snarkos_curves::edwards_bls12::Fq;
|
use snarkos_curves::edwards_bls12::Fq;
|
||||||
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
use snarkos_models::gadgets::r1cs::TestConstraintSystem;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub type EdwardsTestCompiler = Compiler<Fq, EdwardsGroupType>;
|
pub type EdwardsTestCompiler = Compiler<Fq, EdwardsGroupType>;
|
||||||
pub type EdwardsConstrainedValue = ConstrainedValue<Fq, EdwardsGroupType>;
|
pub type EdwardsConstrainedValue = ConstrainedValue<Fq, EdwardsGroupType>;
|
||||||
@ -45,8 +46,11 @@ pub(crate) fn fail_enforce(program: EdwardsTestCompiler) {
|
|||||||
|
|
||||||
fn new_compiler() -> EdwardsTestCompiler {
|
fn new_compiler() -> EdwardsTestCompiler {
|
||||||
let program_name = "test".to_string();
|
let program_name = "test".to_string();
|
||||||
|
let path = PathBuf::from("/test/src/main.leo");
|
||||||
|
let mut compiler = EdwardsTestCompiler::new(program_name);
|
||||||
|
compiler.set_path(path);
|
||||||
|
|
||||||
EdwardsTestCompiler::new(program_name)
|
compiler
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_program(bytes: &[u8]) -> Result<EdwardsTestCompiler, CompilerError> {
|
pub(crate) fn parse_program(bytes: &[u8]) -> Result<EdwardsTestCompiler, CompilerError> {
|
||||||
|
@ -25,10 +25,11 @@ fn test_undefined() {
|
|||||||
CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError(
|
CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError(
|
||||||
ExpressionError::Error(error),
|
ExpressionError::Error(error),
|
||||||
))) => {
|
))) => {
|
||||||
|
println!("{}", error);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{}", error),
|
format!("{}", error),
|
||||||
vec![
|
vec![
|
||||||
" --> 2:10",
|
" --> \"/test/src/main.leo\": 2:10",
|
||||||
" |",
|
" |",
|
||||||
" 2 | return a",
|
" 2 | return a",
|
||||||
" | ^",
|
" | ^",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::Span;
|
use crate::Span;
|
||||||
|
|
||||||
use std::fmt;
|
use std::{fmt, path::PathBuf};
|
||||||
|
|
||||||
/// Formatted compiler error type
|
/// Formatted compiler error type
|
||||||
/// --> file.leo 2:8
|
/// --> file.leo 2:8
|
||||||
@ -37,6 +37,10 @@ impl Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
self.path = Some(format!("{:?}", path));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn format(&self) -> String {
|
pub fn format(&self) -> String {
|
||||||
let indent = " ".to_string();
|
let indent = " ".to_string();
|
||||||
let path = self.path.as_ref().map(|path| format!("{}:", path)).unwrap_or_default();
|
let path = self.path.as_ref().map(|path| format!("{}:", path)).unwrap_or_default();
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
use crate::{error::Error as FormattedError, Span};
|
use crate::{error::Error as FormattedError, Span};
|
||||||
|
|
||||||
use snarkos_errors::gadgets::SynthesisError;
|
use snarkos_errors::gadgets::SynthesisError;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum IntegerError {
|
pub enum IntegerError {
|
||||||
@ -9,6 +10,12 @@ pub enum IntegerError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl IntegerError {
|
impl IntegerError {
|
||||||
|
pub fn set_path(&mut self, path: PathBuf) {
|
||||||
|
match self {
|
||||||
|
IntegerError::Error(error) => error.set_path(path),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn new_from_span(message: String, span: Span) -> Self {
|
fn new_from_span(message: String, span: Span) -> Self {
|
||||||
IntegerError::Error(FormattedError::new_from_span(message, span))
|
IntegerError::Error(FormattedError::new_from_span(message, span))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user