Skip to content

Commit 920d552

Browse files
committed
Replace CargoError with failure::Error
1 parent 4786249 commit 920d552

File tree

16 files changed

+41
-45
lines changed

16 files changed

+41
-45
lines changed

src/bin/cargo/commands/login.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::io::{self, BufRead};
55
use cargo::core::{Source, SourceId};
66
use cargo::ops;
77
use cargo::sources::RegistrySource;
8-
use cargo::util::{CargoError, CargoResultExt};
8+
use cargo::util::CargoResultExt;
99

1010
pub fn cli() -> App {
1111
subcommand("login")
@@ -49,7 +49,7 @@ pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
4949
.lock()
5050
.read_line(&mut line)
5151
.chain_err(|| "failed to read stdin")
52-
.map_err(CargoError::from)?;
52+
.map_err(failure::Error::from)?;
5353
line.trim().to_string()
5454
}
5555
};

src/cargo/core/dependency.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use serde::Serialize;
1010

1111
use crate::core::interning::InternedString;
1212
use crate::core::{PackageId, SourceId, Summary};
13-
use crate::util::errors::{CargoError, CargoResult, CargoResultExt};
13+
use crate::util::errors::{CargoResult, CargoResultExt};
1414
use crate::util::{Cfg, CfgExpr, Config};
1515

1616
/// Information about a dependency requested by a Cargo manifest.
@@ -449,7 +449,7 @@ impl ser::Serialize for Platform {
449449
}
450450

