Switch from failure::Fail trait to std::error::Error for errors

Summary:
This diff replaces eden's dependencies on failure::Error with anyhow::Error.

Failure's error type requires all errors to have an implementation of failure's own failure::Fail trait in order for cause chains and backtraces to work. The necessary methods for this functionality have made their way into the standard library error trait, so modern error libraries build directly on std::error::Error rather than something like failure::Fail. Once we are no longer tied to failure 0.1's Fail trait, different parts of the codebase will be free to use any std::error::Error-based libraries they like while still working nicely together.

Reviewed By: xavierd

Differential Revision: D18576093

fbshipit-source-id: e2d862b659450f2969520d9b74877913fabb2e5d
This commit is contained in:
David Tolnay 2019-11-22 08:51:58 -08:00 committed by Facebook Github Bot
parent 29fc5efd96
commit d1d8fb939a
156 changed files with 223 additions and 251 deletions

View File

@ -16,7 +16,7 @@ crate-type = ["cdylib"]
cpython-ext = { path = "../../../../lib/cpython-ext" }
cpython-failure = { path = "../../../../lib/cpython-failure" }
radixbuf = { path = "../../../../lib/radixbuf" }
failure = "0.1.5"
anyhow = "1.0.20"
thiserror = "1.0.5"
[dependencies.cpython]

View File

