forked from Proxmox/proxmox
switch from failure to anyhow
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
5affb691b5
commit
5dd21ee89b
@ -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" ] }
|
||||
|
@ -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};
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
}
|
||||
});
|
||||
|
@ -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;
|
||||
|
@ -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<TokenStream, Error> {
|
||||
# use proxmox_api_macro::api;
|
||||
# use proxmox::api::{ApiMethod, RpcEnvironment};
|
||||
|
||||
use failure::Error;
|
||||
use anyhow::Error;
|
||||
use serde_json::Value;
|
||||
|
||||
#[api(
|
||||
|
@ -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)]
|
||||
|
@ -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};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use proxmox_api_macro::api;
|
||||
|
||||
use failure::Error;
|
||||
use anyhow::Error;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use proxmox::api::Permission;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use proxmox_api_macro::api;
|
||||
|
||||
use failure::Error;
|
||||
use anyhow::Error;
|
||||
use serde_json::Value;
|
||||
|
||||
#[api(
|
||||
|
@ -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.")
|
||||
|
@ -1,6 +1,6 @@
|
||||
use proxmox_api_macro::api;
|
||||
|
||||
use failure::Error;
|
||||
use anyhow::Error;
|
||||
use serde_json::{json, Value};
|
||||
|
||||
#[api(
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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" ] }
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -1,4 +1,4 @@
|
||||
use failure::*;
|
||||
use anyhow::*;
|
||||
use serde_json::Value;
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
|
@ -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::*, *};
|
||||
|
@ -1,4 +1,4 @@
|
||||
use failure::*;
|
||||
use anyhow::*;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::api::schema::*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
use failure::*;
|
||||
use anyhow::*;
|
||||
|
||||
/// Shell quote type
|
||||
pub use rustyline::completion::Quote;
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::io::Write;
|
||||
|
||||
use failure::*;
|
||||
use anyhow::*;
|
||||
use serde_json::Value;
|
||||
|
||||
use crate::api::schema::*;
|
||||
|
@ -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,
|
||||
))
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Module to generate and format API Documenation
|
||||
|
||||
use failure::Error;
|
||||
use anyhow::Error;
|
||||
|
||||
use std::io::Write;
|
||||
|
||||
|
@ -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<Box<dyn Future<Output = Result<Value, failure::Error>> + Send + 'a>>;
|
||||
pub type ApiFuture<'a> = Pin<Box<dyn Future<Output = Result<Value, anyhow::Error>> + 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<Box<dyn Future<Output = Result<Response<Body>, failure::Error>> + Send>>;
|
||||
Pin<Box<dyn Future<Output = Result<Response<Body>, 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::*};
|
||||
/// #
|
||||
|
@ -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<Error>,
|
||||
}
|
||||
|
||||
impl std::error::Error for ParameterError {}
|
||||
|
||||
// fixme: record parameter names, to make it usefull to display errord
|
||||
// on HTML forms.
|
||||
impl ParameterError {
|
||||
|
@ -18,7 +18,7 @@
|
||||
//! ...
|
||||
//! ```
|
||||
|
||||
use failure::*;
|
||||
use anyhow::*;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
|
@ -33,7 +33,7 @@ pub fn io_err_other<E: ToString>(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;
|
||||
///
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Linux specific helpers and syscall wrapper
|
||||
|
||||
use failure::*;
|
||||
use anyhow::*;
|
||||
|
||||
pub mod magic;
|
||||
pub mod pid;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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)+) => {{
|
||||
|
@ -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<P: AsRef<Path>>(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,
|
||||
|
@ -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) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
//! Some parsing utilities.
|
||||
|
||||
use failure::{bail, Error};
|
||||
use anyhow::{bail, Error};
|
||||
|
||||
/// Parse a hexadecimal digit into a byte.
|
||||
#[inline]
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user