451451
impl FromStr for Platform {
452-
type Err = CargoError;
452+
type Err = failure::Error;
453453

454454
fn from_str(s: &str) -> CargoResult<Platform> {
455455
if s.starts_with("cfg(") && s.ends_with(')') {

src/cargo/core/resolver/encode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use serde::ser;
88
use serde::{Deserialize, Serialize};
99

1010
use crate::core::{Dependency, Package, PackageId, SourceId, Workspace};
11-
use crate::util::errors::{CargoError, CargoResult, CargoResultExt};
11+
use crate::util::errors::{CargoResult, CargoResultExt};
1212
use crate::util::{internal, Graph};
1313

1414
use super::Resolve;
@@ -276,7 +276,7 @@ impl fmt::Display for EncodablePackageId {
276276
}
277277

278278
impl FromStr for EncodablePackageId {
279-
type Err = CargoError;
279+
type Err = failure::Error;
280280

281281
fn from_str(s: &str) -> CargoResult<EncodablePackageId> {
282282
let mut s = s.splitn(3, ' ');

src/cargo/core/resolver/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33

44
use crate::core::{Dependency, PackageId, Registry, Summary};
55
use crate::util::lev_distance::lev_distance;
6-
use crate::util::{CargoError, Config};
6+
use crate::util::Config;
77
use failure::{Error, Fail};
88
use semver;
99

@@ -52,7 +52,7 @@ impl fmt::Display for ResolveError {
5252
pub type ActivateResult<T> = Result<T, ActivateError>;
5353

5454
pub enum ActivateError {
55-
Fatal(CargoError),
55+
Fatal(failure::Error),
5656
Conflict(PackageId, ConflictReason),
5757
}
5858

src/cargo/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::core::shell::Verbosity::Verbose;
2727
use crate::core::Shell;
2828

2929
pub use crate::util::errors::Internal;
30-
pub use crate::util::{CargoError, CargoResult, CliError, CliResult, Config};
30+
pub use crate::util::{CargoResult, CliError, CliResult, Config};
3131

3232
pub const CARGO_ENV: &str = "CARGO";
3333

@@ -126,7 +126,7 @@ pub fn exit_with_error(err: CliError, shell: &mut Shell) -> ! {
126126
std::process::exit(exit_code)
127127
}
128128

129-
pub fn handle_error(err: &CargoError, shell: &mut Shell) {
129+
pub fn handle_error(err: &failure::Error, shell: &mut Shell) {
130130
debug!("handle_error; err={:?}", err);
131131

132132
let _ignored_result = shell.error(err);

src/cargo/ops/cargo_read_manifest.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::{Path, PathBuf};
66
use log::{info, trace};
77

88
use crate::core::{EitherManifest, Package, PackageId, SourceId};
9-
use crate::util::errors::{CargoError, CargoResult};
9+
use crate::util::errors::CargoResult;
1010
use crate::util::important_paths::find_project_manifest_exact;
1111
use crate::util::toml::read_manifest;
1212
use crate::util::{self, Config};
@@ -41,7 +41,7 @@ pub fn read_packages(
4141
) -> CargoResult<Vec<Package>> {
4242
let mut all_packages = HashMap::new();
4343
let mut visited = HashSet::<PathBuf>::new();
44-
let mut errors = Vec::<CargoError>::new();
44+
let mut errors = Vec::<failure::Error>::new();
4545

4646
trace!(
4747
"looking for root package: {}, source_id={}",
@@ -111,7 +111,7 @@ fn walk(path: &Path, callback: &mut dyn FnMut(&Path) -> CargoResult<bool>) -> Ca
111111
Err(ref e) if e.kind() == io::ErrorKind::PermissionDenied => return Ok(()),
112112
Err(e) => {
113113
let cx = format!("failed to read directory `{}`", path.display());
114-
let e = CargoError::from(e);
114+
let e = failure::Error::from(e);
115115
return Err(e.context(cx).into());
116116
}
117117
};
@@ -134,7 +134,7 @@ fn read_nested_packages(
134134
source_id: SourceId,
135135
config: &Config,
136136
visited: &mut HashSet<PathBuf>,
137-
errors: &mut Vec<CargoError>,
137+
errors: &mut Vec<failure::Error>,
138138
) -> CargoResult<()> {
139139
if !visited.insert(path.to_path_buf()) {
140140
return Ok(());

src/cargo/sources/git/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use serde::Serialize;
1313
use url::Url;
1414

1515
use crate::core::GitReference;
16-
use crate::util::errors::{CargoError, CargoResult, CargoResultExt};
16+
use crate::util::errors::{CargoResult, CargoResultExt};
1717
use crate::util::paths;
1818
use crate::util::process_builder::process;
1919
use crate::util::{internal, network, Config, Progress, ToUrl};
@@ -69,7 +69,7 @@ pub struct GitDatabase {
6969

7070
/// `GitCheckout` is a local checkout of a particular revision. Calling
7171
/// `clone_into` with a reference will resolve the reference into a revision,
72-
/// and return a `CargoError` if no revision for that reference was found.
72+
/// and return a `failure::Error` if no revision for that reference was found.
7373
#[derive(Serialize)]
7474
pub struct GitCheckout<'a> {
7575
database: &'a GitDatabase,
@@ -587,7 +587,7 @@ where
587587
// In the case of an authentication failure (where we tried something) then
588588
// we try to give a more helpful error message about precisely what we
589589
// tried.
590-
let res = res.map_err(CargoError::from).chain_err(|| {
590+
let res = res.map_err(failure::Error::from).chain_err(|| {
591591
let mut msg = "failed to authenticate when downloading \
592592
repository"
593593
.to_string();

src/cargo/util/cfg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22
use std::iter;
33
use std::str::{self, FromStr};
44

5-
use crate::util::{CargoError, CargoResult};
5+
use crate::util::CargoResult;
66

77
#[derive(Eq, PartialEq, Hash, Ord, PartialOrd, Clone, Debug)]
88
pub enum Cfg {
@@ -38,7 +38,7 @@ struct Parser<'a> {
3838
}
3939

4040
impl FromStr for Cfg {
41-
type Err = CargoError;
41+
type Err = failure::Error;
4242

4343
fn from_str(s: &str) -> CargoResult<Cfg> {
4444
let mut p = Parser::new(s);
@@ -85,7 +85,7 @@ impl CfgExpr {
8585
}
8686

8787
impl FromStr for CfgExpr {
88-
type Err = CargoError;
88+
type Err = failure::Error;
8989

9090
fn from_str(s: &str) -> CargoResult<CfgExpr> {
9191
let mut p = Parser::new(s);

src/cargo/util/errors.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use log::trace;
1111

1212
use crate::core::{TargetKind, Workspace};
1313

14-
pub use failure::Error as CargoError;
15-
pub type CargoResult<T> = Result<T, Error>;
14+
pub type CargoResult<T> = failure::Fallible<T>; // Alex's body isn't quite ready to give up "Result"
1615

1716
pub trait CargoResultExt<T, E> {
1817
fn chain_err<F, D>(self, f: F) -> Result<T, Context<D>>
@@ -232,13 +231,13 @@ pub type CliResult = Result<(), CliError>;
232231

233232
#[derive(Debug)]
234233
pub struct CliError {
235-
pub error: Option<CargoError>,
234+
pub error: Option<failure::Error>,
236235
pub unknown: bool,
237236
pub exit_code: i32,
238237
}
239238

240239
impl CliError {
241-
pub fn new(error: CargoError, code: i32) -> CliError {
240+
pub fn new(error: failure::Error, code: i32) -> CliError {
242241
let unknown = error.downcast_ref::<Internal>().is_some();
243242
CliError {
244243
error: Some(error),
@@ -256,8 +255,8 @@ impl CliError {
256255
}
257256
}
258257

259-
impl From<CargoError> for CliError {
260-
fn from(err: CargoError) -> CliError {
258+
impl From<failure::Error> for CliError {
259+
fn from(err: failure::Error) -> CliError {
261260
CliError::new(err, 101)
262261
}
263262
}
@@ -342,10 +341,10 @@ pub fn process_error(
342341
}
343342
}
344343

345-
pub fn internal<S: fmt::Display>(error: S) -> CargoError {
344+
pub fn internal<S: fmt::Display>(error: S) -> failure::Error {
346345
_internal(&error)
347346
}
348347

349-
fn _internal(error: &dyn fmt::Display) -> CargoError {
348+
fn _internal(error: &dyn fmt::Display) -> failure::Error {
350349
Internal::new(format_err!("{}", error)).into()
351350
}

src/cargo/util/flock.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use fs2::{lock_contended_error, FileExt};
88
use libc;
99
use termcolor::Color::Cyan;
1010

11-
use crate::util::errors::{CargoError, CargoResult, CargoResultExt};
11+
use crate::util::errors::{CargoResult, CargoResultExt};
1212
use crate::util::paths;
1313
use crate::util::Config;
1414

@@ -303,7 +303,7 @@ fn acquire(
303303

304304
Err(e) => {
305305
if e.raw_os_error() != lock_contended_error().raw_os_error() {
306-
let e = CargoError::from(e);
306+
let e = failure::Error::from(e);
307307
let cx = format!("failed to lock file: {}", path.display());
308308
return Err(e.context(cx).into());
309309
}

0 commit comments

Comments
 (0)