diff --git a/proxmox-api-macro/Cargo.toml b/proxmox-api-macro/Cargo.toml index 22ff94bf..863ecbeb 100644 --- a/proxmox-api-macro/Cargo.toml +++ b/proxmox-api-macro/Cargo.toml @@ -12,7 +12,7 @@ exclude = [ "debian" ] proc-macro = true [dependencies] -failure = "0.1" +anyhow = "1.0" proc-macro2 = "1.0" quote = "1.0" syn = { version = "1.0", features = [ "full", "visit-mut" ] } diff --git a/proxmox-api-macro/src/api.rs b/proxmox-api-macro/src/api.rs index 51a519ee..8beafed0 100644 --- a/proxmox-api-macro/src/api.rs +++ b/proxmox-api-macro/src/api.rs @@ -9,7 +9,7 @@ use std::convert::{TryFrom, TryInto}; -use failure::Error; +use anyhow::Error; use proc_macro2::{Span, TokenStream}; use quote::{quote, quote_spanned}; diff --git a/proxmox-api-macro/src/api/enums.rs b/proxmox-api-macro/src/api/enums.rs index 6a673fa5..2239882b 100644 --- a/proxmox-api-macro/src/api/enums.rs +++ b/proxmox-api-macro/src/api/enums.rs @@ -1,6 +1,6 @@ use std::convert::{TryFrom, TryInto}; -use failure::Error; +use anyhow::Error; use proc_macro2::{Ident, Span, TokenStream}; use quote::quote_spanned; diff --git a/proxmox-api-macro/src/api/method.rs b/proxmox-api-macro/src/api/method.rs index 730c92e7..bb3e0637 100644 --- a/proxmox-api-macro/src/api/method.rs +++ b/proxmox-api-macro/src/api/method.rs @@ -8,7 +8,7 @@ use std::convert::{TryFrom, TryInto}; use std::mem; -use failure::Error; +use anyhow::Error; use proc_macro2::{Span, TokenStream}; use quote::{quote, quote_spanned}; @@ -408,10 +408,10 @@ fn create_wrapper_function( // they have a default): // // Whether the parameter is optional should have been verified by the schema - // verifier already, so here we just use failure::bail! instead of building a + // verifier already, so here we just use anyhow::bail! instead of building a // proper http error! body.extend(quote_spanned! { span => - .ok_or_else(|| ::failure::format_err!( + .ok_or_else(|| ::anyhow::format_err!( "missing non-optional parameter: {}", #name_str, ))? @@ -460,7 +460,7 @@ fn create_wrapper_function( #body Ok(::serde_json::to_value(#func_name(#args) #await_keyword #question_mark)?) } else { - ::failure::bail!("api function wrapper called with a non-object json value"); + ::anyhow::bail!("api function wrapper called with a non-object json value"); } }; @@ -475,7 +475,7 @@ fn create_wrapper_function( // mut input_params: ::serde_json::Value, // api_method_param: &'static ::proxmox::api::ApiMethod, // rpc_env_param: &'a mut dyn ::proxmox::api::RpcEnvironment, - //) -> ::std::result::Result<::serde_json::Value, ::failure::Error> { + //) -> ::std::result::Result<::serde_json::Value, ::anyhow::Error> { // #body //} //::std::boxed::Box::pin(async move { @@ -490,7 +490,7 @@ fn create_wrapper_function( mut input_params: ::serde_json::Value, api_method_param: &::proxmox::api::ApiMethod, rpc_env_param: &mut dyn ::proxmox::api::RpcEnvironment, - ) -> ::std::result::Result<::serde_json::Value, ::failure::Error> { + ) -> ::std::result::Result<::serde_json::Value, ::anyhow::Error> { #body } }); diff --git a/proxmox-api-macro/src/api/structs.rs b/proxmox-api-macro/src/api/structs.rs index 3ccccb1e..93b1786b 100644 --- a/proxmox-api-macro/src/api/structs.rs +++ b/proxmox-api-macro/src/api/structs.rs @@ -13,7 +13,7 @@ use std::collections::HashMap; use std::convert::{TryFrom, TryInto}; -use failure::Error; +use anyhow::Error; use proc_macro2::{Ident, Span, TokenStream}; use quote::quote_spanned; diff --git a/proxmox-api-macro/src/lib.rs b/proxmox-api-macro/src/lib.rs index 7d1122cc..eab8fcc6 100644 --- a/proxmox-api-macro/src/lib.rs +++ b/proxmox-api-macro/src/lib.rs @@ -3,7 +3,7 @@ extern crate proc_macro; extern crate proc_macro2; -use failure::Error; +use anyhow::Error; use proc_macro::TokenStream as TokenStream_1; use proc_macro2::TokenStream; @@ -60,7 +60,7 @@ fn router_do(item: TokenStream) -> Result { # use proxmox_api_macro::api; # use proxmox::api::{ApiMethod, RpcEnvironment}; - use failure::Error; + use anyhow::Error; use serde_json::Value; #[api( diff --git a/proxmox-api-macro/src/types.rs b/proxmox-api-macro/src/types.rs index 220f992f..3ead3396 100644 --- a/proxmox-api-macro/src/types.rs +++ b/proxmox-api-macro/src/types.rs @@ -5,7 +5,7 @@ use proc_macro2::{Ident, Span, TokenStream}; -use failure::Error; +use anyhow::Error; /// A more relaxed version of Ident which allows hyphens. #[derive(Clone, Debug)] diff --git a/proxmox-api-macro/src/util.rs b/proxmox-api-macro/src/util.rs index c169c1b8..6ac39c2d 100644 --- a/proxmox-api-macro/src/util.rs +++ b/proxmox-api-macro/src/util.rs @@ -8,7 +8,7 @@ use syn::punctuated::Punctuated; use syn::spanned::Spanned; use syn::Token; -use failure::Error; +use anyhow::Error; use crate::api::{self, Schema, SchemaItem}; diff --git a/proxmox-api-macro/tests/api1.rs b/proxmox-api-macro/tests/api1.rs index 6eaa2e69..9bf88859 100644 --- a/proxmox-api-macro/tests/api1.rs +++ b/proxmox-api-macro/tests/api1.rs @@ -1,6 +1,6 @@ use proxmox_api_macro::api; -use failure::Error; +use anyhow::Error; use serde_json::{json, Value}; use proxmox::api::Permission; diff --git a/proxmox-api-macro/tests/api2.rs b/proxmox-api-macro/tests/api2.rs index f53eb6ff..af7849ea 100644 --- a/proxmox-api-macro/tests/api2.rs +++ b/proxmox-api-macro/tests/api2.rs @@ -1,6 +1,6 @@ use proxmox_api_macro::api; -use failure::Error; +use anyhow::Error; use serde_json::Value; #[api( diff --git a/proxmox-api-macro/tests/ext-schema.rs b/proxmox-api-macro/tests/ext-schema.rs index b879eb34..a82768c8 100644 --- a/proxmox-api-macro/tests/ext-schema.rs +++ b/proxmox-api-macro/tests/ext-schema.rs @@ -4,7 +4,7 @@ use proxmox::api::{schema, RpcEnvironment}; use proxmox_api_macro::api; -use failure::Error; +use anyhow::Error; use serde_json::{json, Value}; pub const NAME_SCHEMA: schema::Schema = schema::StringSchema::new("Archive name.") diff --git a/proxmox-api-macro/tests/options.rs b/proxmox-api-macro/tests/options.rs index 94195c35..67fbd959 100644 --- a/proxmox-api-macro/tests/options.rs +++ b/proxmox-api-macro/tests/options.rs @@ -1,6 +1,6 @@ use proxmox_api_macro::api; -use failure::Error; +use anyhow::Error; use serde_json::{json, Value}; #[api( diff --git a/proxmox-api-macro/tests/types.rs b/proxmox-api-macro/tests/types.rs index 8c8b5ddf..99949647 100644 --- a/proxmox-api-macro/tests/types.rs +++ b/proxmox-api-macro/tests/types.rs @@ -6,7 +6,7 @@ use proxmox::api::schema; use proxmox_api_macro::api; -use failure::Error; +use anyhow::Error; use serde::Deserialize; use serde_json::Value; diff --git a/proxmox-sortable-macro/Cargo.toml b/proxmox-sortable-macro/Cargo.toml index ae37d04b..d9aa3d64 100644 --- a/proxmox-sortable-macro/Cargo.toml +++ b/proxmox-sortable-macro/Cargo.toml @@ -12,8 +12,7 @@ exclude = [ "debian" ] proc-macro = true [dependencies] -#failure = { version = "0.1", default-features = false, features = ["std"] } -failure = "0.1" +anyhow = "1.0" proc-macro2 = "1.0" quote = "1.0" syn = { version = "1.0", features = [ "full", "visit-mut" ] } diff --git a/proxmox-sortable-macro/src/lib.rs b/proxmox-sortable-macro/src/lib.rs index 4b9b700c..2eaa2037 100644 --- a/proxmox-sortable-macro/src/lib.rs +++ b/proxmox-sortable-macro/src/lib.rs @@ -4,7 +4,7 @@ extern crate proc_macro2; use std::iter::FromIterator; use std::mem; -use failure::Error; +use anyhow::Error; use proc_macro::TokenStream as TokenStream_1; use proc_macro2::TokenStream; diff --git a/proxmox/Cargo.toml b/proxmox/Cargo.toml index c4fac1fa..ce285b59 100644 --- a/proxmox/Cargo.toml +++ b/proxmox/Cargo.toml @@ -13,7 +13,7 @@ exclude = [ "debian" ] [dependencies] # General dependencies -failure = "0.1" +anyhow = "1.0" lazy_static = "1.4" libc = "0.2" nix = "0.16" diff --git a/proxmox/src/api/cli/command.rs b/proxmox/src/api/cli/command.rs index 046440d7..d40713e9 100644 --- a/proxmox/src/api/cli/command.rs +++ b/proxmox/src/api/cli/command.rs @@ -1,4 +1,4 @@ -use failure::*; +use anyhow::*; use serde_json::Value; use std::cell::RefCell; use std::sync::Arc; diff --git a/proxmox/src/api/cli/completion.rs b/proxmox/src/api/cli/completion.rs index 25573acd..de31555d 100644 --- a/proxmox/src/api/cli/completion.rs +++ b/proxmox/src/api/cli/completion.rs @@ -298,7 +298,7 @@ pub fn get_completions( #[cfg(test)] mod test { - use failure::*; + use anyhow::*; use serde_json::Value; use crate::api::{cli::*, schema::*, *}; diff --git a/proxmox/src/api/cli/getopts.rs b/proxmox/src/api/cli/getopts.rs index 19020d83..dfccaa00 100644 --- a/proxmox/src/api/cli/getopts.rs +++ b/proxmox/src/api/cli/getopts.rs @@ -1,4 +1,4 @@ -use failure::*; +use anyhow::*; use serde_json::Value; use crate::api::schema::*; diff --git a/proxmox/src/api/cli/shellword.rs b/proxmox/src/api/cli/shellword.rs index 16eaf04f..4adf51d2 100644 --- a/proxmox/src/api/cli/shellword.rs +++ b/proxmox/src/api/cli/shellword.rs @@ -1,4 +1,4 @@ -use failure::*; +use anyhow::*; /// Shell quote type pub use rustyline::completion::Quote; diff --git a/proxmox/src/api/cli/text_table.rs b/proxmox/src/api/cli/text_table.rs index 26c1813d..51ed2c6b 100644 --- a/proxmox/src/api/cli/text_table.rs +++ b/proxmox/src/api/cli/text_table.rs @@ -1,6 +1,6 @@ use std::io::Write; -use failure::*; +use anyhow::*; use serde_json::Value; use crate::api::schema::*; diff --git a/proxmox/src/api/error.rs b/proxmox/src/api/error.rs index 4c063fa3..221dcf77 100644 --- a/proxmox/src/api/error.rs +++ b/proxmox/src/api/error.rs @@ -1,17 +1,17 @@ use std::fmt; -use failure::Fail; - #[doc(hidden)] pub use http::StatusCode; /// HTTP error including `StatusCode` and message. -#[derive(Debug, Fail)] +#[derive(Debug)] pub struct HttpError { pub code: StatusCode, pub message: String, } +impl std::error::Error for HttpError {} + impl HttpError { pub fn new(code: StatusCode, message: String) -> Self { HttpError { code, message } @@ -24,11 +24,11 @@ impl fmt::Display for HttpError { } } -/// Macro to create a HttpError inside a failure::Error +/// Macro to create a HttpError inside a anyhow::Error #[macro_export] macro_rules! http_err { ($status:ident, $msg:expr) => {{ - ::failure::Error::from($crate::api::error::HttpError::new( + ::anyhow::Error::from($crate::api::error::HttpError::new( $crate::api::error::StatusCode::$status, $msg, )) diff --git a/proxmox/src/api/format.rs b/proxmox/src/api/format.rs index d9911eac..6916b26d 100644 --- a/proxmox/src/api/format.rs +++ b/proxmox/src/api/format.rs @@ -1,6 +1,6 @@ //! Module to generate and format API Documenation -use failure::Error; +use anyhow::Error; use std::io::Write; diff --git a/proxmox/src/api/router.rs b/proxmox/src/api/router.rs index d279f438..11f5e003 100644 --- a/proxmox/src/api/router.rs +++ b/proxmox/src/api/router.rs @@ -3,7 +3,7 @@ use std::fmt; use std::future::Future; use std::pin::Pin; -use failure::Error; +use anyhow::Error; use http::request::Parts; use http::{Method, Response}; use hyper::Body; @@ -18,7 +18,7 @@ use super::Permission; /// /// Most API handler are synchronous. Use this to define such handler: /// ``` -/// # use failure::*; +/// # use anyhow::*; /// # use serde_json::{json, Value}; /// # use proxmox::api::{*, schema::*}; /// # @@ -44,7 +44,7 @@ pub type ApiHandlerFn = &'static (dyn Fn(Value, &ApiMethod, &mut dyn RpcEnvironm /// /// Returns a future Value. /// ``` -/// # use failure::*; +/// # use anyhow::*; /// # use serde_json::{json, Value}; /// # use proxmox::api::{*, schema::*}; /// # @@ -70,14 +70,14 @@ pub type ApiAsyncHandlerFn = &'static (dyn for<'a> Fn(Value, &'static ApiMethod, + Send + Sync); -pub type ApiFuture<'a> = Pin> + Send + 'a>>; +pub type ApiFuture<'a> = Pin> + Send + 'a>>; /// Asynchronous HTTP API handlers /// /// They get low level access to request and response data. Use this /// to implement custom upload/download functions. /// ``` -/// # use failure::*; +/// # use anyhow::*; /// # use serde_json::{json, Value}; /// # use proxmox::api::{*, schema::*}; /// # @@ -117,7 +117,7 @@ pub type ApiAsyncHttpHandlerFn = &'static (dyn Fn( /// The output of an asynchronous API handler is a future yielding a `Response`. pub type ApiResponseFuture = - Pin, failure::Error>> + Send>>; + Pin, anyhow::Error>> + Send>>; /// Enum for different types of API handler functions. pub enum ApiHandler { @@ -213,7 +213,7 @@ macro_rules! list_subdirs_api_method { /// all `const fn(mut self, ..)` methods to configure them. /// ///``` -/// # use failure::*; +/// # use anyhow::*; /// # use serde_json::{json, Value}; /// # use proxmox::api::{*, schema::*}; /// # diff --git a/proxmox/src/api/schema.rs b/proxmox/src/api/schema.rs index df681534..de9a0396 100644 --- a/proxmox/src/api/schema.rs +++ b/proxmox/src/api/schema.rs @@ -6,7 +6,7 @@ use std::fmt; -use failure::*; +use anyhow::{bail, format_err, Error}; use serde_json::{json, Value}; use url::form_urlencoded; @@ -17,11 +17,13 @@ use crate::api::const_regex::ConstRegexPattern; /// The validation functions may produce several error message, /// i.e. when validation objects, it can produce one message for each /// erroneous object property. -#[derive(Default, Debug, Fail)] +#[derive(Default, Debug)] pub struct ParameterError { error_list: Vec, } +impl std::error::Error for ParameterError {} + // fixme: record parameter names, to make it usefull to display errord // on HTML forms. impl ParameterError { diff --git a/proxmox/src/api/section_config.rs b/proxmox/src/api/section_config.rs index c6fcadab..41948789 100644 --- a/proxmox/src/api/section_config.rs +++ b/proxmox/src/api/section_config.rs @@ -18,7 +18,7 @@ //! ... //! ``` -use failure::*; +use anyhow::*; use std::collections::HashMap; use std::collections::HashSet; diff --git a/proxmox/src/sys/error.rs b/proxmox/src/sys/error.rs index 381fe62e..7adfed78 100644 --- a/proxmox/src/sys/error.rs +++ b/proxmox/src/sys/error.rs @@ -33,7 +33,7 @@ pub fn io_err_other(e: E) -> io::Error { /// Usage examples: /// /// ``` -/// # use failure::{bail, Error}; +/// # use anyhow::{bail, Error}; /// use nix::{dir::Dir, fcntl::OFlag, sys::stat::Mode}; /// /// use proxmox::sys::error::SysError; @@ -114,7 +114,7 @@ impl SysError for nix::Error { /// /// ```no_run /// # use std::os::unix::io::RawFd; -/// # use failure::{bail, Error}; +/// # use anyhow::{bail, Error}; /// /// use proxmox::sys::error::SysResult; /// diff --git a/proxmox/src/sys/linux.rs b/proxmox/src/sys/linux.rs index ea93254f..6d8dfd8f 100644 --- a/proxmox/src/sys/linux.rs +++ b/proxmox/src/sys/linux.rs @@ -1,6 +1,6 @@ //! Linux specific helpers and syscall wrapper -use failure::*; +use anyhow::*; pub mod magic; pub mod pid; diff --git a/proxmox/src/sys/linux/procfs.rs b/proxmox/src/sys/linux/procfs.rs index 505671e6..8f6ec835 100644 --- a/proxmox/src/sys/linux/procfs.rs +++ b/proxmox/src/sys/linux/procfs.rs @@ -7,7 +7,7 @@ use std::str::FromStr; use std::sync::RwLock; use std::time::Instant; -use failure::*; +use anyhow::*; use lazy_static::lazy_static; use libc; use nix::unistd::Pid; diff --git a/proxmox/src/sys/linux/procfs/mountinfo.rs b/proxmox/src/sys/linux/procfs/mountinfo.rs index 16a8a72c..1384c089 100644 --- a/proxmox/src/sys/linux/procfs/mountinfo.rs +++ b/proxmox/src/sys/linux/procfs/mountinfo.rs @@ -7,7 +7,7 @@ use std::os::unix::ffi::OsStrExt; use std::path::PathBuf; use std::str::FromStr; -use failure::{bail, format_err, Error}; +use anyhow::{bail, format_err, Error}; use nix::sys::stat; use nix::unistd::Pid; diff --git a/proxmox/src/sys/linux/tty.rs b/proxmox/src/sys/linux/tty.rs index 5a5b1823..a014d2a5 100644 --- a/proxmox/src/sys/linux/tty.rs +++ b/proxmox/src/sys/linux/tty.rs @@ -2,7 +2,7 @@ use std::io::{Read, Write}; use std::mem::MaybeUninit; use std::os::unix::io::AsRawFd; -use failure::*; +use anyhow::*; use crate::try_block; diff --git a/proxmox/src/sys/macros.rs b/proxmox/src/sys/macros.rs index af98670c..da6f7bd7 100644 --- a/proxmox/src/sys/macros.rs +++ b/proxmox/src/sys/macros.rs @@ -1,7 +1,7 @@ -//! A set of macros for I/O handling. These provide for `std::io::Error` what `failure` provides -//! for `failure::Error.` +//! A set of macros for I/O handling. These provide for `std::io::Error` what `anyhow` provides +//! for `anyhow::Error.` -/// Like failure's `format_err` but producing a `std::io::Error`. +/// Like anyhow's `format_err` but producing a `std::io::Error`. #[macro_export] macro_rules! io_format_err { ($($msg:tt)+) => { @@ -19,7 +19,7 @@ macro_rules! io_bail_last { }; } -/// Like failure's `bail` but producing a `std::io::Error`. +/// Like anyhow's `bail` but producing a `std::io::Error`. #[macro_export] macro_rules! io_bail { ($($msg:tt)+) => {{ diff --git a/proxmox/src/tools/fs.rs b/proxmox/src/tools/fs.rs index cb3a37db..a2dd2804 100644 --- a/proxmox/src/tools/fs.rs +++ b/proxmox/src/tools/fs.rs @@ -6,7 +6,7 @@ use std::io::{BufRead, BufReader, Write}; use std::os::unix::io::{AsRawFd, FromRawFd, RawFd}; use std::path::Path; -use failure::{bail, format_err, Error}; +use anyhow::{bail, format_err, Error}; use nix::errno::Errno; use nix::fcntl::OFlag; use nix::sys::stat; @@ -242,7 +242,7 @@ pub fn create_dir>(path: P, options: CreateOptions) -> Result<(), /// # use nix::sys::stat::Mode; /// # use nix::unistd::{Gid, Uid}; /// # use proxmox::tools::fs::{create_path, CreateOptions}; -/// # fn code() -> Result<(), failure::Error> { +/// # fn code() -> Result<(), anyhow::Error> { /// create_path( /// "/var/lib/mytool/wwwdata", /// None, diff --git a/proxmox/src/tools/mod.rs b/proxmox/src/tools/mod.rs index 55afd662..b745598c 100644 --- a/proxmox/src/tools/mod.rs +++ b/proxmox/src/tools/mod.rs @@ -1,6 +1,6 @@ //! This is a general utility crate used by all our rust projects. -use failure::*; +use anyhow::*; use lazy_static::lazy_static; pub mod as_any; @@ -63,7 +63,7 @@ macro_rules! static_assert_size { /// #### Example: /// ``` /// # use proxmox::try_block; -/// # use failure::*; +/// # use anyhow::*; /// # let some_condition = false; /// let result = try_block!({ /// if (some_condition) { diff --git a/proxmox/src/tools/parse.rs b/proxmox/src/tools/parse.rs index f20c7c9b..0986e7ac 100644 --- a/proxmox/src/tools/parse.rs +++ b/proxmox/src/tools/parse.rs @@ -1,6 +1,6 @@ //! Some parsing utilities. -use failure::{bail, Error}; +use anyhow::{bail, Error}; /// Parse a hexadecimal digit into a byte. #[inline] diff --git a/proxmox/src/tools/uuid.rs b/proxmox/src/tools/uuid.rs index 4c93f408..5ce8f215 100644 --- a/proxmox/src/tools/uuid.rs +++ b/proxmox/src/tools/uuid.rs @@ -3,7 +3,7 @@ use std::borrow::{Borrow, BorrowMut}; use std::fmt; -use failure::{bail, Error}; +use anyhow::{bail, Error}; use crate::tools::parse::hex_nibble;