diff --git a/Cargo.lock b/Cargo.lock index d48955c81c..85e1eab4e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,6 +64,18 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base58" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" + +[[package]] +name = "bech32" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58946044516aa9dc922182e0d6e9d124a31aafe6b421614654eb27cf90cec09c" + [[package]] name = "bincode" version = "1.2.1" @@ -1192,6 +1204,8 @@ dependencies = [ name = "snarkos-errors" version = "0.8.0" dependencies = [ + "base58", + "bech32", "bincode", "curl", "hex", diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index be659587ce..90ba339810 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -18,10 +18,10 @@ pub enum CompilerError { #[error("Cannot read from the provided file path - {:?}", _0)] FileReadError(PathBuf), - #[error("Main function not found")] + #[error("`main` function not found")] NoMain, - #[error("Main must be a function")] + #[error("`main` must be a function")] NoMainFunction, #[error("{}", _0)] diff --git a/leo/errors/cli.rs b/leo/errors/cli.rs index 0beff09f8d..a1e4cb1957 100644 --- a/leo/errors/cli.rs +++ b/leo/errors/cli.rs @@ -3,67 +3,180 @@ use crate::errors::*; #[derive(Debug, Error)] pub enum CLIError { #[error("{}", _0)] - BuildError(#[from] BuildError), + BuildError(BuildError), #[error("{}: {}", _0, _1)] Crate(&'static str, String), #[error("{}", _0)] - ChecksumFileError(#[from] ChecksumFileError), + ChecksumFileError(ChecksumFileError), #[error("{}", _0)] - GitignoreError(#[from] GitignoreError), + GitignoreError(GitignoreError), #[error("{}", _0)] - InitError(#[from] InitError), + InitError(InitError), #[error("{}", _0)] - InputsDirectoryError(#[from] InputsDirectoryError), + InputsDirectoryError(InputsDirectoryError), #[error("{}", _0)] - InputsFileError(#[from] InputsFileError), + InputsFileError(InputsFileError), #[error("{}", _0)] - MainFileError(#[from] MainFileError), + MainFileError(MainFileError), #[error("{}", _0)] - ManifestError(#[from] ManifestError), + ManifestError(ManifestError), #[error("{}", _0)] - NewError(#[from] NewError), + NewError(NewError), #[error("{}", _0)] - OutputsDirectoryError(#[from] OutputsDirectoryError), + OutputsDirectoryError(OutputsDirectoryError), #[error("{}", _0)] - ProofFileError(#[from] ProofFileError), + ProofFileError(ProofFileError), #[error("{}", _0)] - ProvingKeyFileError(#[from] ProvingKeyFileError), + ProvingKeyFileError(ProvingKeyFileError), #[error("{}", _0)] - RunError(#[from] RunError), + RunError(RunError), #[error("{}", _0)] - SourceDirectoryError(#[from] SourceDirectoryError), + SourceDirectoryError(SourceDirectoryError), #[error("{}", _0)] - TestError(#[from] TestError), + TestError(TestError), #[error("{}", _0)] - VerificationKeyFileError(#[from] VerificationKeyFileError), + VerificationKeyFileError(VerificationKeyFileError), +} + +impl From for CLIError { + fn from(error: BuildError) -> Self { + log::error!("{}\n", error); + CLIError::BuildError(error) + } +} + +impl From for CLIError { + fn from(error: ChecksumFileError) -> Self { + log::error!("{}\n", error); + CLIError::ChecksumFileError(error) + } +} + +impl From for CLIError { + fn from(error: GitignoreError) -> Self { + log::error!("{}\n", error); + CLIError::GitignoreError(error) + } +} + +impl From for CLIError { + fn from(error: InitError) -> Self { + log::error!("{}\n", error); + CLIError::InitError(error) + } +} + +impl From for CLIError { + fn from(error: InputsDirectoryError) -> Self { + log::error!("{}\n", error); + CLIError::InputsDirectoryError(error) + } +} + +impl From for CLIError { + fn from(error: InputsFileError) -> Self { + log::error!("{}\n", error); + CLIError::InputsFileError(error) + } +} + +impl From for CLIError { + fn from(error: MainFileError) -> Self { + log::error!("{}\n", error); + CLIError::MainFileError(error) + } +} + +impl From for CLIError { + fn from(error: ManifestError) -> Self { + log::error!("{}\n", error); + CLIError::ManifestError(error) + } +} + +impl From for CLIError { + fn from(error: NewError) -> Self { + log::error!("{}\n", error); + CLIError::NewError(error) + } +} + +impl From for CLIError { + fn from(error: OutputsDirectoryError) -> Self { + log::error!("{}\n", error); + CLIError::OutputsDirectoryError(error) + } +} + +impl From for CLIError { + fn from(error: ProofFileError) -> Self { + log::error!("{}\n", error); + CLIError::ProofFileError(error) + } +} + +impl From for CLIError { + fn from(error: ProvingKeyFileError) -> Self { + log::error!("{}\n", error); + CLIError::ProvingKeyFileError(error) + } +} + +impl From for CLIError { + fn from(error: RunError) -> Self { + log::error!("{}\n", error); + CLIError::RunError(error) + } +} + +impl From for CLIError { + fn from(error: SourceDirectoryError) -> Self { + log::error!("{}\n", error); + CLIError::SourceDirectoryError(error) + } +} + +impl From for CLIError { + fn from(error: TestError) -> Self { + log::error!("{}\n", error); + CLIError::TestError(error) + } +} + +impl From for CLIError { + fn from(error: VerificationKeyFileError) -> Self { + log::error!("{}\n", error); + CLIError::VerificationKeyFileError(error) + } } impl From for CLIError { fn from(error: leo_compiler::errors::CompilerError) -> Self { - log::error!("{}", error); + log::error!("{}\n", error); CLIError::Crate("leo_compiler", "Program failed due to previous error".into()) } } impl From for CLIError { fn from(error: leo_inputs::errors::InputParserError) -> Self { - CLIError::Crate("leo_inputs", format!("{}", error)) + log::error!("{}\n", error); + CLIError::Crate("leo_inputs", "Program failed due to previous error".into()) } } diff --git a/types/src/errors/error.rs b/types/src/errors/error.rs index 04723c2cfa..4d2a7fdefa 100644 --- a/types/src/errors/error.rs +++ b/types/src/errors/error.rs @@ -2,6 +2,8 @@ use crate::Span; use std::{fmt, path::PathBuf}; +pub const INDENT: &'static str = " "; + /// Formatted compiler error type /// --> file.leo 2:8 /// | @@ -42,7 +44,6 @@ impl Error { } pub fn format(&self) -> String { - let indent = " ".to_string(); let path = self.path.as_ref().map(|path| format!("{}:", path)).unwrap_or_default(); let underline = underline(self.start, self.end); @@ -53,8 +54,8 @@ impl Error { {indent } | {underline}\n\ {indent } |\n\ {indent } = {message}", - indent = indent, - width = indent.len(), + indent = INDENT, + width = INDENT.len(), path = path, line = self.line, start = self.start,