diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a3e8c8..a8c209b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- **BREAKING** migrated generic error return types from `failure::Error` to `anyhow::Error`. +- **BREAKING** `prepare::PrepareError` is now based on `thiserror::Error`, and not `failure::Fail` any more. +- **BREAKING** `toolchain::ToolchainError` is now based on `thiserror::Error`, and not `failure::Fail` any more. + ## [0.16.0] - 2023-05-02 ### Added @@ -17,14 +23,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -* CI toolchains can now install additional targets and components. +- CI toolchains can now install additional targets and components. ## [0.15.1] - 2022-09-04 ### Changed -* Updated `nix` dependency to 0.25. -* Replaced `winapi` dependency with `windows-sys`. +- Updated `nix` dependency to 0.25. +- Replaced `winapi` dependency with `windows-sys`. ## [0.15.0] - 2022-05-22 @@ -85,7 +91,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed -* Updated tokio dependency to 1.0. +- Updated tokio dependency to 1.0. ## [0.11.0] - 2020-10-30 diff --git a/Cargo.toml b/Cargo.toml index 3013461..d478f14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ unstable-toolchain-ci = [] [dependencies] http = "0.2" -failure = "0.1.3" +anyhow = { version = "1.0.68", features = ["backtrace"]} futures-util = "0.3.5" log = "0.4.6" tokio = { version = "1.0", features = ["process", "time", "io-util", "rt", "rt-multi-thread"] } diff --git a/src/build.rs b/src/build.rs index 0a23625..07b73db 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1,7 +1,7 @@ use crate::cmd::{Command, MountKind, Runnable, SandboxBuilder}; use crate::prepare::Prepare; use crate::{Crate, Toolchain, Workspace}; -use failure::Error; +use anyhow::Result; use std::path::PathBuf; use std::vec::Vec; @@ -131,7 +131,7 @@ impl<'a> BuildBuilder<'a> { /// })?; /// # Ok(()) /// # } - pub fn run Result>(self, f: F) -> Result { + pub fn run Result>(self, f: F) -> Result { self.build_dir .run(self.toolchain, self.krate, self.sandbox, self.patches, f) } @@ -181,14 +181,14 @@ impl BuildDirectory { } } - pub(crate) fn run Result>( + pub(crate) fn run Result>( &mut self, toolchain: &Toolchain, krate: &Crate, sandbox: SandboxBuilder, patches: Vec, f: F, - ) -> Result { + ) -> Result { let source_dir = self.source_dir(); if source_dir.exists() { crate::utils::remove_dir_all(&source_dir)?; @@ -209,7 +209,7 @@ impl BuildDirectory { } /// Remove all the contents of the build directory, freeing disk space. - pub fn purge(&mut self) -> Result<(), Error> { + pub fn purge(&mut self) -> Result<()> { let build_dir = self.build_dir(); if build_dir.exists() { crate::utils::remove_dir_all(&build_dir)?; @@ -322,7 +322,7 @@ impl<'ws> Build<'ws> { /// networking is disabled. #[cfg(any(feature = "unstable", doc))] #[cfg_attr(docs_rs, doc(cfg(feature = "unstable")))] - pub fn fetch_build_std_dependencies(&self, targets: &[&str]) -> Result<(), Error> { + pub fn fetch_build_std_dependencies(&self, targets: &[&str]) -> Result<()> { crate::prepare::fetch_deps( &self.dir.workspace, self.toolchain, diff --git a/src/crates/git.rs b/src/crates/git.rs index 37e8222..4956022 100644 --- a/src/crates/git.rs +++ b/src/crates/git.rs @@ -2,7 +2,7 @@ use super::CrateTrait; use crate::cmd::{Command, ProcessLinesActions}; use crate::prepare::PrepareError; use crate::Workspace; -use failure::{Error, ResultExt}; +use anyhow::{Context as _, Result}; use log::{info, warn}; use std::path::{Path, PathBuf}; @@ -63,7 +63,7 @@ impl GitRepo { } impl CrateTrait for GitRepo { - fn fetch(&self, workspace: &Workspace) -> Result<(), Error> { + fn fetch(&self, workspace: &Workspace) -> Result<()> { // The credential helper that suppresses the password prompt shows this message when a // repository requires authentication: // @@ -86,7 +86,7 @@ impl CrateTrait for GitRepo { .cd(&path) .process_lines(&mut detect_private_repositories) .run() - .with_context(|_| format!("failed to update {}", self.url)) + .with_context(|| format!("failed to update {}", self.url)) } else { info!("cloning repository {}", self.url); Command::new(workspace, "git") @@ -95,7 +95,7 @@ impl CrateTrait for GitRepo { .args(&[&path]) .process_lines(&mut detect_private_repositories) .run() - .with_context(|_| format!("failed to clone {}", self.url)) + .with_context(|| format!("failed to clone {}", self.url)) }; if private_repository && res.is_err() { @@ -105,7 +105,7 @@ impl CrateTrait for GitRepo { } } - fn purge_from_cache(&self, workspace: &Workspace) -> Result<(), Error> { + fn purge_from_cache(&self, workspace: &Workspace) -> Result<()> { let path = self.cached_path(workspace); if path.exists() { crate::utils::remove_dir_all(&path)?; @@ -113,12 +113,12 @@ impl CrateTrait for GitRepo { Ok(()) } - fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error> { + fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<()> { Command::new(workspace, "git") .args(&["clone"]) .args(&[self.cached_path(workspace).as_path(), dest]) .run() - .with_context(|_| format!("failed to checkout {}", self.url))?; + .with_context(|| format!("failed to checkout {}", self.url))?; Ok(()) } } diff --git a/src/crates/local.rs b/src/crates/local.rs index 4c85f83..9dea595 100644 --- a/src/crates/local.rs +++ b/src/crates/local.rs @@ -1,6 +1,6 @@ use super::CrateTrait; use crate::Workspace; -use failure::Error; +use anyhow::Result; use log::info; use std::path::{Path, PathBuf}; use walkdir::WalkDir; @@ -16,17 +16,17 @@ impl Local { } impl CrateTrait for Local { - fn fetch(&self, _workspace: &Workspace) -> Result<(), Error> { + fn fetch(&self, _workspace: &Workspace) -> Result<()> { // There is no fetch to do for a local crate. Ok(()) } - fn purge_from_cache(&self, _workspace: &Workspace) -> Result<(), Error> { + fn purge_from_cache(&self, _workspace: &Workspace) -> Result<()> { // There is no cache to purge for a local crate. Ok(()) } - fn copy_source_to(&self, _workspace: &Workspace, dest: &Path) -> Result<(), Error> { + fn copy_source_to(&self, _workspace: &Workspace, dest: &Path) -> Result<()> { info!( "copying local crate from {} to {}", self.path.display(), @@ -43,7 +43,7 @@ impl std::fmt::Display for Local { } } -fn copy_dir(src: &Path, dest: &Path) -> Result<(), Error> { +fn copy_dir(src: &Path, dest: &Path) -> Result<()> { let src = crate::utils::normalize_path(src); let dest = crate::utils::normalize_path(dest); @@ -75,10 +75,10 @@ fn copy_dir(src: &Path, dest: &Path) -> Result<(), Error> { #[cfg(test)] mod tests { - use failure::Error; + use anyhow::Result; #[test] - fn test_copy_dir() -> Result<(), Error> { + fn test_copy_dir() -> Result<()> { let tmp_src = tempfile::tempdir()?; let tmp_dest = tempfile::tempdir()?; @@ -99,7 +99,7 @@ mod tests { } #[test] - fn test_no_copy_target() -> Result<(), Error> { + fn test_no_copy_target() -> Result<()> { let (src, dest) = (tempfile::tempdir()?, tempfile::tempdir()?); std::fs::create_dir(src.path().join("target"))?; std::fs::write( @@ -116,7 +116,7 @@ mod tests { } #[test] - fn test_copy_symlinks() -> Result<(), Error> { + fn test_copy_symlinks() -> Result<()> { use std::{fs, os, path::Path}; let tmp_src = tempfile::tempdir()?; diff --git a/src/crates/mod.rs b/src/crates/mod.rs index 5c42968..237a4cc 100644 --- a/src/crates/mod.rs +++ b/src/crates/mod.rs @@ -3,16 +3,16 @@ mod local; mod registry; use crate::Workspace; -use failure::Error; +use anyhow::Result; use log::info; use std::path::Path; pub use registry::AlternativeRegistry; trait CrateTrait: std::fmt::Display { - fn fetch(&self, workspace: &Workspace) -> Result<(), Error>; - fn purge_from_cache(&self, workspace: &Workspace) -> Result<(), Error>; - fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error>; + fn fetch(&self, workspace: &Workspace) -> Result<()>; + fn purge_from_cache(&self, workspace: &Workspace) -> Result<()>; + fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<()>; } enum CrateType { @@ -56,12 +56,12 @@ impl Crate { /// Fetch the crate's source code and cache it in the workspace. This method will reach out to /// the network for some crate types. - pub fn fetch(&self, workspace: &Workspace) -> Result<(), Error> { + pub fn fetch(&self, workspace: &Workspace) -> Result<()> { self.as_trait().fetch(workspace) } /// Remove the cached copy of this crate. The method will do nothing if the crate isn't cached. - pub fn purge_from_cache(&self, workspace: &Workspace) -> Result<(), Error> { + pub fn purge_from_cache(&self, workspace: &Workspace) -> Result<()> { self.as_trait().purge_from_cache(workspace) } @@ -75,7 +75,7 @@ impl Crate { } } - pub(crate) fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error> { + pub(crate) fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<()> { if dest.exists() { info!( "crate source directory {} already exists, cleaning it up", diff --git a/src/crates/registry.rs b/src/crates/registry.rs index eac78dc..19c7014 100644 --- a/src/crates/registry.rs +++ b/src/crates/registry.rs @@ -1,6 +1,6 @@ use super::CrateTrait; use crate::Workspace; -use failure::{Error, ResultExt}; +use anyhow::{Context as _, Result}; use flate2::read::GzDecoder; use log::info; use std::fs::File; @@ -88,7 +88,7 @@ impl RegistryCrate { .join(format!("{}-{}.crate", self.name, self.version)) } - fn fetch_url(&self, workspace: &Workspace) -> Result { + fn fetch_url(&self, workspace: &Workspace) -> Result { match &self.registry { Registry::CratesIo => Ok(format!( "{0}/{1}/{1}-{2}.crate", @@ -122,7 +122,7 @@ impl RegistryCrate { git2::build::RepoBuilder::new() .fetch_options(fo) .clone(url, &index_path) - .with_context(|_| format!("unable to update_index at {}", url))?; + .with_context(|| format!("unable to update_index at {}", url))?; info!("cloned registry index"); } let config = std::fs::read_to_string(index_path.join("config.json"))?; @@ -151,7 +151,7 @@ impl RegistryCrate { } impl CrateTrait for RegistryCrate { - fn fetch(&self, workspace: &Workspace) -> Result<(), Error> { + fn fetch(&self, workspace: &Workspace) -> Result<()> { let local = self.cache_path(workspace); if local.exists() { info!("crate {} {} is already in cache", self.name, self.version); @@ -173,7 +173,7 @@ impl CrateTrait for RegistryCrate { Ok(()) } - fn purge_from_cache(&self, workspace: &Workspace) -> Result<(), Error> { + fn purge_from_cache(&self, workspace: &Workspace) -> Result<()> { let path = self.cache_path(workspace); if path.exists() { crate::utils::remove_file(&path)?; @@ -181,7 +181,7 @@ impl CrateTrait for RegistryCrate { Ok(()) } - fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<(), Error> { + fn copy_source_to(&self, workspace: &Workspace, dest: &Path) -> Result<()> { let cached = self.cache_path(workspace); let mut file = File::open(cached)?; let mut tar = Archive::new(GzDecoder::new(BufReader::new(&mut file))); @@ -194,12 +194,10 @@ impl CrateTrait for RegistryCrate { ); if let Err(err) = unpack_without_first_dir(&mut tar, dest) { let _ = crate::utils::remove_dir_all(dest); - Err(err - .context(format!( - "unable to download {} version {}", - self.name, self.version - )) - .into()) + Err(err.context(format!( + "unable to download {} version {}", + self.name, self.version + ))) } else { Ok(()) } @@ -218,7 +216,7 @@ impl std::fmt::Display for RegistryCrate { } } -fn unpack_without_first_dir(archive: &mut Archive, path: &Path) -> Result<(), Error> { +fn unpack_without_first_dir(archive: &mut Archive, path: &Path) -> Result<()> { let entries = archive.entries()?; for entry in entries { let mut entry = entry?; diff --git a/src/inside_docker.rs b/src/inside_docker.rs index d2c0853..b52391b 100644 --- a/src/inside_docker.rs +++ b/src/inside_docker.rs @@ -1,6 +1,6 @@ use crate::cmd::Command; use crate::workspace::Workspace; -use failure::Error; +use anyhow::Result; use getrandom::getrandom; use log::info; @@ -11,7 +11,7 @@ pub(crate) struct CurrentContainer { } impl CurrentContainer { - pub(crate) fn detect(workspace: &Workspace) -> Result, Error> { + pub(crate) fn detect(workspace: &Workspace) -> Result> { if let Some(id) = probe_container_id(workspace)? { info!("inspecting the current container"); let inspect = Command::new(workspace, "docker") @@ -22,7 +22,7 @@ impl CurrentContainer { let content = inspect.stdout_lines().join("\n"); let mut metadata: Vec = serde_json::from_str(&content)?; if metadata.len() != 1 { - failure::bail!("invalid output returned by `docker inspect`"); + anyhow::bail!("invalid output returned by `docker inspect`"); } Ok(Some(CurrentContainer { metadata: metadata.pop().unwrap(), @@ -44,7 +44,7 @@ impl CurrentContainer { /// This function uses a simpler but slower method to get the ID: a file with a random string is /// created in the temp directory, the list of all the containers is fetched from Docker and then /// `cat` is executed inside each of them to check whether they have the same random string. -pub(crate) fn probe_container_id(workspace: &Workspace) -> Result, Error> { +pub(crate) fn probe_container_id(workspace: &Workspace) -> Result> { info!("detecting the ID of the container where rustwide is running"); // Create the probe on the current file system diff --git a/src/native/unix.rs b/src/native/unix.rs index a5df3f2..a9c7e11 100644 --- a/src/native/unix.rs +++ b/src/native/unix.rs @@ -1,6 +1,6 @@ use super::CurrentUser; use crate::cmd::KillFailedError; -use failure::Error; +use anyhow::Result; use nix::{ sys::signal::{kill, Signal}, unistd::{Gid, Pid, Uid}, @@ -29,7 +29,7 @@ pub(crate) fn current_user() -> Option { }) } -fn executable_mode_for(path: &Path) -> Result { +fn executable_mode_for(path: &Path) -> Result { let metadata = path.metadata()?; let user = current_user().unwrap(); @@ -43,14 +43,14 @@ fn executable_mode_for(path: &Path) -> Result { } } -pub(crate) fn is_executable>(path: P) -> Result { +pub(crate) fn is_executable>(path: P) -> Result { let path = path.as_ref(); let expected_mode = executable_mode_for(path)?; Ok(path.metadata()?.mode() & expected_mode == expected_mode) } -pub(crate) fn make_executable>(path: P) -> Result<(), Error> { +pub(crate) fn make_executable>(path: P) -> Result<()> { let path = path.as_ref(); // Set the executable and readable bits on the file diff --git a/src/native/windows.rs b/src/native/windows.rs index c78e6d1..b10ba46 100644 --- a/src/native/windows.rs +++ b/src/native/windows.rs @@ -1,6 +1,6 @@ use super::CurrentUser; use crate::cmd::KillFailedError; -use failure::Error; +use anyhow::{anyhow, Result}; use std::fs::File; use std::path::Path; use windows_sys::Win32::Foundation::CloseHandle; @@ -29,26 +29,26 @@ pub(crate) fn current_user() -> Option { None } -fn path_ends_in_exe>(path: P) -> Result { +fn path_ends_in_exe>(path: P) -> Result { path.as_ref() .extension() - .ok_or_else(|| failure::format_err!("Unable to get `Path` extension")) + .ok_or_else(|| anyhow!("Unable to get `Path` extension")) .map(|ext| ext == "exe") } /// Check that the file exists and has `.exe` as its extension. -pub(crate) fn is_executable>(path: P) -> Result { +pub(crate) fn is_executable>(path: P) -> Result { let path = path.as_ref(); File::open(path) .map_err(Into::into) .and_then(|_| path_ends_in_exe(path)) } -pub(crate) fn make_executable>(path: P) -> Result<(), Error> { +pub(crate) fn make_executable>(path: P) -> Result<()> { if is_executable(path)? { Ok(()) } else { - failure::bail!("Downloaded binaries should be executable by default"); + anyhow::bail!("Downloaded binaries should be executable by default"); } } diff --git a/src/prepare.rs b/src/prepare.rs index 402db27..f639bae 100644 --- a/src/prepare.rs +++ b/src/prepare.rs @@ -1,6 +1,6 @@ use crate::cmd::Command; use crate::{build::CratePatch, Crate, Toolchain, Workspace}; -use failure::{Error, Fail, ResultExt}; +use anyhow::{Context as _, Result}; use log::info; use std::path::Path; use toml::{ @@ -33,7 +33,7 @@ impl<'a> Prepare<'a> { } } - pub(crate) fn prepare(&mut self) -> Result<(), Error> { + pub(crate) fn prepare(&mut self) -> Result<()> { self.krate.copy_source_to(self.workspace, self.source_dir)?; self.validate_manifest()?; self.remove_override_files()?; @@ -44,7 +44,7 @@ impl<'a> Prepare<'a> { Ok(()) } - fn validate_manifest(&self) -> Result<(), Error> { + fn validate_manifest(&self) -> Result<()> { info!( "validating manifest of {} on toolchain {}", self.krate, self.toolchain @@ -67,7 +67,7 @@ impl<'a> Prepare<'a> { Ok(()) } - fn remove_override_files(&self) -> Result<(), Error> { + fn remove_override_files(&self) -> Result<()> { let paths = [ &Path::new(".cargo").join("config"), &Path::new(".cargo").join("config.toml"), @@ -84,7 +84,7 @@ impl<'a> Prepare<'a> { Ok(()) } - fn tweak_toml(&self) -> Result<(), Error> { + fn tweak_toml(&self) -> Result<()> { let path = self.source_dir.join("Cargo.toml"); let mut tweaker = TomlTweaker::new(self.krate, &path, &self.patches)?; tweaker.tweak(); @@ -92,7 +92,7 @@ impl<'a> Prepare<'a> { Ok(()) } - fn capture_lockfile(&mut self) -> Result<(), Error> { + fn capture_lockfile(&mut self) -> Result<()> { if self.source_dir.join("Cargo.lock").exists() { info!( "crate {} already has a lockfile, it will not be regenerated", @@ -137,7 +137,7 @@ impl<'a> Prepare<'a> { Ok(()) } - fn fetch_deps(&mut self) -> Result<(), Error> { + fn fetch_deps(&mut self) -> Result<()> { fetch_deps(self.workspace, self.toolchain, self.source_dir, &[]) } } @@ -147,7 +147,7 @@ pub(crate) fn fetch_deps( toolchain: &Toolchain, source_dir: &Path, fetch_build_std_targets: &[&str], -) -> Result<(), Error> { +) -> Result<()> { let mut missing_deps = false; let mut cmd = Command::new(workspace, toolchain.cargo()) .args(&["fetch", "--manifest-path", "Cargo.toml"]) @@ -183,15 +183,11 @@ struct TomlTweaker<'a> { } impl<'a> TomlTweaker<'a> { - pub fn new( - krate: &'a Crate, - cargo_toml: &'a Path, - patches: &[CratePatch], - ) -> Result { - let toml_content = ::std::fs::read_to_string(cargo_toml) - .with_context(|_| PrepareError::MissingCargoToml)?; + pub fn new(krate: &'a Crate, cargo_toml: &'a Path, patches: &[CratePatch]) -> Result { + let toml_content = + ::std::fs::read_to_string(cargo_toml).context(PrepareError::MissingCargoToml)?; let table: Table = - toml::from_str(&toml_content).with_context(|_| PrepareError::InvalidCargoTomlSyntax)?; + toml::from_str(&toml_content).context(PrepareError::InvalidCargoTomlSyntax)?; let dir = cargo_toml.parent(); @@ -353,7 +349,7 @@ impl<'a> TomlTweaker<'a> { } } - pub fn save(self, output_file: &Path) -> Result<(), Error> { + pub fn save(self, output_file: &Path) -> Result<()> { let crate_name = self.krate.to_string(); ::std::fs::write(output_file, Value::Table(self.table).to_string().as_bytes())?; info!( @@ -367,24 +363,24 @@ impl<'a> TomlTweaker<'a> { } /// Error happened while preparing a crate for a build. -#[derive(Debug, Fail)] +#[derive(Debug, thiserror::Error)] #[non_exhaustive] pub enum PrepareError { /// The git repository isn't publicly available. - #[fail(display = "can't fetch private git repositories")] + #[error("can't fetch private git repositories")] PrivateGitRepository, /// The crate doesn't have a `Cargo.toml` in its source code. - #[fail(display = "missing Cargo.toml")] + #[error("missing Cargo.toml")] MissingCargoToml, /// The crate's Cargo.toml is invalid, either due to a TOML syntax error in it or cargo /// rejecting it. - #[fail(display = "invalid Cargo.toml syntax")] + #[error("invalid Cargo.toml syntax")] InvalidCargoTomlSyntax, /// Some of this crate's dependencies were yanked, preventing Crater from fetching them. - #[fail(display = "the crate depends on yanked dependencies")] + #[error("the crate depends on yanked dependencies")] YankedDependencies, /// Some of the dependencies do not exist anymore. - #[fail(display = "the crate depends on missing dependencies")] + #[error("the crate depends on missing dependencies")] MissingDependencies, } diff --git a/src/toolchain.rs b/src/toolchain.rs index a2d1b6a..281f456 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -5,7 +5,7 @@ use crate::tools::RUSTUP; #[cfg(feature = "unstable-toolchain-ci")] use crate::tools::RUSTUP_TOOLCHAIN_INSTALL_MASTER; use crate::Workspace; -use failure::{Error, ResultExt}; +use anyhow::{anyhow, Context as _, Result}; use log::info; use std::borrow::Cow; use std::path::Path; @@ -13,18 +13,18 @@ use std::path::Path; pub(crate) const MAIN_TOOLCHAIN_NAME: &str = "stable"; /// Error caused by methods in the `toolchain` moodule. -#[derive(Debug, failure::Fail)] +#[derive(Debug, thiserror::Error)] #[non_exhaustive] pub enum ToolchainError { /// The toolchain is not installed in the workspace, but the called method requires it to be /// present. Use the [`Toolchain::Install`](struct.Toolchain.html#method.install) method to /// install it inside the workspace. - #[fail(display = "the toolchain is not installed")] + #[error("the toolchain is not installed")] NotInstalled, /// Not every method can be called with every kind of toolchain. If you receive this error /// please check the documentation of the method you're calling to see which toolchains can you /// use with it. - #[fail(display = "unsupported operation on this toolchain")] + #[error("unsupported operation on this toolchain")] UnsupportedOperation, } @@ -40,7 +40,7 @@ impl DistToolchain { self.name.as_ref() } - fn init(&self, workspace: &Workspace) -> Result<(), Error> { + fn init(&self, workspace: &Workspace) -> Result<()> { info!("installing toolchain {}", self.name()); Command::new(workspace, &RUSTUP) .args(&[ @@ -51,7 +51,7 @@ impl DistToolchain { workspace.rustup_profile(), ]) .run() - .with_context(|_| format!("unable to install toolchain {} via rustup", self.name()))?; + .with_context(|| format!("unable to install toolchain {} via rustup", self.name()))?; Ok(()) } @@ -123,7 +123,7 @@ impl CiToolchain { self.alt } - fn init(&self, workspace: &Workspace) -> Result<(), Error> { + fn init(&self, workspace: &Workspace) -> Result<()> { if self.alt { info!("installing toolchain {}-alt", self.sha); } else { @@ -138,7 +138,7 @@ impl CiToolchain { Command::new(workspace, &RUSTUP_TOOLCHAIN_INSTALL_MASTER) .args(&args) .run() - .with_context(|_| { + .with_context(|| { format!( "unable to install toolchain {} via rustup-toolchain-install-master", self.sha @@ -255,7 +255,7 @@ impl Toolchain { } /// Download and install the toolchain. - pub fn install(&self, workspace: &Workspace) -> Result<(), Error> { + pub fn install(&self, workspace: &Workspace) -> Result<()> { match &self.inner { ToolchainInner::Dist(dist) => dist.init(workspace)?, #[cfg(feature = "unstable-toolchain-ci")] @@ -266,12 +266,12 @@ impl Toolchain { } /// Download and install a component for the toolchain. - pub fn add_component(&self, workspace: &Workspace, name: &str) -> Result<(), Error> { + pub fn add_component(&self, workspace: &Workspace, name: &str) -> Result<()> { self.change_rustup_thing(workspace, RustupAction::Add, RustupThing::Component, name) } /// Remove a component already installed for the toolchain. - pub fn remove_component(&self, workspace: &Workspace, name: &str) -> Result<(), Error> { + pub fn remove_component(&self, workspace: &Workspace, name: &str) -> Result<()> { self.change_rustup_thing( workspace, RustupAction::Remove, @@ -284,7 +284,7 @@ impl Toolchain { /// /// If the toolchain is not installed in the workspace an error will be returned. This is only /// supported for dist toolchains. - pub fn add_target(&self, workspace: &Workspace, name: &str) -> Result<(), Error> { + pub fn add_target(&self, workspace: &Workspace, name: &str) -> Result<()> { self.change_rustup_thing(workspace, RustupAction::Add, RustupThing::Target, name) } @@ -292,14 +292,14 @@ impl Toolchain { /// /// If the toolchain is not installed in the workspace or the target is missing an error will /// be returned. This is only supported for dist toolchains. - pub fn remove_target(&self, workspace: &Workspace, name: &str) -> Result<(), Error> { + pub fn remove_target(&self, workspace: &Workspace, name: &str) -> Result<()> { self.change_rustup_thing(workspace, RustupAction::Remove, RustupThing::Target, name) } /// Return a list of installed targets for this toolchain. /// /// If the toolchain is not installed an empty list is returned. - pub fn installed_targets(&self, workspace: &Workspace) -> Result, Error> { + pub fn installed_targets(&self, workspace: &Workspace) -> Result> { self.list_rustup_things(workspace, RustupThing::Target) } @@ -309,7 +309,7 @@ impl Toolchain { action: RustupAction, thing: RustupThing, name: &str, - ) -> Result<(), Error> { + ) -> Result<()> { let (log_action, log_action_ing) = match action { RustupAction::Add => ("add", "adding"), RustupAction::Remove => ("remove", "removing"), @@ -321,7 +321,7 @@ impl Toolchain { #[cfg(feature = "unstable-toolchain-ci")] if let ToolchainInner::CI(ci) = &self.inner { if let RustupAction::Remove = action { - failure::bail!("removing {thing} on CI toolchains is not supported yet"); + anyhow::bail!("removing {thing} on CI toolchains is not supported yet"); } let mut args = Vec::with_capacity(6); @@ -345,7 +345,7 @@ impl Toolchain { Command::new(workspace, &RUSTUP_TOOLCHAIN_INSTALL_MASTER) .args(&args) .run() - .with_context(|_| { + .with_context(|| { format!( "unable to {log_action} {thing} {name} for CI toolchain {toolchain_name} \ via rustup-toolchain-install-master" @@ -367,7 +367,7 @@ impl Toolchain { name, ]) .run() - .with_context(|_| { + .with_context(|| { format!( "unable to {log_action} {thing} {name} for toolchain {toolchain_name} via rustup" ) @@ -375,11 +375,7 @@ impl Toolchain { Ok(()) } - fn list_rustup_things( - &self, - workspace: &Workspace, - thing: RustupThing, - ) -> Result, Error> { + fn list_rustup_things(&self, workspace: &Workspace, thing: RustupThing) -> Result> { let thing = thing.to_string(); let name = if let Some(dist) = self.as_dist() { dist.name() @@ -406,22 +402,20 @@ impl Toolchain { .cloned() .collect()), Err(_) if not_installed => Err(ToolchainError::NotInstalled.into()), - Err(err) => Err(Error::from(err) - .context(format!( - "failed to read the list of installed {}s for {} with rustup", - thing, name - )) - .into()), + Err(err) => Err(anyhow!(err).context(format!( + "failed to read the list of installed {}s for {} with rustup", + thing, name + ))), } } /// Remove the toolchain from the rustwide workspace, freeing up disk space. - pub fn uninstall(&self, workspace: &Workspace) -> Result<(), Error> { + pub fn uninstall(&self, workspace: &Workspace) -> Result<()> { let name = self.rustup_name(); Command::new(workspace, &RUSTUP) .args(&["toolchain", "uninstall", &name]) .run() - .with_context(|_| format!("unable to uninstall toolchain {} via rustup", name))?; + .with_context(|| format!("unable to uninstall toolchain {} via rustup", name))?; Ok(()) } @@ -522,7 +516,7 @@ impl Runnable for RustupProxy<'_> { } } -pub(crate) fn list_installed_toolchains(rustup_home: &Path) -> Result, Error> { +pub(crate) fn list_installed_toolchains(rustup_home: &Path) -> Result> { let update_hashes = rustup_home.join("update-hashes"); let mut result = Vec::new(); @@ -531,7 +525,7 @@ pub(crate) fn list_installed_toolchains(rustup_home: &Path) -> Result Result Result<(), Error> { + fn test_dist_serde_repr() -> Result<()> { const DIST: &str = r#"{"type": "dist", "name": "stable"}"#; assert_eq!(Toolchain::dist("stable"), serde_json::from_str(DIST)?); @@ -568,7 +562,7 @@ mod tests { #[test] #[cfg(feature = "unstable-toolchain-ci")] - fn test_ci_serde_repr() -> Result<(), Error> { + fn test_ci_serde_repr() -> Result<()> { const CI_NORMAL: &str = r#"{"type": "ci", "sha": "0000000", "alt": false}"#; const CI_ALT: &str = r#"{"type": "ci", "sha": "0000000", "alt": true}"#; @@ -585,7 +579,7 @@ mod tests { } #[test] - fn test_list_installed() -> Result<(), Error> { + fn test_list_installed() -> Result<()> { const DIST_NAME: &str = "stable-x86_64-unknown-linux-gnu"; const LINK_NAME: &str = "stage1"; const CI_SHA: &str = "0000000000000000000000000000000000000000"; diff --git a/src/tools/binary_crates.rs b/src/tools/binary_crates.rs index c7a39c4..3a186b6 100644 --- a/src/tools/binary_crates.rs +++ b/src/tools/binary_crates.rs @@ -1,7 +1,7 @@ use crate::cmd::{Binary, Command, Runnable}; use crate::tools::Tool; use crate::{Toolchain, Workspace}; -use failure::Error; +use anyhow::Result; use std::path::PathBuf; pub(crate) struct BinaryCrate { @@ -38,7 +38,7 @@ impl Tool for BinaryCrate { self.binary } - fn is_installed(&self, workspace: &Workspace) -> Result { + fn is_installed(&self, workspace: &Workspace) -> Result { let path = self.binary_path(workspace); if !path.is_file() { return Ok(false); @@ -47,7 +47,7 @@ impl Tool for BinaryCrate { crate::native::is_executable(path) } - fn install(&self, workspace: &Workspace, fast_install: bool) -> Result<(), Error> { + fn install(&self, workspace: &Workspace, fast_install: bool) -> Result<()> { let mut cmd = Command::new(workspace, &Toolchain::MAIN.cargo()) .args(&["install", self.crate_name]) .timeout(None); @@ -58,7 +58,7 @@ impl Tool for BinaryCrate { Ok(()) } - fn update(&self, workspace: &Workspace, fast_install: bool) -> Result<(), Error> { + fn update(&self, workspace: &Workspace, fast_install: bool) -> Result<()> { self.install(workspace, fast_install) } } diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 148f4cf..9d159bf 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -2,8 +2,8 @@ mod binary_crates; mod rustup; use crate::workspace::Workspace; +use anyhow::{bail, Result}; use binary_crates::BinaryCrate; -use failure::{bail, Error}; use log::info; use rustup::Rustup; use std::env::consts::EXE_SUFFIX; @@ -33,9 +33,9 @@ static INSTALLABLE_TOOLS: &[&dyn Tool] = &[ trait Tool: Send + Sync { fn name(&self) -> &'static str; - fn is_installed(&self, workspace: &Workspace) -> Result; - fn install(&self, workspace: &Workspace, fast_install: bool) -> Result<(), Error>; - fn update(&self, workspace: &Workspace, fast_install: bool) -> Result<(), Error>; + fn is_installed(&self, workspace: &Workspace) -> Result; + fn install(&self, workspace: &Workspace, fast_install: bool) -> Result<()>; + fn update(&self, workspace: &Workspace, fast_install: bool) -> Result<()>; fn binary_path(&self, workspace: &Workspace) -> PathBuf { crate::utils::normalize_path(&workspace.cargo_home().join("bin").join(format!( @@ -46,7 +46,7 @@ trait Tool: Send + Sync { } } -pub(crate) fn install(workspace: &Workspace, fast_install: bool) -> Result<(), Error> { +pub(crate) fn install(workspace: &Workspace, fast_install: bool) -> Result<()> { for tool in INSTALLABLE_TOOLS { if tool.is_installed(workspace)? { info!("tool {} is installed, trying to update it", tool.name()); diff --git a/src/tools/rustup.rs b/src/tools/rustup.rs index b46495b..57386b8 100644 --- a/src/tools/rustup.rs +++ b/src/tools/rustup.rs @@ -2,7 +2,7 @@ use crate::cmd::{Binary, Command, Runnable}; use crate::toolchain::MAIN_TOOLCHAIN_NAME; use crate::tools::{Tool, RUSTUP}; use crate::workspace::Workspace; -use failure::{Error, ResultExt}; +use anyhow::{Context as _, Result}; use std::env::consts::EXE_SUFFIX; use std::fs::{self, File}; use std::io; @@ -23,7 +23,7 @@ impl Tool for Rustup { "rustup" } - fn is_installed(&self, workspace: &Workspace) -> Result { + fn is_installed(&self, workspace: &Workspace) -> Result { let path = self.binary_path(workspace); if !path.is_file() { return Ok(false); @@ -32,7 +32,7 @@ impl Tool for Rustup { crate::native::is_executable(path) } - fn install(&self, workspace: &Workspace, _fast_install: bool) -> Result<(), Error> { + fn install(&self, workspace: &Workspace, _fast_install: bool) -> Result<()> { fs::create_dir_all(workspace.cargo_home())?; fs::create_dir_all(workspace.rustup_home())?; @@ -68,20 +68,20 @@ impl Tool for Rustup { .env("RUSTUP_HOME", workspace.rustup_home()) .env("CARGO_HOME", workspace.cargo_home()) .run() - .with_context(|_| "unable to install rustup")?; + .context("unable to install rustup")?; Ok(()) } - fn update(&self, workspace: &Workspace, _fast_install: bool) -> Result<(), Error> { + fn update(&self, workspace: &Workspace, _fast_install: bool) -> Result<()> { Command::new(workspace, &RUSTUP) .args(&["self", "update"]) .run() - .with_context(|_| "failed to update rustup")?; + .context("failed to update rustup")?; Command::new(workspace, &RUSTUP) .args(&["update", MAIN_TOOLCHAIN_NAME]) .run() - .with_context(|_| format!("failed to update main toolchain {}", MAIN_TOOLCHAIN_NAME))?; + .with_context(|| format!("failed to update main toolchain {}", MAIN_TOOLCHAIN_NAME))?; Ok(()) } } diff --git a/src/utils.rs b/src/utils.rs index 62a260f..bdaf5f8 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::Result; use fs2::FileExt; use log::warn; use percent_encoding::{AsciiSet, CONTROLS}; @@ -24,8 +24,8 @@ pub(crate) fn escape_path(unescaped: &[u8]) -> String { pub(crate) fn file_lock( path: &Path, msg: &str, - f: impl FnOnce() -> Result + std::panic::UnwindSafe, -) -> Result { + f: impl FnOnce() -> Result + std::panic::UnwindSafe, +) -> Result { let file = OpenOptions::new() .read(true) .write(true) diff --git a/src/workspace.rs b/src/workspace.rs index 59c5ed1..80e74ec 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -2,7 +2,7 @@ use crate::build::BuildDirectory; use crate::cmd::{Command, SandboxImage}; use crate::inside_docker::CurrentContainer; use crate::Toolchain; -use failure::{Error, ResultExt}; +use anyhow::{Context as _, Result}; use log::info; use std::path::{Path, PathBuf}; use std::sync::Arc; @@ -134,8 +134,8 @@ impl WorkspaceBuilder { /// Initialize the workspace. This will create all the necessary local files and fetch the rest from the network. It's /// not unexpected for this method to take minutes to run on slower network connections. - pub fn init(self) -> Result { - std::fs::create_dir_all(&self.path).with_context(|_| { + pub fn init(self) -> Result { + std::fs::create_dir_all(&self.path).with_context(|| { format!( "failed to create workspace directory: {}", self.path.display() @@ -206,7 +206,7 @@ impl Workspace { } /// Remove all the contents of all the build directories, freeing disk space. - pub fn purge_all_build_dirs(&self) -> Result<(), Error> { + pub fn purge_all_build_dirs(&self) -> Result<()> { let dir = self.builds_dir(); if dir.exists() { crate::utils::remove_dir_all(&dir)?; @@ -215,7 +215,7 @@ impl Workspace { } /// Remove all the contents of the caches in the workspace, freeing disk space. - pub fn purge_all_caches(&self) -> Result<(), Error> { + pub fn purge_all_caches(&self) -> Result<()> { let mut paths = vec![ self.cache_dir(), self.cargo_home().join("git"), @@ -259,7 +259,7 @@ impl Workspace { /// # Ok(()) /// # } /// ``` - pub fn installed_toolchains(&self) -> Result, Error> { + pub fn installed_toolchains(&self) -> Result> { crate::toolchain::list_installed_toolchains(&self.rustup_home()) } @@ -307,7 +307,7 @@ impl Workspace { &self.inner.rustup_profile } - fn init(&self, fast_init: bool) -> Result<(), Error> { + fn init(&self, fast_init: bool) -> Result<()> { info!("installing tools required by rustwide"); crate::tools::install(self, fast_init)?; if !self.fetch_registry_index_during_builds() { @@ -318,7 +318,7 @@ impl Workspace { } #[allow(clippy::unnecessary_wraps)] // hopefully we could actually catch the error here at some point - fn update_cratesio_registry(&self) -> Result<(), Error> { + fn update_cratesio_registry(&self) -> Result<()> { // This nop cargo command is to update the registry so we don't have to do it for each // crate. using `install` is a temporary solution until // https://github.com/rust-lang/cargo/pull/5961 is ready diff --git a/tests/buildtest/inside_docker.rs b/tests/buildtest/inside_docker.rs index df41265..2d79b54 100644 --- a/tests/buildtest/inside_docker.rs +++ b/tests/buildtest/inside_docker.rs @@ -1,6 +1,6 @@ #![cfg_attr(windows, allow(unused))] -use failure::{Error, ResultExt}; +use anyhow::{Context, Result}; use std::io::Write; use std::path::Path; use std::process::Command; @@ -22,7 +22,7 @@ fn test_path_based_patch() { execute("buildtest::path_based_patch").unwrap(); } -fn execute(test: &str) -> Result<(), Error> { +fn execute(test: &str) -> Result<()> { // The current working directory is mounted in the container to /outside. // The binary to execute is remapped to be prefixed by /outside instead of the current // directory. @@ -37,7 +37,7 @@ fn execute(test: &str) -> Result<(), Error> { let container_exe = target_prefix.join( current_exe .strip_prefix(target_parent_dir) - .with_context(|_| "could not determine cargo target dir")?, + .context("could not determine cargo target dir")?, ); let src_mount = os_string!(¤t_dir, ":", &container_prefix); let target_mount = os_string!(&target_parent_dir, ":", &target_prefix); @@ -69,13 +69,13 @@ fn execute(test: &str) -> Result<(), Error> { } trait CommandExt { - fn map_user_group(&mut self) -> Result<&mut Self, Error>; - fn assert(&mut self) -> Result<(), Error>; + fn map_user_group(&mut self) -> Result<&mut Self>; + fn assert(&mut self) -> Result<()>; } impl CommandExt for Command { #[cfg(unix)] - fn map_user_group(&mut self) -> Result<&mut Self, Error> { + fn map_user_group(&mut self) -> Result<&mut Self> { use std::os::unix::fs::MetadataExt; let gid = std::fs::metadata(DOCKER_SOCKET)?.gid(); let uid = nix::unistd::Uid::effective(); @@ -85,11 +85,11 @@ impl CommandExt for Command { } #[cfg(windows)] - fn map_user_group(&mut self) -> Result<&mut Self, Error> { + fn map_user_group(&mut self) -> Result<&mut Self> { Ok(self) } - fn assert(&mut self) -> Result<(), Error> { + fn assert(&mut self) -> Result<()> { let out = self.output()?; if !out.status.success() { eprintln!("failed to execute command {:?}", self); @@ -97,7 +97,7 @@ impl CommandExt for Command { std::io::stderr().lock().write_all(&out.stdout)?; eprintln!("stderr:"); std::io::stderr().lock().write_all(&out.stderr)?; - failure::bail!("failed to execute command {:?}", self); + anyhow::bail!("failed to execute command {:?}", self); } Ok(()) } diff --git a/tests/buildtest/mod.rs b/tests/buildtest/mod.rs index b99b1cb..ffbb2c3 100644 --- a/tests/buildtest/mod.rs +++ b/tests/buildtest/mod.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::Result; use log::LevelFilter; use rustwide::cmd::{ProcessLinesActions, SandboxBuilder}; @@ -11,7 +11,7 @@ fn test_hello_world() { runner::run("hello-world", |run| { run.run(SandboxBuilder::new().enable_networking(false), |build| { let storage = rustwide::logging::LogStorage::new(LevelFilter::Info); - rustwide::logging::capture(&storage, || -> Result<_, Error> { + rustwide::logging::capture(&storage, || -> Result<_> { build.cargo().args(&["run"]).run()?; Ok(()) })?; @@ -36,9 +36,9 @@ fn test_fetch_build_std() { runner::run("hello-world", |run| { run.run(SandboxBuilder::new().enable_networking(false), |build| { - build.fetch_build_std_dependencies(&vec![target.as_str()])?; + build.fetch_build_std_dependencies(&[target.as_str()])?; let storage = rustwide::logging::LogStorage::new(LevelFilter::Info); - rustwide::logging::capture(&storage, || -> Result<_, Error> { + rustwide::logging::capture(&storage, || -> Result<_> { build .cargo() .env("RUSTC_BOOTSTRAP", "1") @@ -65,7 +65,7 @@ fn path_based_patch() { .patch_with_path("empty-library", "./patch") .run(move |build| { let storage = rustwide::logging::LogStorage::new(LevelFilter::Info); - rustwide::logging::capture(&storage, || -> Result<_, Error> { + rustwide::logging::capture(&storage, || -> Result<_> { build.cargo().args(&["run"]).run()?; Ok(()) })?; @@ -87,7 +87,7 @@ fn test_process_lines() { run.run(SandboxBuilder::new().enable_networking(false), |build| { let storage = rustwide::logging::LogStorage::new(LevelFilter::Info); let mut ex = false; - rustwide::logging::capture(&storage, || -> Result<_, Error> { + rustwide::logging::capture(&storage, || -> Result<_> { build .cargo() .process_lines(&mut |line: &str, actions: &mut ProcessLinesActions| { @@ -142,7 +142,7 @@ fn test_override_files() { runner::run("cargo-config", |run| { run.run(SandboxBuilder::new().enable_networking(false), |build| { let storage = rustwide::logging::LogStorage::new(LevelFilter::Info); - rustwide::logging::capture(&storage, || -> Result<_, Error> { + rustwide::logging::capture(&storage, || -> Result<_> { build.cargo().args(&["--version"]).run()?; Ok(()) })?; @@ -161,7 +161,7 @@ fn test_cargo_workspace() { runner::run("cargo-workspace", |run| { run.run(SandboxBuilder::new().enable_networking(false), |build| { let storage = rustwide::logging::LogStorage::new(LevelFilter::Info); - rustwide::logging::capture(&storage, || -> Result<_, Error> { + rustwide::logging::capture(&storage, || -> Result<_> { build.cargo().args(&["run"]).run()?; Ok(()) })?; diff --git a/tests/buildtest/runner.rs b/tests/buildtest/runner.rs index eac5a1e..45d205b 100644 --- a/tests/buildtest/runner.rs +++ b/tests/buildtest/runner.rs @@ -1,9 +1,9 @@ -use failure::Error; +use anyhow::Result; use rand::{distributions::Alphanumeric, Rng}; use rustwide::{cmd::SandboxBuilder, Build, BuildBuilder, Crate, Toolchain, Workspace}; use std::path::Path; -pub(crate) fn run(crate_name: &str, f: impl FnOnce(&mut Runner) -> Result<(), Error>) { +pub(crate) fn run(crate_name: &str, f: impl FnOnce(&mut Runner) -> Result<()>) { let mut runner = Runner::new(crate_name).unwrap(); f(&mut runner).unwrap(); } @@ -16,7 +16,7 @@ pub(crate) struct Runner { } impl Runner { - fn new(crate_name: &str) -> Result { + fn new(crate_name: &str) -> Result { let workspace = crate::utils::init_workspace()?; let krate = Crate::local( &Path::new("tests") @@ -39,8 +39,8 @@ impl Runner { pub(crate) fn build( &self, sandbox: SandboxBuilder, - f: impl FnOnce(BuildBuilder) -> Result, - ) -> Result { + f: impl FnOnce(BuildBuilder) -> Result, + ) -> Result { // Use a random string at the end to avoid conflicts if multiple tests use the same source crate. let suffix: String = rand::thread_rng() .sample_iter(&Alphanumeric) @@ -58,8 +58,8 @@ impl Runner { pub(crate) fn run( &self, sandbox: SandboxBuilder, - f: impl FnOnce(&Build) -> Result, - ) -> Result { + f: impl FnOnce(&Build) -> Result, + ) -> Result { self.build(sandbox, |builder| builder.run(f)) } } diff --git a/tests/integration/crates_alt.rs b/tests/integration/crates_alt.rs index 44d7955..c0535ec 100644 --- a/tests/integration/crates_alt.rs +++ b/tests/integration/crates_alt.rs @@ -1,10 +1,10 @@ -use failure::Error; +use anyhow::Result; use rustwide::{AlternativeRegistry, Crate}; const INDEX_URL: &str = "https://github.com/rust-lang/staging.crates.io-index"; #[test] -fn test_fetch() -> Result<(), Error> { +fn test_fetch() -> Result<()> { let workspace = crate::utils::init_workspace()?; let alt = AlternativeRegistry::new(INDEX_URL); diff --git a/tests/integration/crates_git.rs b/tests/integration/crates_git.rs index 7ec04bc..11b4669 100644 --- a/tests/integration/crates_git.rs +++ b/tests/integration/crates_git.rs @@ -1,9 +1,9 @@ -use failure::Error; +use anyhow::{anyhow, Result}; use rustwide::cmd::{Command, CommandError, SandboxBuilder}; use rustwide::{Crate, PrepareError, Toolchain, Workspace}; #[test] -fn test_fetch() -> Result<(), Error> { +fn test_fetch() -> Result<()> { let workspace = crate::utils::init_workspace()?; let toolchain = Toolchain::dist("stable"); toolchain.install(&workspace)?; @@ -13,7 +13,7 @@ fn test_fetch() -> Result<(), Error> { krate.fetch(&workspace)?; // Return the commit that was used during a build. - let cloned_commit = || -> Result { + let cloned_commit = || -> Result { let mut dir = workspace.build_dir("integration-crates_git-test_fetch"); dir.purge()?; dir.build(&toolchain, &krate, SandboxBuilder::new()) @@ -48,7 +48,7 @@ fn test_fetch() -> Result<(), Error> { } #[test] -fn test_fetch_with_authentication() -> Result<(), Error> { +fn test_fetch_with_authentication() -> Result<()> { let workspace = crate::utils::init_workspace()?; let repo = Repo::new(&workspace)?.authenticated(); @@ -73,7 +73,7 @@ struct Repo { } impl Repo { - fn new(workspace: &Workspace) -> Result { + fn new(workspace: &Workspace) -> Result { let source = tempfile::tempdir()?; // Initialize a cargo project with a git repo in it. @@ -96,7 +96,7 @@ impl Repo { self } - fn commit(&mut self, workspace: &Workspace) -> Result<(), Error> { + fn commit(&mut self, workspace: &Workspace) -> Result<()> { Command::new(workspace, "git") .args(&["add", "."]) .cd(self.source.path()) @@ -125,9 +125,8 @@ impl Repo { Ok(()) } - fn serve(&self) -> Result { - let server = - tiny_http::Server::http("localhost:0").map_err(|e| failure::err_msg(e.to_string()))?; + fn serve(&self) -> Result { + let server = tiny_http::Server::http("localhost:0").map_err(|e| anyhow!(e.to_string()))?; let port = server.server_addr().port(); let base = self.source.path().join(".git"); diff --git a/tests/integration/purge_caches.rs b/tests/integration/purge_caches.rs index 3b032ea..48065de 100644 --- a/tests/integration/purge_caches.rs +++ b/tests/integration/purge_caches.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::Result; use rustwide::cmd::SandboxBuilder; use rustwide::{Crate, Toolchain}; use std::collections::HashMap; @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf}; const WORKSPACE_NAME: &str = "purge-caches"; #[test] -fn test_purge_caches() -> Result<(), Error> { +fn test_purge_caches() -> Result<()> { let workspace_path = crate::utils::workspace_path(WORKSPACE_NAME); let workspace = crate::utils::init_named_workspace(WORKSPACE_NAME)?; @@ -76,7 +76,7 @@ struct WorkspaceContents { } impl WorkspaceContents { - fn collect(path: &Path) -> Result { + fn collect(path: &Path) -> Result { let mut files = HashMap::new(); for entry in walkdir::WalkDir::new(path) diff --git a/tests/issue_30.rs b/tests/issue_30.rs index a2f7de3..26da2fb 100644 --- a/tests/issue_30.rs +++ b/tests/issue_30.rs @@ -1,11 +1,11 @@ -use failure::Error; +use anyhow::Result; use rustwide::cmd::Command; use std::fs; mod utils; #[test] -fn run_binary_with_same_name_as_file() -> Result<(), Error> { +fn run_binary_with_same_name_as_file() -> Result<()> { let workspace = crate::utils::init_workspace()?; let tmpdir = tempfile::tempdir()?; diff --git a/tests/utils/mod.rs b/tests/utils/mod.rs index 8ff0c8d..453e45b 100644 --- a/tests/utils/mod.rs +++ b/tests/utils/mod.rs @@ -1,4 +1,4 @@ -use failure::Error; +use anyhow::Result; use log::LevelFilter; use rustwide::{cmd::SandboxImage, Workspace, WorkspaceBuilder}; use std::path::{Path, PathBuf}; @@ -9,11 +9,11 @@ pub(crate) fn workspace_path(name: &str) -> PathBuf { Path::new(".workspaces").join(name) } -pub(crate) fn init_workspace() -> Result { +pub(crate) fn init_workspace() -> Result { init_named_workspace("integration") } -pub(crate) fn init_named_workspace(name: &str) -> Result { +pub(crate) fn init_named_workspace(name: &str) -> Result { init_logs(); let workspace_path = workspace_path(name); let mut builder = WorkspaceBuilder::new(&workspace_path, USER_AGENT).fast_init(true);