@ -6,7 +6,7 @@
*/
use crate::errors::ErrorKind;
use failure::{bail, Fallible as Result};
use anyhow::{bail, Result};
use radixbuf::errors as rerrors;
use radixbuf::key::KeyId;
use radixbuf::radix::{

View File

@ -8,4 +8,4 @@ cpython-failure = { path = "../../../../lib/cpython-failure" }
cpython = { version = "0.3", features = ["python27-sys"], default-features = false }
dag = { path = "../../../../lib/dag" }
encoding = { path = "../../../../lib/encoding" }
failure = "0.1.3"
anyhow = "1.0.20"

View File

@ -7,6 +7,7 @@
#![allow(non_camel_case_types)]
use anyhow::Error;
use cpython::*;
use cpython_failure::{FallibleExt, ResultPyErrExt};
use dag::{
@ -15,7 +16,6 @@ use dag::{
spanset::{SpanSet, SpanSetIter},
};
use encoding::local_bytes_to_path;
use failure::Error;
use std::cell::RefCell;
type Result<T, E = Error> = std::result::Result<T, E>;

View File

@ -9,7 +9,6 @@ cpython-failure = { path = "../../../../lib/cpython-failure" }
cpython = { version = "0.3", features = ["python27-sys"], default-features = false }
edenapi = { path = "../../../../lib/edenapi" }
encoding = { path = "../../../../lib/encoding" }
failure = "0.1.3"
pyrevisionstore = { path = "../pyrevisionstore" }
revisionstore = { path = "../../../../lib/revisionstore" }
types = { path = "../../../../lib/types" }

View File

@ -4,12 +4,12 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.20"
bytes = { version = "0.4.11" }
cpython-ext = { path = "../../../../lib/cpython-ext" }
cpython-failure = { path = "../../../../lib/cpython-failure" }
cpython = { version = "0.3", features = ["python27-sys"], default-features = false }
encoding = { path = "../../../../lib/encoding" }
failure = "0.1.3"
manifest = { path = "../../../../lib/manifest" }
pathmatcher = { path = "../../../../lib/pathmatcher" }
pypathmatcher = { path = "../pypathmatcher" }

View File

@ -9,9 +9,9 @@
use std::{borrow::Borrow, cell::RefCell, ops::Deref, str, sync::Arc};
use anyhow::{format_err, Error};
use bytes::Bytes;
use cpython::*;
use failure::{format_err, Error};
use cpython_ext::{pyset_add, pyset_new};
use cpython_failure::ResultPyErrExt;

View File

@ -4,12 +4,13 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.20"
byteorder = "1.2.7"
cpython-ext = { path = "../../../../lib/cpython-ext" }
cpython-failure = { path = "../../../../lib/cpython-failure" }
cpython = { version = "0.3", features = ["python27-sys"], default-features = false }
encoding = { path = "../../../../lib/encoding" }
failure = "0.1.3"
mutationstore = { path = "../../../../lib/mutationstore" }
thiserror = "1.0.5"
types = { path = "../../../../lib/types" }
vlqencoding = { path = "../../../../lib/vlqencoding" }

View File

@ -9,10 +9,11 @@
use std::{cell::RefCell, io::Cursor};
use anyhow::Error;
use byteorder::{ReadBytesExt, WriteBytesExt};
use cpython::*;
use cpython_failure::ResultPyErrExt;
use failure::ResultExt;
use thiserror::Error;
use ::mutationstore::{MutationEntry, MutationEntryOrigin, MutationStore};
use encoding::local_bytes_to_path;
@ -75,6 +76,16 @@ fn unbundle(py: Python, data: PyBytes) -> PyResult<Vec<mutationentry>> {
Ok(entries)
}
#[derive(Error, Debug)]
enum InvalidNode {
#[error("Invalid successor node: {0}")]
Successor(Error),
#[error("Invalid predecessor node: {0}")]
Predecessor(Error),
#[error("Invalid split node: {0}")]
Split(Error),
}
py_class!(class mutationentry |py| {
data entry: MutationEntry;
@ -92,14 +103,14 @@ py_class!(class mutationentry |py| {
) -> PyResult<mutationentry> {
let origin = MutationEntryOrigin::from_id(origin).map_pyerr::<exc::ValueError>(py)?;
let succ = Node::from_slice(succ.data(py))
.with_context(|e| format!("Invalid successor node: {}", e))
.map_err(InvalidNode::Successor)
.map_pyerr::<exc::ValueError>(py)?;
let preds = {
let mut nodes = Vec::new();
if let Some(preds) = preds {
for p in preds {
nodes.push(Node::from_slice(p.data(py))
.with_context(|e| format!("Invalid predecessor node: {}", e))
.map_err(InvalidNode::Predecessor)
.map_pyerr::<exc::ValueError>(py)?);
}
}
@ -110,7 +121,7 @@ py_class!(class mutationentry |py| {
if let Some(split) = split {
for s in split {
nodes.push(Node::from_slice(s.data(py))
.with_context(|e| format!("Invalid split node: {}", e))
.map_err(InvalidNode::Split)
.map_pyerr::<exc::ValueError>(py)?);
}
}

View File

@ -4,11 +4,11 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.20"
cpython-ext = { path = "../../../../lib/cpython-ext" }
cpython-failure = { path = "../../../../lib/cpython-failure" }
cpython = { version = "0.3", features = ["python27-sys"], default-features = false }
encoding = { path = "../../../../lib/encoding" }
failure = "0.1"
parking_lot = "0.9.0"
pyconfigparser = { path = "../pyconfigparser" }
revisionstore = { path = "../../../../lib/revisionstore" }

View File

@ -5,11 +5,11 @@
* GNU General Public License version 2.
*/
use anyhow::Result;
use cpython::{
PyBytes, PyDict, PyIterator, PyList, PyObject, PyResult, PyTuple, Python, PythonObject,
ToPyObject,
};
use failure::Fallible as Result;
use revisionstore::{DataStore, MutableDeltaStore, RemoteDataStore, ToKeys};
use types::{Key, Node};

View File

@ -5,10 +5,10 @@
* GNU General Public License version 2.
*/
use anyhow::Result;
use cpython::{
PyBytes, PyIterator, PyList, PyObject, PyResult, PyTuple, Python, PythonObject, ToPyObject,
};
use failure::Fallible as Result;
use revisionstore::{HistoryStore, MutableHistoryStore, RemoteHistoryStore, ToKeys};
use types::{Key, NodeInfo};

View File

@ -15,8 +15,8 @@ use std::{
sync::Arc,
};
use anyhow::{format_err, Error};
use cpython::*;
use failure::{format_err, Error};
use parking_lot::RwLock;
use cpython_ext::{Bytes, PyErr};

View File

@ -5,11 +5,11 @@
* GNU General Public License version 2.
*/
use anyhow::Result;
use cpython::{
exc, FromPyObject, ObjectProtocol, PyBytes, PyDict, PyList, PyObject, PyTuple, Python,
PythonObject, PythonObjectWithTypeObject,
};
use failure::Fallible as Result;
use cpython_ext::PyErr;
use revisionstore::{DataStore, Delta, LocalStore, Metadata, RemoteDataStore};

View File

@ -5,11 +5,11 @@
* GNU General Public License version 2.
*/
use anyhow::Result;
use cpython::{
exc, FromPyObject, ObjectProtocol, PyBytes, PyClone, PyList, PyObject, PyTuple, Python,
PythonObject, PythonObjectWithTypeObject,
};
use failure::Fallible as Result;
use cpython_ext::PyErr;
use revisionstore::{HistoryStore, LocalStore};

View File

@ -7,11 +7,11 @@
use std::io;
use anyhow::{Error, Result};
use cpython::{
exc, FromPyObject, PyBytes, PyDict, PyErr, PyObject, PyResult, PyTuple, Python, PythonObject,
ToPyObject,
};
use failure::{Error, Fallible as Result};
use cpython_ext::PyErr as ExtPyErr;
use revisionstore::datastore::{Delta, Metadata};
@ -19,12 +19,9 @@ use types::{Key, Node, RepoPath, RepoPathBuf};
pub fn to_pyerr(py: Python, error: &Error) -> PyErr {
if let Some(io_error) = error.downcast_ref::<io::Error>() {
PyErr::new::<exc::OSError, _>(
py,
(io_error.raw_os_error(), format!("{}", error.as_fail())),
)
PyErr::new::<exc::OSError, _>(py, (io_error.raw_os_error(), format!("{}", error)))
} else {
PyErr::new::<exc::RuntimeError, _>(py, format!("{}", error.as_fail()))
PyErr::new::<exc::RuntimeError, _>(py, format!("{}", error))
}
}

View File

@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.20"
cpython-failure = { path = "../../../../lib/cpython-failure" }
cpython = { version = "0.3", features = ["python27-sys"], default-features = false }
encoding = { path = "../../../../lib/encoding" }
failure = "0.1"
treestate = { path = "../../../../lib/treestate" }

View File

@ -23,8 +23,8 @@
use std::cell::RefCell;
use std::path::PathBuf;
use anyhow::Error;
use cpython::*;
use failure::Error;
use ::treestate::{
errors::ErrorKind,

View File

@ -14,8 +14,8 @@ hgcommands = { path = "../../lib/hgcommands" }
pyblackbox = { path = "../../edenscmnative/bindings/modules/pyblackbox" }
[target.'cfg(windows)'.dependencies]
anyhow = "1.0.20"
winapi = {version = "0.3.7", features = ["handleapi", "processenv", "winbase"]}
failure = "0.1"
[dependencies.encoding]
path = "../../lib/encoding"

View File

@ -5,7 +5,7 @@
* GNU General Public License version 2.
*/
use failure::{format_err, Error};
use anyhow::{format_err, Error};
use winapi::shared::minwindef::DWORD;
use winapi::um::errhandlingapi::GetLastError;
use winapi::um::handleapi::{SetHandleInformation, INVALID_HANDLE_VALUE};

View File

@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.20"
clap = "2.32.0"
env_logger = "0.7"
failure = "0.1.3"
libc = "0.2"
log = "0.4.6"
serde = "1.0.80"

View File

@ -7,7 +7,7 @@
#![deny(warnings)]
pub use failure::Error;
pub use anyhow::{Error, Result};
use thiserror::Error;
#[derive(Debug, Error)]
@ -15,5 +15,3 @@ pub enum ErrorKind {
#[error("unexpected error {0}")]
ScmDaemonUnexpectedError(String),
}
pub type Result<T> = ::std::result::Result<T, Error>;

View File

@ -7,11 +7,11 @@
pub mod error;
use anyhow::{bail, Result};
use clap::{App, Arg};
use commitcloudsubscriber::{
CommitCloudConfig, CommitCloudTcpReceiverService, CommitCloudWorkspaceSubscriberService,
};
use failure::{bail, Fallible as Result};
use log::info;
use serde::Deserialize;
use std::fs::File;

View File

@ -5,9 +5,9 @@ authors = ["Source Control Oncall oncall+source_control@xmail.facebook.com"]
edition = "2018"
[dependencies]
anyhow = "1.0.20"
clap = "2.31.2"
dirs = "1.0"
failure = "0.1"
libc = "0.2" # version taken from fbcode/third-party2/.../crates.io/..
serde = "1.0"
serde_derive = "1.0"

View File

@ -13,8 +13,8 @@
//! may want to use watchman to watch a portion of the scratch space
//! and can arrange the directory structure to prevent over-watching.
use anyhow::{bail, ensure, format_err, Result};
use clap::{App, AppSettings, Arg, SubCommand};
use failure::{bail, format_err, Fallible as Result};
use serde::Deserialize;
use std::collections::HashMap;
use std::env;
@ -254,7 +254,7 @@ struct PasswordEntry {
impl PasswordEntry {
fn maybe_string(cstr: *const libc::c_char, context: &str) -> Result<String> {
if cstr.is_null() {
Err(failure::err_msg(context.to_string()))
bail!(context.to_string());
} else {
let cstr = unsafe { std::ffi::CStr::from_ptr(cstr) };
cstr.to_str().map_err(|e| e.into()).map(|x| x.to_owned())
@ -262,7 +262,7 @@ impl PasswordEntry {
}
fn from_password(pwent: *const libc::passwd) -> Result<Self> {
failure::ensure!(!pwent.is_null(), "password ptr is null");
ensure!(!pwent.is_null(), "password ptr is null");
let pw = unsafe { &*pwent };
Ok(Self {
unixname: Self::maybe_string(pw.pw_name, "pw_name is null")?,

View File

@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.20"
bytes = { version = "0.4.11", features = ["serde"] }
failure = "0.1.3"
indexedlog = { path = "../../lib/indexedlog" }
manifest = { path = "../../lib/manifest" }
pathmatcher = { path = "../../lib/pathmatcher" }

View File

@ -7,8 +7,8 @@
use std::{path::PathBuf, sync::Arc};
use anyhow::{format_err, Result};
use bytes::Bytes;
use failure::{format_err, Fallible as Result};
use structopt::StructOpt;
use pathmatcher::AlwaysMatcher;

View File

@ -7,7 +7,7 @@
use std::path::PathBuf;
use failure::Error;
use anyhow::Error;
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -5,7 +5,7 @@
* GNU General Public License version 2.
*/
use failure::{Error, Fallible as Result};
use anyhow::{Error, Result};
use futures::{future::ok, stream::iter_ok};
use tokio::prelude::*;

View File

@ -7,7 +7,7 @@
use std::path::PathBuf;
use failure::Error;
use anyhow::Error;
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -5,7 +5,7 @@
* GNU General Public License version 2.
*/
use failure::{Error, Fallible as Result};
use anyhow::{Error, Result};
use futures::{future::ok, stream::iter_ok};
use tokio::prelude::*;

View File

@ -7,7 +7,7 @@
use std::path::PathBuf;
use failure::Error;
use anyhow::Error;
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -7,7 +7,7 @@
use std::path::PathBuf;
use failure::Error;
use anyhow::Error;
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -7,7 +7,7 @@
use std::path::PathBuf;
use failure::Error;
use anyhow::Error;
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -7,7 +7,7 @@
use std::path::PathBuf;
use failure::Error;
use anyhow::Error;
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -7,7 +7,7 @@
use std::path::PathBuf;
use failure::Error;
use anyhow::Error;
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -7,7 +7,7 @@
use std::path::PathBuf;
use failure::Error;
use anyhow::Error;
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -7,7 +7,7 @@
use std::path::{Path, PathBuf};
use failure::{Error, Fallible as Result};
use anyhow::{Error, Result};
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -7,7 +7,7 @@
use std::path::{Path, PathBuf};
use failure::{Error, Fallible as Result};
use anyhow::{Error, Result};
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -7,7 +7,7 @@
use std::sync::Arc;
use failure::{Error, Fallible as Result};
use anyhow::{Error, Result};
use futures::future::poll_fn;
use tokio::prelude::*;
use tokio_threadpool::blocking;

View File

@ -4,9 +4,9 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.20"
bytes = "0.4.12"
configparser = { path = "../configparser" }
failure = "0.1.6"
indexmap = "1.0.1"
url = "2.1.0"
util = { path = "../util" }

View File

@ -7,8 +7,8 @@
use std::{collections::HashMap, convert::TryFrom, path::PathBuf, str};
use anyhow::{Error, Result};
use bytes::Bytes;
use failure::{err_msg, Error, Fallible as Result};
use indexmap::IndexMap;
use url::Url;
@ -38,7 +38,7 @@ impl TryFrom<(&str, HashMap<&str, Bytes>)> for Auth {
.map(bytes_to_str)
.transpose()?
.map(String::from)
.ok_or(err_msg("auth prefix missing"))?;
.ok_or_else(|| Error::msg("auth prefix missing"))?;
let cert = settings
.get("cert")

View File

@ -9,8 +9,8 @@ configparser = { path = "../configparser" }
manifest = { path = "../manifest" }
revisionstore = { path = "../revisionstore" }
types = { path = "../types" }
anyhow = "1.0.20"
bytes = "0.4.12"
failure = "0.1.6"
libc = "0.2.62"
[lib]

View File

@ -7,9 +7,9 @@
use crate::raw;
use crate::treecontentstore::TreeContentStore;
use anyhow::Result;
use configparser::config::ConfigSet;
use configparser::hg::ConfigSetHgExt;
use failure::Fallible as Result;
use manifest::Tree;
use revisionstore::{ContentStore, ContentStoreBuilder, DataStore};
use std::convert::TryFrom;

View File

@ -7,7 +7,7 @@
//! Provides the c-bindings for `crate::backingstore`.
use failure::{ensure, err_msg, Fallible as Result};
use anyhow::{ensure, Error, Result};
use libc::{c_char, size_t};
use std::{slice, str};
@ -59,7 +59,7 @@ fn backingstore_get_blob(
store
.get_blob(path, node)
.and_then(|opt| opt.ok_or_else(|| err_msg("no blob found")))
.and_then(|opt| opt.ok_or_else(|| Error::msg("no blob found")))
.map(CBytes::from_vec)
.map(|result| Box::into_raw(Box::new(result)))
}

View File

@ -14,7 +14,7 @@
//! Consumer of this struct needs to ensure the returned error string freed with
//! `rust_cfallible_free_error`.
use failure::Fallible as Result;
use anyhow::Result;
use libc::c_char;
use std::ffi::CString;

View File

@ -10,7 +10,7 @@
//! Structs in this file should be keep in sync with `eden/fs/model/{Tree, TreeEntry}.h`.
use crate::raw::CBytes;
use failure::{format_err, Fallible};
use anyhow::{format_err, Result};
use manifest::{tree::List, FileType, FsNode};
use std::convert::TryFrom;
use types::PathComponentBuf;
@ -44,7 +44,7 @@ pub struct TreeEntry {
}
impl TreeEntry {
fn try_from_path_node(path: PathComponentBuf, node: FsNode) -> Fallible<Self> {
fn try_from_path_node(path: PathComponentBuf, node: FsNode) -> Result<Self> {
let (ttype, hash) = match node {
FsNode::Directory(Some(hgid)) => (TreeEntryType::Tree, hgid.as_ref().to_vec()),
FsNode::File(metadata) => (metadata.file_type.into(), metadata.hgid.as_ref().to_vec()),
@ -72,7 +72,7 @@ pub struct Tree {
}
impl TryFrom<List> for Tree {
type Error = failure::Error;
type Error = anyhow::Error;
fn try_from(list: List) -> Result<Self, Self::Error> {
match list {
@ -81,7 +81,7 @@ impl TryFrom<List> for Tree {
let entries = list
.into_iter()
.map(|(path, node)| TreeEntry::try_from_path_node(path, node))
.collect::<Fallible<Vec<_>>>()?;
.collect::<Result<Vec<_>>>()?;
let entries = Box::new(entries);
let length = entries.len();

View File

@ -5,8 +5,8 @@
* GNU General Public License version 2.
*/
use anyhow::{format_err, Result};
use bytes::Bytes;
use failure::{format_err, Fallible};
use manifest::TreeStore;
use revisionstore::{ContentStore, DataStore};
use types::{HgId, Key, RepoPath};
@ -22,7 +22,7 @@ impl TreeContentStore {
}
impl TreeStore for TreeContentStore {
fn get(&self, path: &RepoPath, hgid: HgId) -> Fallible<Bytes> {
fn get(&self, path: &RepoPath, hgid: HgId) -> Result<Bytes> {
let key = Key::new(path.to_owned(), hgid);
self.inner.get(&key).and_then(|opt| {
@ -31,7 +31,7 @@ impl TreeStore for TreeContentStore {
})
}
fn insert(&self, _path: &RepoPath, _hgid: HgId, _data: Bytes) -> Fallible<()> {
fn insert(&self, _path: &RepoPath, _hgid: HgId, _data: Bytes) -> Result<()> {
Err(format_err!("insert is not implemented."))
}
}

View File

@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.20"
byteorder = "1"
failure = "0.1"
indexedlog = { path = "../indexedlog" }
lazy_static = "1"
libc = "0.2"

View File

@ -7,8 +7,8 @@
use super::{capture_pattern, json, match_pattern};
use crate::event::Event;
use anyhow::Result;
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use failure::Fallible as Result;
use indexedlog::log::IndexOutput;
use indexedlog::rotate::{OpenOptions, RotateLog, RotateLowLevelExt};
use lazy_static::lazy_static;

View File

@ -14,7 +14,7 @@
//! types of events that are outside this module.
use super::ToValue;
use failure::Fallible as Result;
use anyhow::Result;
use serde_alt::serde_alt;
use serde_derive::{Deserialize, Serialize};
use serde_json::Value;

View File

@ -5,8 +5,8 @@ authors = ["Facebook Source Control Team <sourcecontrol-dev@fb.com>"]
edition = "2018"
[dependencies]
anyhow = "1.0.20"
atomicwrites = "0.2.2"
failure = "0.1.5"
types = { path = "../types" }
indexedlog = { path = "../indexedlog" }
thiserror = "1.0.5"

View File

@ -16,7 +16,7 @@ use std::io::Write;
use std::path::Path;
use std::str;
use failure::Fallible as Result;
use anyhow::Result;
use indexedlog::log::{IndexDef, IndexOutput, Log};
use types::hgid::HgId;

View File

@ -5,11 +5,11 @@ authors = ["Facebook Source Control Team <sourcecontrol-dev@fb.com>"]
edition = "2018"
[dependencies]
anyhow = "1.0.20"
bytes = "0.4.10"
blackbox = { path = "../blackbox" }
configparser = { path = "../configparser" }
cliparser = { path = "../cliparser" }
failure = "0.1.3"
indexedlog = { path = "../indexedlog" }
thiserror = "1.0.5"
util = { path = "../util" }

View File

@ -6,8 +6,8 @@
*/
use crate::{io::IO, repo::Repo};
use anyhow::Result;
use cliparser::parser::{Flag, ParseOutput, StructFlags};
use failure::Fallible as Result;
use std::collections::BTreeMap;
use std::convert::{TryFrom, TryInto};
use std::ops::Deref;
@ -105,7 +105,7 @@ pub trait Register<FN, T> {
// NoRepo commands.
impl<S, FN> Register<FN, (S,)> for CommandTable
where
S: TryFrom<ParseOutput, Error = failure::Error> + StructFlags,
S: TryFrom<ParseOutput, Error = anyhow::Error> + StructFlags,
FN: Fn(S, &mut IO) -> Result<u8> + 'static,
{
fn register(&mut self, f: FN, name: &str, doc: &str) {
@ -120,7 +120,7 @@ where
// OptionalRepo commands.
impl<S, FN> Register<FN, ((), S)> for CommandTable
where
S: TryFrom<ParseOutput, Error = failure::Error> + StructFlags,
S: TryFrom<ParseOutput, Error = anyhow::Error> + StructFlags,
FN: Fn(S, &mut IO, Option<Repo>) -> Result<u8> + 'static,
{
fn register(&mut self, f: FN, name: &str, doc: &str) {
@ -136,7 +136,7 @@ where
// Repo commands.
impl<S, FN> Register<FN, ((), (), S)> for CommandTable
where
S: TryFrom<ParseOutput, Error = failure::Error> + StructFlags,
S: TryFrom<ParseOutput, Error = anyhow::Error> + StructFlags,
FN: Fn(S, &mut IO, Repo) -> Result<u8> + 'static,
{
fn register(&mut self, f: FN, name: &str, doc: &str) {

View File

@ -10,12 +10,12 @@ use crate::errors;
use crate::global_flags::HgGlobalOpts;
use crate::io::IO;
use crate::repo::OptionalRepo;
use anyhow::Error;
use bytes::Bytes;
use cliparser::alias::{expand_aliases, find_command_name};
use cliparser::parser::{ParseError, ParseOptions, ParseOutput, StructFlags};
use configparser::config::ConfigSet;
use configparser::hg::ConfigSetHgExt;
use failure::Error;
use std::convert::TryInto;
use std::{env, path::Path};

View File

@ -48,7 +48,7 @@ pub struct Abort(pub Cow<'static, str>);
/// Print an error suitable for end-user consumption.
///
/// This function adds `hg:` or `abort:` to error messages.
pub fn print_error(err: &failure::Error, io: &mut crate::io::IO) {
pub fn print_error(err: &anyhow::Error, io: &mut crate::io::IO) {
use cliparser::parser::ParseError;
if err.downcast_ref::<configparser::Error>().is_some() {
let _ = io.write_err(format!("hg: parse error: {}\n", err));

View File

@ -13,6 +13,3 @@ pub mod errors;
pub mod global_flags;
pub mod io;
pub mod repo;
// Re-export
pub use failure;

View File

@ -6,8 +6,8 @@
*/
use crate::errors;
use anyhow::Result;
use configparser::{config::ConfigSet, hg::ConfigSetHgExt};
use failure::Fallible as Result;
use std::fs;
use std::path::Path;
use std::path::PathBuf;

View File

@ -5,7 +5,7 @@ authors = ["Facebook Source Control Team <sourcecontrol-dev@fb.com>"]
edition = "2018"
[dependencies]
failure = "0.1.3"
anyhow = "1.0.20"
lazy_static = "1.3.0"
shlex = "0.1"
cpython-ext = { path = "../cpython-ext", optional = true }

View File

@ -47,9 +47,9 @@ macro_rules! _define_flags_impl {
}
impl ::std::convert::TryFrom<$crate::parser::ParseOutput> for $name {
type Error = ::failure::Error;
type Error = ::anyhow::Error;
fn try_from(out: $crate::parser::ParseOutput) -> ::failure::Fallible<Self> {
fn try_from(out: $crate::parser::ParseOutput) -> ::anyhow::Result<Self> {
if !$has_varargs && out.args.len() > $varargs_offset {
return Err($crate::errors::InvalidArguments.into());
}

View File

@ -16,8 +16,8 @@ description = """ \
edition = "2018"
[dependencies]
anyhow = "1.0.20"
eventsource = "0.3.0"
failure = "0.1.3"
lazy_static = "1.2.0"
log = "0.4.6"
serde = { version = "1.0.80", features = ["derive"] }

View File

@ -6,7 +6,7 @@
*/
use crate::error::*;
use failure::Fallible as Result;
use anyhow::Result;
use log::{error, info};
use std::path::Path;
use std::process::{Command, Stdio};

View File

@ -5,7 +5,7 @@
* GNU General Public License version 2.
*/
use failure::Fallible as Result;
use anyhow::Result;
use log::{error, info};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

View File

@ -13,8 +13,8 @@ use crate::receiver::CommandName::{
CommitCloudStartSubscriptions,
};
use crate::util;
use anyhow::{bail, Result};
use eventsource::reqwest::Client;
use failure::{bail, Fallible as Result};
use log::{error, info, warn};
use reqwest::Url;
use serde::Deserialize;

View File

@ -7,7 +7,7 @@
use crate::error::*;
use crate::subscriber::Subscription;
use failure::{bail, Fallible as Result};
use anyhow::{bail, Result};
use ini::Ini;
use log::{error, info};
use std::collections::HashMap;

View File

@ -4,14 +4,14 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.19"
bytes = "0.4.10"
dirs = "1.0.4"
failure = "0.1.2"
failure_derive = "0.1.2"
indexmap = "1.0.1"
parking_lot = "0.9"
pest = "2.1.0"
pest_derive = "2.1.0"
thiserror = "1.0.5"
util = { path = "../util" }
[dev-dependencies]

View File

@ -9,24 +9,24 @@ use std::io;
use std::path::PathBuf;
use std::str;
use failure::Fail;
use thiserror::Error;
/// The error type for parsing config files.
#[derive(Fail, Debug)]
#[derive(Error, Debug)]
pub enum Error {
/// Unable to convert to a type.
#[fail(display = "{}", _0)]
#[error("{0}")]
Convert(String),
/// Unable to parse a file due to syntax.
#[fail(display = "{:?}:\n{}", _0, _1)]
#[error("{0:?}:\n{1}")]
Parse(PathBuf, String),
/// Unable to read a file due to IO errors.
#[fail(display = "{:?}: {}", _0, _1)]
Io(PathBuf, #[cause] io::Error),
#[error("{0:?}: {1}")]
Io(PathBuf, #[source] io::Error),
/// Config file contains invalid UTF-8.
#[fail(display = "{:?}: {}", _0, _1)]
Utf8(PathBuf, #[cause] str::Utf8Error),
#[error("{0:?}: {1}")]
Utf8(PathBuf, #[source] str::Utf8Error),
}

View File

@ -13,8 +13,8 @@ use std::env;
use std::hash::Hash;
use std::path::{Path, PathBuf};
use anyhow::Result;
use bytes::Bytes;
use failure::Fallible as Result;
use util::path::expand_path;
use crate::config::{ConfigSet, Options};

View File

@ -9,7 +9,7 @@ python2 = []
python3 = []
[dependencies]
failure = "0.1.3"
anyhow = "1.0.20"
serde = "1"
[dependencies.cpython]

View File

@ -5,10 +5,10 @@
* GNU General Public License version 2.
*/
//! Integrate cpython with failure
//! Integrate cpython with anyhow
use anyhow::{Error, Result};
use cpython::{ObjectProtocol, PyClone, PyResult, Python, PythonObjectWithTypeObject};
use failure::{AsFail, Error, Fallible as Result};
use std::fmt;
/// Extends the `Result` type to allow conversion to `PyResult` by specifying a
@ -20,9 +20,9 @@ use std::fmt;
/// # Examples
///
/// ```
/// use anyhow::{format_err, Error};
/// use cpython::{exc, Python, PyResult};
/// use cpython_ext::failure::ResultPyErrExt;
/// use failure::{format_err, Error};
///
/// fn fail_if_negative(i: i32) -> Result<i32, Error> {
/// if (i >= 0) {
@ -45,8 +45,8 @@ pub trait ResultPyErrExt<T> {
/// # Examples
///
/// ```
/// use anyhow::Result;
/// use cpython_ext::failure::{FallibleExt, PyErr};
/// use failure::Fallible as Result;
///
/// fn eval_py() -> Result<i32> {
/// let gil = cpython::Python::acquire_gil();
@ -68,10 +68,10 @@ pub trait FallibleExt<T> {
fn into_fallible(self) -> Result<T>;
}
impl<T, E: AsFail> ResultPyErrExt<T> for std::result::Result<T, E> {
impl<T, E: Into<Error>> ResultPyErrExt<T> for Result<T, E> {
fn map_pyerr<PE: PythonObjectWithTypeObject>(self, py: Python<'_>) -> PyResult<T> {
self.map_err(|e| {
let e = e.as_fail();
let e = e.into();
if let Some(e) = e.downcast_ref::<PyErr>() {
e.inner.clone_ref(py)
} else {
@ -83,7 +83,7 @@ impl<T, E: AsFail> ResultPyErrExt<T> for std::result::Result<T, E> {
impl<T> FallibleExt<T> for PyResult<T> {
fn into_fallible(self) -> Result<T> {
self.map_err(|e| Error::from_boxed_compat(Box::new(PyErr::from(e))))
self.map_err(|e| Error::new(PyErr::from(e)))
}
}

View File

@ -7,9 +7,9 @@ edition = "2018"
indexedlog = { path = "../indexedlog" }
vlqencoding = { path = "../vlqencoding" }
anyhow = "1.0.20"
bitflags = "1"
byteorder = "1.2.7"
failure = "0.1.5"
fs2 = "0.4.3"
indexmap = "1.0.1"
tempfile = "3.0.7"

View File

@ -5,8 +5,8 @@
* GNU General Public License version 2.
*/
use anyhow::Result;
use dag::{idmap::IdMap, segment::Dag, spanset::SpanSet};
use failure::Fallible as Result;
use minibench::{bench, elapsed};
use tempfile::tempdir;

View File

@ -5,8 +5,8 @@
* GNU General Public License version 2.
*/
use anyhow::Result;
use dag::{idmap::IdMap, segment::Dag};
use failure::Fallible as Result;
use minibench::{
bench, elapsed,
measure::{self, Measure},

View File

@ -9,8 +9,8 @@
//!
//! See [`IdMap`] for the main structure.
use anyhow::{bail, ensure, Result};
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
use failure::{bail, ensure, Fallible as Result};
use fs2::FileExt;
use indexedlog::log;
use std::fs::{self, File};

View File

@ -16,9 +16,9 @@
use crate::spanset::Span;
use crate::spanset::SpanSet;
use anyhow::{bail, Result};
use bitflags::bitflags;
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use failure::{bail, Fallible as Result};
use fs2::FileExt;
use indexedlog::log;
use indexmap::set::IndexSet;

View File

@ -8,7 +8,7 @@
use crate::idmap::IdMap;
use crate::segment::Dag;
use crate::spanset::SpanSet;
use failure::Fallible as Result;
use anyhow::Result;
use tempfile::tempdir;
// Example from segmented-changelog.pdf

View File

@ -4,12 +4,12 @@ version = "0.1.0"
edition = "2018"
[dependencies]
anyhow = "1.0.20"
auth = { path = "../auth" }
blackbox = { path = "../blackbox" }
bytes = "0.4.11"
configparser = { path = "../configparser" }
curl = { version = "0.4.20", features = ["http2"] }
failure = "0.1.3"
http = "0.1.17"
itertools = "0.8.0"
lazy_static = "1.2"

View File

@ -187,7 +187,7 @@ mod tests {
use std::fs::File;
use failure::Fallible as Result;
use anyhow::Result;
use tempdir::TempDir;
use configparser::config::Options;

View File

@ -7,13 +7,13 @@
use std::{cmp, sync::mpsc::channel, sync::Arc, thread, time::Instant};
use anyhow::{format_err, Result};
use bytes::Bytes;
use curl::{
self,
easy::{Easy2, Handler, HttpVersion, List},
multi::Multi,
};
use failure::{format_err, Fallible};
use itertools::Itertools;
use parking_lot::{Mutex, MutexGuard};
use serde::{de::DeserializeOwned, Serialize};
@ -583,7 +583,7 @@ fn prepare_cbor_post<H, R: Serialize>(
/// Check the integrity of the data in this entry and either return
/// the data or an integrity check failure depending on the validation
/// result and the user's configuration.
fn check_data(entry: &DataEntry, validate: bool) -> Fallible<Bytes> {
fn check_data(entry: &DataEntry, validate: bool) -> Result<Bytes> {
log::trace!("Validating data for: {}", entry.key());
let (data, validity) = entry.data();

View File

@ -7,11 +7,12 @@
use std::{
convert::TryInto,
error::Error as StdError,
fmt::{self, Display},
path::PathBuf,
};
use failure::{Backtrace, Error, Fail};
use anyhow::{Error, Result};
use http::StatusCode;
use thiserror::Error;
@ -59,13 +60,12 @@ impl ApiError {
}
}
impl Fail for ApiError {
fn cause(&self) -> Option<&dyn Fail> {
self.cause.as_ref().map(Error::as_fail)
}
fn backtrace(&self) -> Option<&Backtrace> {
self.cause.as_ref().map(Error::backtrace)
impl StdError for ApiError {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
match &self.cause {
Some(cause) => Some(&**cause),
None => None,
}
}
}

View File

@ -5,9 +5,9 @@ edition = "2018"
[dependencies]
watchman_client = { version = "0.1.0", path = "../watchman_client" }
anyhow = "1.0.20"
serde = "1"
serde_json = "1"
failure = "0.1.3"
[features]
default = []

View File

@ -5,7 +5,7 @@
* GNU General Public License version 2.
*/
use failure::Fallible as Result;
use anyhow::Result;
use serde_json::json;
use std::path::{Path, PathBuf};
use watchman_client::queries::*;

View File

@ -6,9 +6,9 @@ edition = "2018"
[dependencies]
hg_watchman_client = { version = "0.1.0", path = "../" }
watchman_client = { version = "0.1.0", path = "../../watchman_client/" }
anyhow = "1.0.20"
clap = "2.32.0"
serde = { version = "1", features = ["derive"] }
failure = "0.1.3"
[features]
default = []

View File

@ -55,7 +55,7 @@ macro_rules! println_result {
}
mod test_client {
use failure::bail;
use anyhow::{bail, Result};
use hg_watchman_client::{
HgWatchmanClient, QueryResponse, StateEnterResponse, StateLeaveResponse,
};
@ -69,8 +69,6 @@ mod test_client {
use watchman_client::protocol::{JsonProtocol, Protocol};
use watchman_client::transport::Transport;
type Result<T> = std::result::Result<T, failure::Error>;
static FILENAME: &str = "tester_watchmanstate";
#[derive(Clone, Default, Debug, Serialize, Deserialize)]

View File

@ -9,13 +9,13 @@ python2 = []
python3 = []
[dependencies]
anyhow = "1.0.20"
bindings = { path = "../../edenscmnative/bindings" }
blackbox = { path = "../blackbox" }
clidispatch = { path = "../clidispatch" }
cliparser = { path = "../cliparser", features = ["python"] }
cpython-ext = { path = "../cpython-ext" }
edenapi = { path = "../edenapi" }
failure = "0.1"
flate2 = "1"
hgtime = { path = "../hgtime"}
indexedlog = { path = "../indexedlog" }

View File

@ -5,6 +5,7 @@
* GNU General Public License version 2.
*/
use anyhow::Result;
use clidispatch::{
command::{CommandTable, Register},
errors,
@ -12,7 +13,6 @@ use clidispatch::{
repo::Repo,
};
use cliparser::define_flags;
use failure::Fallible as Result;
use blackbox::{event::Event, json, SessionId};
use edenapi::{Config as EdenApiConfig, EdenApi, EdenApiCurlClient};

View File

@ -6,8 +6,8 @@
*/
use crate::{commands, HgPython};
use anyhow::Result;
use clidispatch::{dispatch, errors};
use failure::Fallible as Result;
use parking_lot::Mutex;
use std::env;
use std::fs::File;

View File

@ -21,7 +21,7 @@ use std::path::Path;
// - The library can change error structure internals. That means accesses
// to the error object are via public methods instead of struct or enum
// fields. `Error` is the only opaque public error type.
// - Compatible with std Error. Therefore failure::Error is supported too.
// - Compatible with std Error. Therefore anyhow::Error is supported too.
/// Represents all possible errors that can occur when using indexedlog.
pub struct Error {

View File

@ -5,8 +5,8 @@ authors = ["Facebook Source Control Team <sourcecontrol-dev@fb.com>"]
edition = "2018"
[dependencies]
anyhow = "1.0.20"
byteorder = "1"
failure = "0"
libc = "0.2"
lz4-sys = "1"
thiserror = "1.0.5"

View File

@ -5,8 +5,8 @@
* GNU General Public License version 2.
*/
use anyhow::Result;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use failure::Fallible as Result;
use libc::{c_int, c_void};
use lz4_sys::{
LZ4StreamDecode, LZ4StreamEncode, LZ4_compressBound, LZ4_compress_continue, LZ4_createStream,

View File

@ -9,8 +9,8 @@ default = []
for-tests = ["quickcheck"]
[dependencies]
anyhow = "1.0.20"
bytes = { version = "0.4.11", features = ["serde"] }
failure = "0.1.3"
once_cell = "1.0.2"
quickcheck = { version = "0.9", optional = true }
rand = { version = "0.7", optional = true }

View File

@ -12,7 +12,7 @@
//! repository. The file path and file revision are then used to retrieve the contents of the
//! file thus achieving the reconstruction of the entire repository state.
use failure::Fallible as Result;
use anyhow::Result;
use types::{HgId, RepoPath, RepoPathBuf};

View File

@ -7,7 +7,7 @@
use std::collections::btree_map;
use failure::Error;
use anyhow::Error;
use types::{PathComponentBuf, RepoPath, RepoPathBuf};

View File

@ -7,7 +7,7 @@
use std::{cmp::Ordering, collections::VecDeque, mem};
use failure::Fallible as Result;
use anyhow::Result;
use pathmatcher::{DirectoryMatch, Matcher};
use types::{RepoPath, RepoPathBuf};

View File

@ -7,7 +7,7 @@
use std::{collections::VecDeque, mem};
use failure::Fallible as Result;
use anyhow::Result;
use pathmatcher::{DirectoryMatch, Matcher};
use types::{HgId, RepoPathBuf};

View File

@ -7,7 +7,7 @@
use std::{collections::BTreeMap, sync::Arc};
use failure::{bail, format_err, Fallible as Result};
use anyhow::{bail, format_err, Result};
use once_cell::sync::OnceCell;
use types::{HgId, PathComponentBuf, RepoPath};

View File

@ -20,9 +20,9 @@ use std::{
sync::Arc,
};
use anyhow::{bail, Result};
use bytes::Bytes;
use crypto::{digest::Digest, sha1::Sha1};
use failure::{bail, Fallible as Result};
use once_cell::sync::OnceCell;
use pathmatcher::Matcher;

View File

@ -7,8 +7,8 @@
use std::{str::from_utf8, sync::Arc};
use anyhow::{format_err, Result};
use bytes::{Bytes, BytesMut};
use failure::{format_err, Fallible as Result};
use types::{HgId, Key, PathComponent, PathComponentBuf, RepoPath};

View File

@ -7,7 +7,7 @@
use std::sync::Arc;
use failure::Fallible as Result;
use anyhow::Result;
use types::{testutil::*, HgId, RepoPath};

Some files were not shown because too many files have changed in this diff Show More