diff --git a/Cargo.lock b/Cargo.lock index 266888918d..52a8c8399d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -478,7 +478,6 @@ dependencies = [ "clap", "colored", "env_logger", - "failure", "from-pest", "leo-compiler", "log", @@ -493,6 +492,7 @@ dependencies = [ "snarkos-models", "snarkos-utilities", "structopt", + "thiserror", "toml", ] diff --git a/Cargo.toml b/Cargo.toml index 687cde3ae9..a0a065c435 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,6 @@ snarkos-utilities = { path = "../snarkOS/utilities", version = "0.8.0" } clap = { version = "2.33.0" } colored = { version = "1.9" } env_logger = { version = "0.7" } -failure = { version = "0.1.5" } from-pest = { version = "0.3.1" } log = { version = "0.4" } rand = { version = "0.7" } @@ -37,3 +36,4 @@ serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0" } structopt = { version = "0.3.14" } toml = { version = "0.5" } +thiserror = { version = "1.0" } diff --git a/leo/commands/build.rs b/leo/commands/build.rs index e5575ad973..a8447bfba8 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -88,8 +88,8 @@ impl CLI for BuildCommand { // bt: vec![], // ct: vec![], // }; - program.evaluate_program::>()?; } + program.evaluate_program::>()?; log::info!("Compiled program in {:?}", main_file_path); diff --git a/leo/errors/cli.rs b/leo/errors/cli.rs index 28e909a3d0..be0a8f3cfd 100644 --- a/leo/errors/cli.rs +++ b/leo/errors/cli.rs @@ -1,47 +1,47 @@ use crate::errors::*; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum CLIError { - #[fail(display = "{}", _0)] + #[error("{}", _0)] BuildError(BuildError), - #[fail(display = "{}: {}", _0, _1)] + #[error("{}: {}", _0, _1)] Crate(&'static str, String), - #[fail(display = "{}", _0)] + #[error("{}", _0)] ChecksumFileError(ChecksumFileError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] InitError(InitError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] InputsDirectoryError(InputsDirectoryError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] MainFileError(MainFileError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] ManifestError(ManifestError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] NewError(NewError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] OutputsDirectoryError(OutputsDirectoryError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] ProofFileError(ProofFileError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] ProvingKeyFileError(ProvingKeyFileError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] RunError(RunError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] SourceDirectoryError(SourceDirectoryError), - #[fail(display = "{}", _0)] + #[error("{}", _0)] VerificationKeyFileError(VerificationKeyFileError), } diff --git a/leo/errors/commands/build.rs b/leo/errors/commands/build.rs index dc302e2010..e6a6b76f1f 100644 --- a/leo/errors/commands/build.rs +++ b/leo/errors/commands/build.rs @@ -2,12 +2,12 @@ use crate::errors::ManifestError; use std::ffi::OsString; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum BuildError { - #[fail(display = "main file {:?} does not exist", _0)] + #[error("main file {:?} does not exist", _0)] MainFileDoesNotExist(OsString), - #[fail(display = "{}", _0)] + #[error("{}", _0)] ManifestError(ManifestError), } diff --git a/leo/errors/commands/init.rs b/leo/errors/commands/init.rs index 5d8c9c118e..c31f2dffdd 100644 --- a/leo/errors/commands/init.rs +++ b/leo/errors/commands/init.rs @@ -3,21 +3,21 @@ use crate::errors::ManifestError; use std::ffi::OsString; use std::io; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum InitError { - #[fail(display = "root directory {:?} creating: {}", _0, _1)] + #[error("root directory {:?} creating: {}", _0, _1)] CreatingRootDirectory(OsString, io::Error), - #[fail(display = "directory {:?} does not exist", _0)] + #[error("directory {:?} does not exist", _0)] DirectoryDoesNotExist(OsString), - #[fail(display = "{}", _0)] + #[error("{}", _0)] ManifestError(ManifestError), - #[fail(display = "package at path {:?} already exists", _0)] + #[error("package at path {:?} already exists", _0)] PackageAlreadyExists(OsString), - #[fail(display = "package name is missing - {:?}", _0)] + #[error("package name is missing - {:?}", _0)] ProjectNameInvalid(OsString), } diff --git a/leo/errors/commands/new.rs b/leo/errors/commands/new.rs index e420d648ca..cdaad80598 100644 --- a/leo/errors/commands/new.rs +++ b/leo/errors/commands/new.rs @@ -3,21 +3,21 @@ use crate::errors::ManifestError; use std::ffi::OsString; use std::io; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum NewError { - #[fail(display = "root directory {:?} creating: {}", _0, _1)] + #[error("root directory {:?} creating: {}", _0, _1)] CreatingRootDirectory(OsString, io::Error), - #[fail(display = "directory {:?} already exists", _0)] + #[error("directory {:?} already exists", _0)] DirectoryAlreadyExists(OsString), - #[fail(display = "{}", _0)] + #[error("{}", _0)] ManifestError(ManifestError), - #[fail(display = "package at path {:?} already exists", _0)] + #[error("package at path {:?} already exists", _0)] PackageAlreadyExists(OsString), - #[fail(display = "package name is missing - {:?}", _0)] + #[error("package name is missing - {:?}", _0)] ProjectNameInvalid(OsString), } diff --git a/leo/errors/commands/run.rs b/leo/errors/commands/run.rs index ab23f3be90..d03f954af3 100644 --- a/leo/errors/commands/run.rs +++ b/leo/errors/commands/run.rs @@ -2,12 +2,12 @@ use crate::errors::ManifestError; use std::ffi::OsString; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum RunError { - #[fail(display = "main file {:?} does not exist", _0)] + #[error("main file {:?} does not exist", _0)] MainFileDoesNotExist(OsString), - #[fail(display = "{}", _0)] + #[error("{}", _0)] ManifestError(ManifestError), } diff --git a/leo/errors/directory/inputs.rs b/leo/errors/directory/inputs.rs index 38e92b335f..398271b2fd 100644 --- a/leo/errors/directory/inputs.rs +++ b/leo/errors/directory/inputs.rs @@ -1,25 +1,25 @@ use std::{ffi::OsString, fs::FileType, io}; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum InputsDirectoryError { - #[fail(display = "creating: {}", _0)] + #[error("creating: {}", _0)] Creating(io::Error), - #[fail(display = "file entry getting: {}", _0)] + #[error("file entry getting: {}", _0)] GettingFileEntry(io::Error), - #[fail(display = "file {:?} extension getting", _0)] + #[error("file {:?} extension getting", _0)] GettingFileExtension(OsString), - #[fail(display = "file {:?} type getting: {}", _0, _1)] + #[error("file {:?} type getting: {}", _0, _1)] GettingFileType(OsString, io::Error), - #[fail(display = "invalid file {:?} extension: {:?}", _0, _1)] + #[error("invalid file {:?} extension: {:?}", _0, _1)] InvalidFileExtension(OsString, OsString), - #[fail(display = "invalid file {:?} type: {:?}", _0, _1)] + #[error("invalid file {:?} type: {:?}", _0, _1)] InvalidFileType(OsString, FileType), - #[fail(display = "reading: {}", _0)] + #[error("reading: {}", _0)] Reading(io::Error), } diff --git a/leo/errors/directory/outputs.rs b/leo/errors/directory/outputs.rs index 156dd866af..7742fff615 100644 --- a/leo/errors/directory/outputs.rs +++ b/leo/errors/directory/outputs.rs @@ -1,28 +1,28 @@ use std::{ffi::OsString, fs::FileType, io}; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum OutputsDirectoryError { - #[fail(display = "creating: {}", _0)] + #[error("creating: {}", _0)] Creating(io::Error), - #[fail(display = "file entry getting: {}", _0)] + #[error("file entry getting: {}", _0)] GettingFileEntry(io::Error), - #[fail(display = "file {:?} extension getting", _0)] + #[error("file {:?} extension getting", _0)] GettingFileExtension(OsString), - #[fail(display = "file {:?} type getting: {}", _0, _1)] + #[error("file {:?} type getting: {}", _0, _1)] GettingFileType(OsString, io::Error), - #[fail(display = "invalid file {:?} extension: {:?}", _0, _1)] + #[error("invalid file {:?} extension: {:?}", _0, _1)] InvalidFileExtension(OsString, OsString), - #[fail(display = "invalid file {:?} type: {:?}", _0, _1)] + #[error("invalid file {:?} type: {:?}", _0, _1)] InvalidFileType(OsString, FileType), - #[fail(display = "reading: {}", _0)] + #[error("reading: {}", _0)] Reading(io::Error), - #[fail(display = "removing: {}", _0)] + #[error("removing: {}", _0)] Removing(io::Error), } diff --git a/leo/errors/directory/source.rs b/leo/errors/directory/source.rs index bbfc7394f3..984969e1cc 100644 --- a/leo/errors/directory/source.rs +++ b/leo/errors/directory/source.rs @@ -1,25 +1,25 @@ use std::{ffi::OsString, fs::FileType, io}; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum SourceDirectoryError { - #[fail(display = "creating: {}", _0)] + #[error("creating: {}", _0)] Creating(io::Error), - #[fail(display = "file entry getting: {}", _0)] + #[error("file entry getting: {}", _0)] GettingFileEntry(io::Error), - #[fail(display = "file {:?} extension getting", _0)] + #[error("file {:?} extension getting", _0)] GettingFileExtension(OsString), - #[fail(display = "file {:?} type getting: {}", _0, _1)] + #[error("file {:?} type getting: {}", _0, _1)] GettingFileType(OsString, io::Error), - #[fail(display = "invalid file {:?} extension: {:?}", _0, _1)] + #[error("invalid file {:?} extension: {:?}", _0, _1)] InvalidFileExtension(OsString, OsString), - #[fail(display = "invalid file {:?} type: {:?}", _0, _1)] + #[error("invalid file {:?} type: {:?}", _0, _1)] InvalidFileType(OsString, FileType), - #[fail(display = "reading: {}", _0)] + #[error("reading: {}", _0)] Reading(io::Error), } diff --git a/leo/errors/files/checksum.rs b/leo/errors/files/checksum.rs index b60fe67ea0..b2b00db40f 100644 --- a/leo/errors/files/checksum.rs +++ b/leo/errors/files/checksum.rs @@ -1,18 +1,18 @@ use std::io; use std::path::PathBuf; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum ChecksumFileError { - #[fail(display = "{}: {}", _0, _1)] + #[error("{}: {}", _0, _1)] Crate(&'static str, String), - #[fail(display = "creating: {}", _0)] + #[error("creating: {}", _0)] Creating(io::Error), - #[fail(display = "Cannot read from the provided file path - {:?}", _0)] + #[error("Cannot read from the provided file path - {:?}", _0)] FileReadError(PathBuf), - #[fail(display = "writing: {}", _0)] + #[error("writing: {}", _0)] Writing(io::Error), } diff --git a/leo/errors/files/main.rs b/leo/errors/files/main.rs index 4a10c35bcd..b11527bf95 100644 --- a/leo/errors/files/main.rs +++ b/leo/errors/files/main.rs @@ -1,14 +1,14 @@ use std::io; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum MainFileError { - #[fail(display = "{}: {}", _0, _1)] + #[error("{}: {}", _0, _1)] Crate(&'static str, String), - #[fail(display = "creating: {}", _0)] + #[error("creating: {}", _0)] Creating(io::Error), - #[fail(display = "writing: {}", _0)] + #[error("writing: {}", _0)] Writing(io::Error), } diff --git a/leo/errors/files/proof.rs b/leo/errors/files/proof.rs index 6f866463c4..5d0ab39611 100644 --- a/leo/errors/files/proof.rs +++ b/leo/errors/files/proof.rs @@ -1,18 +1,18 @@ use std::io; use std::path::PathBuf; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum ProofFileError { - #[fail(display = "{}: {}", _0, _1)] + #[error("{}: {}", _0, _1)] Crate(&'static str, String), - #[fail(display = "creating: {}", _0)] + #[error("creating: {}", _0)] Creating(io::Error), - #[fail(display = "Cannot read from the provided file path - {:?}", _0)] + #[error("Cannot read from the provided file path - {:?}", _0)] FileReadError(PathBuf), - #[fail(display = "writing: {}", _0)] + #[error("writing: {}", _0)] Writing(io::Error), } diff --git a/leo/errors/files/proving_key.rs b/leo/errors/files/proving_key.rs index bf88916588..7c2b67558f 100644 --- a/leo/errors/files/proving_key.rs +++ b/leo/errors/files/proving_key.rs @@ -1,18 +1,18 @@ use std::io; use std::path::PathBuf; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum ProvingKeyFileError { - #[fail(display = "{}: {}", _0, _1)] + #[error("{}: {}", _0, _1)] Crate(&'static str, String), - #[fail(display = "creating: {}", _0)] + #[error("creating: {}", _0)] Creating(io::Error), - #[fail(display = "Cannot read from the provided file path - {:?}", _0)] + #[error("Cannot read from the provided file path - {:?}", _0)] FileReadError(PathBuf), - #[fail(display = "writing: {}", _0)] + #[error("writing: {}", _0)] Writing(io::Error), } diff --git a/leo/errors/files/verification_key.rs b/leo/errors/files/verification_key.rs index f1f0586019..5725ade273 100644 --- a/leo/errors/files/verification_key.rs +++ b/leo/errors/files/verification_key.rs @@ -1,21 +1,21 @@ use std::io; use std::path::PathBuf; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum VerificationKeyFileError { - #[fail(display = "{}: {}", _0, _1)] + #[error("{}: {}", _0, _1)] Crate(&'static str, String), - #[fail(display = "creating: {}", _0)] + #[error("creating: {}", _0)] Creating(io::Error), - #[fail(display = "Cannot read from the provided file path - {:?}", _0)] + #[error("Cannot read from the provided file path - {:?}", _0)] FileReadError(PathBuf), - #[fail(display = "Verification key file was corrupted")] + #[error("Verification key file was corrupted")] IncorrectVerificationKey, - #[fail(display = "writing: {}", _0)] + #[error("writing: {}", _0)] Writing(io::Error), } diff --git a/leo/errors/manifest.rs b/leo/errors/manifest.rs index 7520d70005..6ffe9d4a8d 100644 --- a/leo/errors/manifest.rs +++ b/leo/errors/manifest.rs @@ -1,22 +1,22 @@ use std::io; -#[derive(Debug, Fail)] +#[derive(Debug, Error)] pub enum ManifestError { - #[fail(display = "`{}` creating: {}", _0, _1)] + #[error("`{}` creating: {}", _0, _1)] Creating(&'static str, io::Error), - #[fail(display = "`{}` metadata: {}", _0, _1)] + #[error("`{}` metadata: {}", _0, _1)] Metadata(&'static str, io::Error), - #[fail(display = "`{}` opening: {}", _0, _1)] + #[error("`{}` opening: {}", _0, _1)] Opening(&'static str, io::Error), - #[fail(display = "`{}` parsing: {}", _0, _1)] + #[error("`{}` parsing: {}", _0, _1)] Parsing(&'static str, toml::de::Error), - #[fail(display = "`{}` reading: {}", _0, _1)] + #[error("`{}` reading: {}", _0, _1)] Reading(&'static str, io::Error), - #[fail(display = "`{}` writing: {}", _0, _1)] + #[error("`{}` writing: {}", _0, _1)] Writing(&'static str, io::Error), } diff --git a/leo/files/main.rs b/leo/files/main.rs index fb4936e20e..9209b41c89 100644 --- a/leo/files/main.rs +++ b/leo/files/main.rs @@ -49,8 +49,8 @@ impl MainFile { fn template(&self) -> String { format!( r#"// The '{}' main function. -function main() -> (u32) {{ - a = 1 + 1; +function main() -> u32 {{ + let a = 1 + 1; return a }} "#, diff --git a/leo/lib.rs b/leo/lib.rs index 55d29c86db..abd38d0f5e 100644 --- a/leo/lib.rs +++ b/leo/lib.rs @@ -1,5 +1,5 @@ #[macro_use] -extern crate failure; +extern crate thiserror; #[cfg_attr(tarpaulin, skip)] pub mod cli;