From e19f234d27e24fe7c4b1434dab98e9f8f5712465 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 4 Jun 2020 16:12:24 -0700 Subject: [PATCH] use from error macro in leo cli --- leo/errors/cli.rs | 112 +++++------------------------------ leo/errors/commands/build.rs | 8 +-- leo/errors/commands/init.rs | 8 +-- leo/errors/commands/new.rs | 8 +-- leo/errors/commands/run.rs | 8 +-- 5 files changed, 18 insertions(+), 126 deletions(-) diff --git a/leo/errors/cli.rs b/leo/errors/cli.rs index 1f36c8f092..f2ce79f2c1 100644 --- a/leo/errors/cli.rs +++ b/leo/errors/cli.rs @@ -3,133 +3,49 @@ use crate::errors::*; #[derive(Debug, Error)] pub enum CLIError { #[error("{}", _0)] - BuildError(BuildError), + BuildError(#[from] BuildError), #[error("{}: {}", _0, _1)] Crate(&'static str, String), #[error("{}", _0)] - ChecksumFileError(ChecksumFileError), + ChecksumFileError(#[from] ChecksumFileError), #[error("{}", _0)] - GitignoreError(GitignoreError), + GitignoreError(#[from] GitignoreError), #[error("{}", _0)] - InitError(InitError), + InitError(#[from] InitError), #[error("{}", _0)] - InputsDirectoryError(InputsDirectoryError), + InputsDirectoryError(#[from] InputsDirectoryError), #[error("{}", _0)] - MainFileError(MainFileError), + MainFileError(#[from] MainFileError), #[error("{}", _0)] - ManifestError(ManifestError), + ManifestError(#[from] ManifestError), #[error("{}", _0)] - NewError(NewError), + NewError(#[from] NewError), #[error("{}", _0)] - OutputsDirectoryError(OutputsDirectoryError), + OutputsDirectoryError(#[from] OutputsDirectoryError), #[error("{}", _0)] - ProofFileError(ProofFileError), + ProofFileError(#[from] ProofFileError), #[error("{}", _0)] - ProvingKeyFileError(ProvingKeyFileError), + ProvingKeyFileError(#[from] ProvingKeyFileError), #[error("{}", _0)] - RunError(RunError), + RunError(#[from] RunError), #[error("{}", _0)] - SourceDirectoryError(SourceDirectoryError), + SourceDirectoryError(#[from] SourceDirectoryError), #[error("{}", _0)] - VerificationKeyFileError(VerificationKeyFileError), -} - -impl From for CLIError { - fn from(error: BuildError) -> Self { - CLIError::BuildError(error) - } -} - -impl From for CLIError { - fn from(error: ChecksumFileError) -> Self { - CLIError::ChecksumFileError(error) - } -} - -impl From for CLIError { - fn from(error: GitignoreError) -> Self { - CLIError::GitignoreError(error) - } -} - -impl From for CLIError { - fn from(error: InitError) -> Self { - CLIError::InitError(error) - } -} - -impl From for CLIError { - fn from(error: InputsDirectoryError) -> Self { - CLIError::InputsDirectoryError(error) - } -} - -impl From for CLIError { - fn from(error: MainFileError) -> Self { - CLIError::MainFileError(error) - } -} - -impl From for CLIError { - fn from(error: ManifestError) -> Self { - CLIError::ManifestError(error) - } -} - -impl From for CLIError { - fn from(error: NewError) -> Self { - CLIError::NewError(error) - } -} - -impl From for CLIError { - fn from(error: OutputsDirectoryError) -> Self { - CLIError::OutputsDirectoryError(error) - } -} - -impl From for CLIError { - fn from(error: ProofFileError) -> Self { - CLIError::ProofFileError(error) - } -} - -impl From for CLIError { - fn from(error: ProvingKeyFileError) -> Self { - CLIError::ProvingKeyFileError(error) - } -} - -impl From for CLIError { - fn from(error: RunError) -> Self { - CLIError::RunError(error) - } -} - -impl From for CLIError { - fn from(error: SourceDirectoryError) -> Self { - CLIError::SourceDirectoryError(error) - } -} - -impl From for CLIError { - fn from(error: VerificationKeyFileError) -> Self { - CLIError::VerificationKeyFileError(error) - } + VerificationKeyFileError(#[from] VerificationKeyFileError), } impl From for CLIError { diff --git a/leo/errors/commands/build.rs b/leo/errors/commands/build.rs index e6a6b76f1f..3c7b4b7370 100644 --- a/leo/errors/commands/build.rs +++ b/leo/errors/commands/build.rs @@ -8,11 +8,5 @@ pub enum BuildError { MainFileDoesNotExist(OsString), #[error("{}", _0)] - ManifestError(ManifestError), -} - -impl From for BuildError { - fn from(error: ManifestError) -> Self { - BuildError::ManifestError(error) - } + ManifestError(#[from] ManifestError), } diff --git a/leo/errors/commands/init.rs b/leo/errors/commands/init.rs index c31f2dffdd..abada9aa21 100644 --- a/leo/errors/commands/init.rs +++ b/leo/errors/commands/init.rs @@ -12,7 +12,7 @@ pub enum InitError { DirectoryDoesNotExist(OsString), #[error("{}", _0)] - ManifestError(ManifestError), + ManifestError(#[from] ManifestError), #[error("package at path {:?} already exists", _0)] PackageAlreadyExists(OsString), @@ -20,9 +20,3 @@ pub enum InitError { #[error("package name is missing - {:?}", _0)] ProjectNameInvalid(OsString), } - -impl From for InitError { - fn from(error: ManifestError) -> Self { - InitError::ManifestError(error) - } -} diff --git a/leo/errors/commands/new.rs b/leo/errors/commands/new.rs index cdaad80598..d5bb6cfdea 100644 --- a/leo/errors/commands/new.rs +++ b/leo/errors/commands/new.rs @@ -12,7 +12,7 @@ pub enum NewError { DirectoryAlreadyExists(OsString), #[error("{}", _0)] - ManifestError(ManifestError), + ManifestError(#[from] ManifestError), #[error("package at path {:?} already exists", _0)] PackageAlreadyExists(OsString), @@ -20,9 +20,3 @@ pub enum NewError { #[error("package name is missing - {:?}", _0)] ProjectNameInvalid(OsString), } - -impl From for NewError { - fn from(error: ManifestError) -> Self { - NewError::ManifestError(error) - } -} diff --git a/leo/errors/commands/run.rs b/leo/errors/commands/run.rs index d03f954af3..ebd8931a5a 100644 --- a/leo/errors/commands/run.rs +++ b/leo/errors/commands/run.rs @@ -8,11 +8,5 @@ pub enum RunError { MainFileDoesNotExist(OsString), #[error("{}", _0)] - ManifestError(ManifestError), -} - -impl From for RunError { - fn from(error: ManifestError) -> Self { - RunError::ManifestError(error) - } + ManifestError(#[from] ManifestError), }