mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-24 18:52:58 +03:00
add formatting for cli errors
This commit is contained in:
parent
5bc1bc022d
commit
c2862c7a0c
14
Cargo.lock
generated
14
Cargo.lock
generated
@ -64,6 +64,18 @@ dependencies = [
|
|||||||
"rustc-demangle",
|
"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]]
|
[[package]]
|
||||||
name = "bincode"
|
name = "bincode"
|
||||||
version = "1.2.1"
|
version = "1.2.1"
|
||||||
@ -1192,6 +1204,8 @@ dependencies = [
|
|||||||
name = "snarkos-errors"
|
name = "snarkos-errors"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"base58",
|
||||||
|
"bech32",
|
||||||
"bincode",
|
"bincode",
|
||||||
"curl",
|
"curl",
|
||||||
"hex",
|
"hex",
|
||||||
|
@ -18,10 +18,10 @@ pub enum CompilerError {
|
|||||||
#[error("Cannot read from the provided file path - {:?}", _0)]
|
#[error("Cannot read from the provided file path - {:?}", _0)]
|
||||||
FileReadError(PathBuf),
|
FileReadError(PathBuf),
|
||||||
|
|
||||||
#[error("Main function not found")]
|
#[error("`main` function not found")]
|
||||||
NoMain,
|
NoMain,
|
||||||
|
|
||||||
#[error("Main must be a function")]
|
#[error("`main` must be a function")]
|
||||||
NoMainFunction,
|
NoMainFunction,
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
|
@ -3,67 +3,180 @@ use crate::errors::*;
|
|||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum CLIError {
|
pub enum CLIError {
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
BuildError(#[from] BuildError),
|
BuildError(BuildError),
|
||||||
|
|
||||||
#[error("{}: {}", _0, _1)]
|
#[error("{}: {}", _0, _1)]
|
||||||
Crate(&'static str, String),
|
Crate(&'static str, String),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
ChecksumFileError(#[from] ChecksumFileError),
|
ChecksumFileError(ChecksumFileError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
GitignoreError(#[from] GitignoreError),
|
GitignoreError(GitignoreError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
InitError(#[from] InitError),
|
InitError(InitError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
InputsDirectoryError(#[from] InputsDirectoryError),
|
InputsDirectoryError(InputsDirectoryError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
InputsFileError(#[from] InputsFileError),
|
InputsFileError(InputsFileError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
MainFileError(#[from] MainFileError),
|
MainFileError(MainFileError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
ManifestError(#[from] ManifestError),
|
ManifestError(ManifestError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
NewError(#[from] NewError),
|
NewError(NewError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
OutputsDirectoryError(#[from] OutputsDirectoryError),
|
OutputsDirectoryError(OutputsDirectoryError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
ProofFileError(#[from] ProofFileError),
|
ProofFileError(ProofFileError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
ProvingKeyFileError(#[from] ProvingKeyFileError),
|
ProvingKeyFileError(ProvingKeyFileError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
RunError(#[from] RunError),
|
RunError(RunError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
SourceDirectoryError(#[from] SourceDirectoryError),
|
SourceDirectoryError(SourceDirectoryError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
TestError(#[from] TestError),
|
TestError(TestError),
|
||||||
|
|
||||||
#[error("{}", _0)]
|
#[error("{}", _0)]
|
||||||
VerificationKeyFileError(#[from] VerificationKeyFileError),
|
VerificationKeyFileError(VerificationKeyFileError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<BuildError> for CLIError {
|
||||||
|
fn from(error: BuildError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::BuildError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ChecksumFileError> for CLIError {
|
||||||
|
fn from(error: ChecksumFileError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::ChecksumFileError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<GitignoreError> for CLIError {
|
||||||
|
fn from(error: GitignoreError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::GitignoreError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<InitError> for CLIError {
|
||||||
|
fn from(error: InitError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::InitError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<InputsDirectoryError> for CLIError {
|
||||||
|
fn from(error: InputsDirectoryError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::InputsDirectoryError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<InputsFileError> for CLIError {
|
||||||
|
fn from(error: InputsFileError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::InputsFileError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<MainFileError> for CLIError {
|
||||||
|
fn from(error: MainFileError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::MainFileError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ManifestError> for CLIError {
|
||||||
|
fn from(error: ManifestError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::ManifestError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<NewError> for CLIError {
|
||||||
|
fn from(error: NewError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::NewError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<OutputsDirectoryError> for CLIError {
|
||||||
|
fn from(error: OutputsDirectoryError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::OutputsDirectoryError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ProofFileError> for CLIError {
|
||||||
|
fn from(error: ProofFileError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::ProofFileError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ProvingKeyFileError> for CLIError {
|
||||||
|
fn from(error: ProvingKeyFileError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::ProvingKeyFileError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RunError> for CLIError {
|
||||||
|
fn from(error: RunError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::RunError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SourceDirectoryError> for CLIError {
|
||||||
|
fn from(error: SourceDirectoryError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::SourceDirectoryError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<TestError> for CLIError {
|
||||||
|
fn from(error: TestError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::TestError(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<VerificationKeyFileError> for CLIError {
|
||||||
|
fn from(error: VerificationKeyFileError) -> Self {
|
||||||
|
log::error!("{}\n", error);
|
||||||
|
CLIError::VerificationKeyFileError(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<leo_compiler::errors::CompilerError> for CLIError {
|
impl From<leo_compiler::errors::CompilerError> for CLIError {
|
||||||
fn from(error: leo_compiler::errors::CompilerError) -> Self {
|
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())
|
CLIError::Crate("leo_compiler", "Program failed due to previous error".into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<leo_inputs::errors::InputParserError> for CLIError {
|
impl From<leo_inputs::errors::InputParserError> for CLIError {
|
||||||
fn from(error: leo_inputs::errors::InputParserError) -> Self {
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ use crate::Span;
|
|||||||
|
|
||||||
use std::{fmt, path::PathBuf};
|
use std::{fmt, path::PathBuf};
|
||||||
|
|
||||||
|
pub const INDENT: &'static str = " ";
|
||||||
|
|
||||||
/// Formatted compiler error type
|
/// Formatted compiler error type
|
||||||
/// --> file.leo 2:8
|
/// --> file.leo 2:8
|
||||||
/// |
|
/// |
|
||||||
@ -42,7 +44,6 @@ impl Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn format(&self) -> String {
|
pub fn format(&self) -> 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();
|
||||||
let underline = underline(self.start, self.end);
|
let underline = underline(self.start, self.end);
|
||||||
|
|
||||||
@ -53,8 +54,8 @@ impl Error {
|
|||||||
{indent } | {underline}\n\
|
{indent } | {underline}\n\
|
||||||
{indent } |\n\
|
{indent } |\n\
|
||||||
{indent } = {message}",
|
{indent } = {message}",
|
||||||
indent = indent,
|
indent = INDENT,
|
||||||
width = indent.len(),
|
width = INDENT.len(),
|
||||||
path = path,
|
path = path,
|
||||||
line = self.line,
|
line = self.line,
|
||||||
start = self.start,
|
start = self.start,
|
||||||
|
Loading…
Reference in New Issue
Block a user