From 2cbb7db66d3cb2263ad38c0d3c9b4ae579e0beda Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Fri, 11 Nov 2022 09:39:29 -0500 Subject: [PATCH] Use `color_eyre` (#173) --- Cargo.lock | 148 ++++++++++++++++++++++++++++++++++-- Cargo.toml | 2 +- src/command.rs | 37 ++++----- src/config.rs | 7 +- src/execution_context.rs | 2 +- src/executor.rs | 9 ++- src/main.rs | 9 ++- src/runner.rs | 2 +- src/self_renamer.rs | 2 +- src/self_update.rs | 2 +- src/steps/containers.rs | 6 +- src/steps/emacs.rs | 2 +- src/steps/generic.rs | 6 +- src/steps/git.rs | 4 +- src/steps/kakoune.rs | 2 +- src/steps/node.rs | 2 +- src/steps/os/android.rs | 2 +- src/steps/os/archlinux.rs | 5 +- src/steps/os/dragonfly.rs | 2 +- src/steps/os/freebsd.rs | 2 +- src/steps/os/linux.rs | 2 +- src/steps/os/macos.rs | 2 +- src/steps/os/openbsd.rs | 2 +- src/steps/os/unix.rs | 2 +- src/steps/os/windows.rs | 2 +- src/steps/powershell.rs | 2 +- src/steps/remote/ssh.rs | 2 +- src/steps/remote/vagrant.rs | 2 +- src/steps/tmux.rs | 2 +- src/steps/toolbx.rs | 2 +- src/steps/vim.rs | 2 +- src/steps/zsh.rs | 2 +- src/terminal.rs | 9 ++- src/utils.rs | 2 +- 34 files changed, 216 insertions(+), 72 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0aa46ae7..9da92b40 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" @@ -37,12 +46,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anyhow" -version = "1.0.66" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" - [[package]] name = "async-broadcast" version = "0.4.1" @@ -154,6 +157,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.1" @@ -272,6 +290,33 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "color-eyre" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" +dependencies = [ + "backtrace", + "color-spantrace", + "eyre", + "indenter", + "once_cell", + "owo-colors", + "tracing-error", +] + +[[package]] +name = "color-spantrace" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" +dependencies = [ + "once_cell", + "owo-colors", + "tracing-core", + "tracing-error", +] + [[package]] name = "concurrent-queue" version = "1.2.4" @@ -491,6 +536,16 @@ version = "2.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" +[[package]] +name = "eyre" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" +dependencies = [ + "indenter", + "once_cell", +] + [[package]] name = "fastrand" version = "1.8.0" @@ -652,6 +707,12 @@ dependencies = [ "wasi 0.11.0+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" + [[package]] name = "glob" version = "0.3.0" @@ -839,6 +900,12 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "indenter" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683" + [[package]] name = "indexmap" version = "1.9.1" @@ -1126,6 +1193,15 @@ dependencies = [ "objc", ] +[[package]] +name = "object" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.16.0" @@ -1158,6 +1234,12 @@ version = "6.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3baf96e39c5359d2eb0dd6ccb42c62b91d9678aa68160d261b9e0ccbf9e9dea9" +[[package]] +name = "owo-colors" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" + [[package]] name = "parking" version = "2.0.0" @@ -1465,6 +1547,12 @@ dependencies = [ "ordered-multimap", ] +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + [[package]] name = "rustls" version = "0.20.7" @@ -1625,6 +1713,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" +[[package]] +name = "sharded-slab" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" +dependencies = [ + "lazy_static", +] + [[package]] name = "shell-words" version = "1.1.0" @@ -1837,6 +1934,15 @@ dependencies = [ "syn", ] +[[package]] +name = "thread_local" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" +dependencies = [ + "once_cell", +] + [[package]] name = "time" version = "0.1.44" @@ -1948,10 +2054,10 @@ dependencies = [ name = "topgrade" version = "10.1.2" dependencies = [ - "anyhow", "cfg-if", "chrono", "clap", + "color-eyre", "console", "directories", "futures", @@ -2017,6 +2123,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", + "valuable", +] + +[[package]] +name = "tracing-error" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" +dependencies = [ + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6176eae26dd70d0c919749377897b54a9276bd7061339665dd68777926b5a70" +dependencies = [ + "sharded-slab", + "thread_local", + "tracing-core", ] [[package]] @@ -2085,6 +2213,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 63c321ce..3a1d861e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,6 @@ pretty_env_logger = "~0.4" glob = "~0.3" strum = { version = "~0.24", features = ["derive"] } thiserror = "~1.0" -anyhow = "~1.0" tempfile = "~3.2" cfg-if = "~1.0" tokio = { version = "~1.5", features = ["process", "rt-multi-thread"] } @@ -45,6 +44,7 @@ regex = "~1.5" sys-info = "~0.9" semver = "~1.0" shell-words = "~1.1" +color-eyre = "0.6.2" [target.'cfg(target_os = "macos")'.dependencies] notify-rust = "~4.5" diff --git a/src/command.rs b/src/command.rs index 016c8003..51ef1a76 100644 --- a/src/command.rs +++ b/src/command.rs @@ -4,8 +4,9 @@ use std::fmt::Display; use std::process::Child; use std::process::{Command, ExitStatus, Output}; -use anyhow::anyhow; -use anyhow::Context; +use color_eyre::eyre; +use color_eyre::eyre::eyre; +use color_eyre::eyre::Context; use crate::error::TopgradeError; @@ -18,17 +19,17 @@ pub struct Utf8Output { } impl TryFrom for Utf8Output { - type Error = anyhow::Error; + type Error = eyre::Error; fn try_from(Output { status, stdout, stderr }: Output) -> Result { let stdout = String::from_utf8(stdout).map_err(|err| { - anyhow!( + eyre!( "Stdout contained invalid UTF-8: {}", String::from_utf8_lossy(err.as_bytes()) ) })?; let stderr = String::from_utf8(stderr).map_err(|err| { - anyhow!( + eyre!( "Stderr contained invalid UTF-8: {}", String::from_utf8_lossy(err.as_bytes()) ) @@ -39,17 +40,17 @@ impl TryFrom for Utf8Output { } impl TryFrom<&Output> for Utf8Output { - type Error = anyhow::Error; + type Error = eyre::Error; fn try_from(Output { status, stdout, stderr }: &Output) -> Result { let stdout = String::from_utf8(stdout.to_vec()).map_err(|err| { - anyhow!( + eyre!( "Stdout contained invalid UTF-8: {}", String::from_utf8_lossy(err.as_bytes()) ) })?; let stderr = String::from_utf8(stderr.to_vec()).map_err(|err| { - anyhow!( + eyre!( "Stderr contained invalid UTF-8: {}", String::from_utf8_lossy(err.as_bytes()) ) @@ -85,7 +86,7 @@ pub trait CommandExt { /// /// Returns an `Err` if the command failed to execute or returned a non-zero exit code. #[track_caller] - fn output_checked(&mut self) -> anyhow::Result { + fn output_checked(&mut self) -> eyre::Result { self.output_checked_with(|output: &Output| if output.status.success() { Ok(()) } else { Err(()) }) } @@ -94,7 +95,7 @@ pub trait CommandExt { /// Returns an `Err` if the command failed to execute, returned a non-zero exit code, or if the /// output contains invalid UTF-8. #[track_caller] - fn output_checked_utf8(&mut self) -> anyhow::Result { + fn output_checked_utf8(&mut self) -> eyre::Result { let output = self.output_checked()?; output.try_into() } @@ -106,7 +107,7 @@ pub trait CommandExt { /// (This lets the caller substitute their own notion of "success" instead of assuming /// non-zero exit codes indicate success.) #[track_caller] - fn output_checked_with(&mut self, succeeded: impl Fn(&Output) -> Result<(), ()>) -> anyhow::Result; + fn output_checked_with(&mut self, succeeded: impl Fn(&Output) -> Result<(), ()>) -> eyre::Result; /// Like [`output_checked_with`], but also decodes Stdout and Stderr as UTF-8. /// @@ -116,7 +117,7 @@ pub trait CommandExt { fn output_checked_with_utf8( &mut self, succeeded: impl Fn(&Utf8Output) -> Result<(), ()>, - ) -> anyhow::Result { + ) -> eyre::Result { // This decodes the Stdout and Stderr as UTF-8 twice... let output = self.output_checked_with(|output| output.try_into().map_err(|_| ()).and_then(|o| succeeded(&o)))?; @@ -129,7 +130,7 @@ pub trait CommandExt { /// Returns `Ok` if the command executes successfully, returns `Err` if the command fails to /// execute or returns a non-zero exit code. #[track_caller] - fn status_checked(&mut self) -> anyhow::Result<()> { + fn status_checked(&mut self) -> eyre::Result<()> { self.status_checked_with(|status| if status.success() { Ok(()) } else { Err(()) }) } @@ -141,18 +142,18 @@ pub trait CommandExt { /// (This lets the caller substitute their own notion of "success" instead of assuming /// non-zero exit codes indicate success.) #[track_caller] - fn status_checked_with(&mut self, succeeded: impl Fn(ExitStatus) -> Result<(), ()>) -> anyhow::Result<()>; + fn status_checked_with(&mut self, succeeded: impl Fn(ExitStatus) -> Result<(), ()>) -> eyre::Result<()>; /// Like [`Command::spawn`], but gives a nice error message if the command fails to /// execute. #[track_caller] - fn spawn_checked(&mut self) -> anyhow::Result; + fn spawn_checked(&mut self) -> eyre::Result; } impl CommandExt for Command { type Child = Child; - fn output_checked_with(&mut self, succeeded: impl Fn(&Output) -> Result<(), ()>) -> anyhow::Result { + fn output_checked_with(&mut self, succeeded: impl Fn(&Output) -> Result<(), ()>) -> eyre::Result { let command = log(self); // This is where we implement `output_checked`, which is what we prefer to use instead of @@ -187,7 +188,7 @@ impl CommandExt for Command { } } - fn status_checked_with(&mut self, succeeded: impl Fn(ExitStatus) -> Result<(), ()>) -> anyhow::Result<()> { + fn status_checked_with(&mut self, succeeded: impl Fn(ExitStatus) -> Result<(), ()>) -> eyre::Result<()> { let command = log(self); let message = format!("Failed to execute `{command}`"); @@ -207,7 +208,7 @@ impl CommandExt for Command { } } - fn spawn_checked(&mut self) -> anyhow::Result { + fn spawn_checked(&mut self) -> eyre::Result { let command = log(self); let message = format!("Failed to execute `{command}`"); diff --git a/src/config.rs b/src/config.rs index 5db208c5..f636a769 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,9 +5,10 @@ use std::path::PathBuf; use std::process::Command; use std::{env, fs}; -use anyhow::Context; -use anyhow::Result; use clap::{ArgEnum, Parser}; +use color_eyre::eyre; +use color_eyre::eyre::Context; +use color_eyre::eyre::Result; use directories::BaseDirs; use log::debug; use regex::Regex; @@ -635,7 +636,7 @@ impl Config { } /// Extra Tmux arguments - pub fn tmux_arguments(&self) -> anyhow::Result> { + pub fn tmux_arguments(&self) -> eyre::Result> { let args = &self.config_file.tmux_arguments.as_deref().unwrap_or_default(); shell_words::split(args) // The only time the parse failed is in case of a missing close quote. diff --git a/src/execution_context.rs b/src/execution_context.rs index 6fe89e7a..af6315e4 100644 --- a/src/execution_context.rs +++ b/src/execution_context.rs @@ -3,7 +3,7 @@ use crate::executor::RunType; use crate::git::Git; use crate::utils::require_option; use crate::{config::Config, executor::Executor}; -use anyhow::Result; +use color_eyre::eyre::Result; use directories::BaseDirs; use std::path::{Path, PathBuf}; diff --git a/src/executor.rs b/src/executor.rs index 7116c288..a68dd244 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -3,7 +3,8 @@ use std::ffi::{OsStr, OsString}; use std::path::Path; use std::process::{Child, Command, ExitStatus, Output}; -use anyhow::Result; +use color_eyre::eyre; +use color_eyre::eyre::Result; use log::debug; use crate::command::CommandExt; @@ -240,7 +241,7 @@ impl CommandExt for Executor { // TODO: It might be nice to make `output_checked_with` return something that has a // variant for wet/dry runs. - fn output_checked_with(&mut self, succeeded: impl Fn(&Output) -> Result<(), ()>) -> anyhow::Result { + fn output_checked_with(&mut self, succeeded: impl Fn(&Output) -> Result<(), ()>) -> eyre::Result { match self { Executor::Wet(c) => c.output_checked_with(succeeded), Executor::Dry(c) => { @@ -250,7 +251,7 @@ impl CommandExt for Executor { } } - fn status_checked_with(&mut self, succeeded: impl Fn(ExitStatus) -> Result<(), ()>) -> anyhow::Result<()> { + fn status_checked_with(&mut self, succeeded: impl Fn(ExitStatus) -> Result<(), ()>) -> eyre::Result<()> { match self { Executor::Wet(c) => c.status_checked_with(succeeded), Executor::Dry(c) => { @@ -260,7 +261,7 @@ impl CommandExt for Executor { } } - fn spawn_checked(&mut self) -> anyhow::Result { + fn spawn_checked(&mut self) -> eyre::Result { self.spawn() } } diff --git a/src/main.rs b/src/main.rs index d87114cb..78425c12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,9 +4,9 @@ use std::env; use std::io; use std::process::exit; -use anyhow::Context; -use anyhow::{anyhow, Result}; use clap::{crate_version, Parser}; +use color_eyre::eyre::Context; +use color_eyre::eyre::{eyre, Result}; use console::Key; use log::debug; use log::LevelFilter; @@ -36,9 +36,10 @@ mod terminal; mod utils; fn run() -> Result<()> { + color_eyre::install()?; ctrlc::set_handler(); - let base_dirs = directories::BaseDirs::new().ok_or_else(|| anyhow!("No base directories"))?; + let base_dirs = directories::BaseDirs::new().ok_or_else(|| eyre!("No base directories"))?; let opt = CommandLineArgs::parse(); @@ -526,7 +527,7 @@ fn main() { .is_some()); if !skip_print { - // The `Debug` implementation of `anyhow::Result` prints a multi-line + // The `Debug` implementation of `eyre::Result` prints a multi-line // error message that includes all the 'causes' added with // `.with_context(...)` calls. println!("Error: {:?}", error); diff --git a/src/runner.rs b/src/runner.rs index 2636a88a..2c29f17e 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -3,7 +3,7 @@ use crate::error::{DryRun, SkipStep}; use crate::execution_context::ExecutionContext; use crate::report::{Report, StepResult}; use crate::{config::Step, terminal::should_retry}; -use anyhow::Result; +use color_eyre::eyre::Result; use log::debug; use std::borrow::Cow; use std::fmt::Debug; diff --git a/src/self_renamer.rs b/src/self_renamer.rs index 16186bac..6cc7a40e 100644 --- a/src/self_renamer.rs +++ b/src/self_renamer.rs @@ -1,6 +1,6 @@ #![cfg(windows)] -use anyhow::Result; +use color_eyre::eyre::Result; use log::{debug, error}; use std::{env::current_exe, fs, path::PathBuf}; diff --git a/src/self_update.rs b/src/self_update.rs index 1bbf9ef5..95274e99 100644 --- a/src/self_update.rs +++ b/src/self_update.rs @@ -3,7 +3,7 @@ use std::env; use std::os::unix::process::CommandExt as _; use std::process::Command; -use anyhow::{bail, Result}; +use color_eyre::eyre::{bail, Result}; use self_update_crate::backends::github::Update; use self_update_crate::update::UpdateStatus; diff --git a/src/steps/containers.rs b/src/steps/containers.rs index 5712a613..15a25419 100644 --- a/src/steps/containers.rs +++ b/src/steps/containers.rs @@ -1,4 +1,6 @@ -use anyhow::{Context, Result}; +use color_eyre::eyre::eyre; +use color_eyre::eyre::Context; +use color_eyre::eyre::Result; use crate::command::CommandExt; use crate::error::{self, TopgradeError}; @@ -108,6 +110,6 @@ pub fn run_containers(ctx: &ExecutionContext) -> Result<()> { if success { Ok(()) } else { - Err(anyhow::anyhow!(error::StepFailed)) + Err(eyre!(error::StepFailed)) } } diff --git a/src/steps/emacs.rs b/src/steps/emacs.rs index b6a4faa9..89e04885 100644 --- a/src/steps/emacs.rs +++ b/src/steps/emacs.rs @@ -2,7 +2,7 @@ use std::env; use std::path::{Path, PathBuf}; -use anyhow::Result; +use color_eyre::eyre::Result; use directories::BaseDirs; use crate::command::CommandExt; diff --git a/src/steps/generic.rs b/src/steps/generic.rs index daa26fdc..b6c90883 100644 --- a/src/steps/generic.rs +++ b/src/steps/generic.rs @@ -5,7 +5,9 @@ use std::process::Command; use std::{env, path::Path}; use std::{fs, io::Write}; -use anyhow::{Context, Result}; +use color_eyre::eyre::eyre; +use color_eyre::eyre::Context; +use color_eyre::eyre::Result; use directories::BaseDirs; use log::debug; use tempfile::tempfile_in; @@ -154,7 +156,7 @@ pub fn run_micro(run_type: RunType) -> Result<()> { if stdout.contains("Nothing to install / update") || stdout.contains("One or more plugins installed") { Ok(()) } else { - Err(anyhow::anyhow!("micro output does not indicate success: {}", stdout)) + Err(eyre!("micro output does not indicate success: {}", stdout)) } } diff --git a/src/steps/git.rs b/src/steps/git.rs index 3323ab92..811e31f4 100644 --- a/src/steps/git.rs +++ b/src/steps/git.rs @@ -3,7 +3,7 @@ use std::io; use std::path::{Path, PathBuf}; use std::process::{Command, Output, Stdio}; -use anyhow::{anyhow, Result}; +use color_eyre::eyre::{eyre, Result}; use console::style; use futures::stream::{iter, FuturesUnordered}; use futures::StreamExt; @@ -37,7 +37,7 @@ pub struct Repositories<'a> { fn output_checked_utf8(output: Output) -> Result<()> { if !(output.status.success()) { let stderr = String::from_utf8(output.stderr).unwrap(); - Err(anyhow!(stderr)) + Err(eyre!(stderr)) } else { Ok(()) } diff --git a/src/steps/kakoune.rs b/src/steps/kakoune.rs index 1a347fcd..d1b955aa 100644 --- a/src/steps/kakoune.rs +++ b/src/steps/kakoune.rs @@ -1,6 +1,6 @@ use crate::terminal::print_separator; use crate::utils::require; -use anyhow::Result; +use color_eyre::eyre::Result; use crate::execution_context::ExecutionContext; diff --git a/src/steps/node.rs b/src/steps/node.rs index 8559e317..29908108 100644 --- a/src/steps/node.rs +++ b/src/steps/node.rs @@ -4,7 +4,7 @@ use std::os::unix::fs::MetadataExt; use std::path::PathBuf; use std::process::Command; -use anyhow::Result; +use color_eyre::eyre::Result; use log::debug; #[cfg(target_os = "linux")] use nix::unistd::Uid; diff --git a/src/steps/os/android.rs b/src/steps/os/android.rs index 008af2ff..fe954f94 100644 --- a/src/steps/os/android.rs +++ b/src/steps/os/android.rs @@ -2,7 +2,7 @@ use crate::execution_context::ExecutionContext; use crate::terminal::print_separator; use crate::utils::require; use crate::Step; -use anyhow::Result; +use color_eyre::eyre::Result; pub fn upgrade_packages(ctx: &ExecutionContext) -> Result<()> { //let pkg = require("pkg")?; diff --git a/src/steps/os/archlinux.rs b/src/steps/os/archlinux.rs index b02e96fa..7c4e938c 100644 --- a/src/steps/os/archlinux.rs +++ b/src/steps/os/archlinux.rs @@ -3,7 +3,8 @@ use std::ffi::OsString; use std::path::{Path, PathBuf}; use std::process::Command; -use anyhow::Result; +use color_eyre::eyre; +use color_eyre::eyre::Result; use walkdir::WalkDir; use crate::command::CommandExt; @@ -301,7 +302,7 @@ pub fn get_arch_package_manager(ctx: &ExecutionContext) -> Option Result<()> { let package_manager = - get_arch_package_manager(ctx).ok_or_else(|| anyhow::Error::from(TopgradeError::FailedGettingPackageManager))?; + get_arch_package_manager(ctx).ok_or_else(|| eyre::Report::from(TopgradeError::FailedGettingPackageManager))?; package_manager.upgrade(ctx) } diff --git a/src/steps/os/dragonfly.rs b/src/steps/os/dragonfly.rs index 9893dfe1..55e8c3c3 100644 --- a/src/steps/os/dragonfly.rs +++ b/src/steps/os/dragonfly.rs @@ -1,7 +1,7 @@ use crate::executor::RunType; use crate::terminal::print_separator; use crate::utils::require_option; -use anyhow::Result; +use color_eyre::eyre::Result; use std::path::PathBuf; use std::process::Command; diff --git a/src/steps/os/freebsd.rs b/src/steps/os/freebsd.rs index 6233cc89..158a29bb 100644 --- a/src/steps/os/freebsd.rs +++ b/src/steps/os/freebsd.rs @@ -1,7 +1,7 @@ use crate::executor::RunType; use crate::terminal::print_separator; use crate::utils::require_option; -use anyhow::Result; +use color_eyre::eyre::Result; use std::path::PathBuf; use std::process::Command; diff --git a/src/steps/os/linux.rs b/src/steps/os/linux.rs index caa579f7..d9439bca 100644 --- a/src/steps/os/linux.rs +++ b/src/steps/os/linux.rs @@ -1,7 +1,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; -use anyhow::Result; +use color_eyre::eyre::Result; use ini::Ini; use log::{debug, warn}; diff --git a/src/steps/os/macos.rs b/src/steps/os/macos.rs index a9f23e5b..a2d9f527 100644 --- a/src/steps/os/macos.rs +++ b/src/steps/os/macos.rs @@ -3,7 +3,7 @@ use crate::execution_context::ExecutionContext; use crate::executor::RunType; use crate::terminal::{print_separator, prompt_yesno}; use crate::{utils::require, Step}; -use anyhow::Result; +use color_eyre::eyre::Result; use log::debug; use std::fs; use std::process::Command; diff --git a/src/steps/os/openbsd.rs b/src/steps/os/openbsd.rs index a8993231..b32c3e1e 100644 --- a/src/steps/os/openbsd.rs +++ b/src/steps/os/openbsd.rs @@ -1,7 +1,7 @@ use crate::executor::RunType; use crate::terminal::print_separator; use crate::utils::require_option; -use anyhow::Result; +use color_eyre::eyre::Result; use std::path::PathBuf; pub fn upgrade_openbsd(sudo: Option<&PathBuf>, run_type: RunType) -> Result<()> { diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index 8396f7ea..9457e4b5 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -6,7 +6,7 @@ use std::{env, path::Path}; use crate::command::CommandExt; use crate::Step; -use anyhow::Result; +use color_eyre::eyre::Result; use directories::BaseDirs; use home; use ini::Ini; diff --git a/src/steps/os/windows.rs b/src/steps/os/windows.rs index 8fbddc78..b98bb8de 100644 --- a/src/steps/os/windows.rs +++ b/src/steps/os/windows.rs @@ -2,7 +2,7 @@ use std::convert::TryFrom; use std::path::Path; use std::{ffi::OsStr, process::Command}; -use anyhow::Result; +use color_eyre::eyre::Result; use log::debug; use crate::command::CommandExt; diff --git a/src/steps/powershell.rs b/src/steps/powershell.rs index 324e093a..f6fe50e3 100644 --- a/src/steps/powershell.rs +++ b/src/steps/powershell.rs @@ -3,7 +3,7 @@ use std::path::Path; use std::path::PathBuf; use std::process::Command; -use anyhow::Result; +use color_eyre::eyre::Result; use crate::command::CommandExt; use crate::execution_context::ExecutionContext; diff --git a/src/steps/remote/ssh.rs b/src/steps/remote/ssh.rs index b6feb2c9..9d76a46f 100644 --- a/src/steps/remote/ssh.rs +++ b/src/steps/remote/ssh.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +use color_eyre::eyre::Result; use crate::{ command::CommandExt, error::SkipStep, execution_context::ExecutionContext, terminal::print_separator, utils, diff --git a/src/steps/remote/vagrant.rs b/src/steps/remote/vagrant.rs index 5a63214a..25f511d3 100644 --- a/src/steps/remote/vagrant.rs +++ b/src/steps/remote/vagrant.rs @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf}; use std::process::Command; use std::{fmt::Display, rc::Rc, str::FromStr}; -use anyhow::Result; +use color_eyre::eyre::Result; use log::{debug, error}; use regex::Regex; use strum::EnumString; diff --git a/src/steps/tmux.rs b/src/steps/tmux.rs index fcc016ea..399ba455 100644 --- a/src/steps/tmux.rs +++ b/src/steps/tmux.rs @@ -2,7 +2,7 @@ use std::env; use std::path::PathBuf; use std::process::{exit, Command}; -use anyhow::Result; +use color_eyre::eyre::Result; use directories::BaseDirs; use crate::command::CommandExt; diff --git a/src/steps/toolbx.rs b/src/steps/toolbx.rs index 9ddd2d0c..014ed706 100644 --- a/src/steps/toolbx.rs +++ b/src/steps/toolbx.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +use color_eyre::eyre::Result; use crate::command::CommandExt; use crate::config::Step; diff --git a/src/steps/vim.rs b/src/steps/vim.rs index 6b0137db..5f931795 100644 --- a/src/steps/vim.rs +++ b/src/steps/vim.rs @@ -1,6 +1,6 @@ use crate::command::CommandExt; use crate::error::{SkipStep, TopgradeError}; -use anyhow::Result; +use color_eyre::eyre::Result; use crate::executor::{Executor, ExecutorOutput, RunType}; use crate::terminal::print_separator; diff --git a/src/steps/zsh.rs b/src/steps/zsh.rs index 0c3f90df..e66aafa4 100644 --- a/src/steps/zsh.rs +++ b/src/steps/zsh.rs @@ -2,7 +2,7 @@ use std::env; use std::path::{Path, PathBuf}; use std::process::Command; -use anyhow::Result; +use color_eyre::eyre::Result; use directories::BaseDirs; use log::debug; use walkdir::WalkDir; diff --git a/src/terminal.rs b/src/terminal.rs index a92699cc..3ff525bf 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -7,8 +7,9 @@ use std::process::Command; use std::sync::Mutex; use std::time::Duration; -use anyhow::Context; use chrono::{Local, Timelike}; +use color_eyre::eyre; +use color_eyre::eyre::Context; use console::{style, Key, Term}; use lazy_static::lazy_static; use log::{debug, error}; @@ -36,7 +37,7 @@ pub fn shell() -> &'static str { which("pwsh").map(|_| "pwsh").unwrap_or("powershell") } -pub fn run_shell() -> anyhow::Result<()> { +pub fn run_shell() -> eyre::Result<()> { Command::new(shell()).env("IN_TOPGRADE", "1").status_checked() } @@ -213,7 +214,7 @@ impl Terminal { } } #[allow(unused_variables)] - fn should_retry(&mut self, interrupted: bool, step_name: &str) -> anyhow::Result { + fn should_retry(&mut self, interrupted: bool, step_name: &str) -> eyre::Result { if self.width.is_none() { return Ok(false); } @@ -269,7 +270,7 @@ impl Default for Terminal { } } -pub fn should_retry(interrupted: bool, step_name: &str) -> anyhow::Result { +pub fn should_retry(interrupted: bool, step_name: &str) -> eyre::Result { TERMINAL.lock().unwrap().should_retry(interrupted, step_name) } diff --git a/src/utils.rs b/src/utils.rs index 9eedf50a..8feddad5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,5 +1,5 @@ use crate::error::SkipStep; -use anyhow::Result; +use color_eyre::eyre::Result; use log::{debug, error}; use std::env;