Better error model
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use super::error::{Error, ErrorKind};
|
||||
use super::executor::Executor;
|
||||
use super::terminal::print_separator;
|
||||
use super::utils::{self, which, Check};
|
||||
use failure;
|
||||
use failure::ResultExt;
|
||||
use log::error;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
@@ -11,7 +12,7 @@ pub fn run_chocolatey(dry_run: bool) -> Option<(&'static str, bool)> {
|
||||
if let Some(choco) = utils::which("choco") {
|
||||
print_separator("Chocolatey");
|
||||
|
||||
let success = || -> Result<(), failure::Error> {
|
||||
let success = || -> Result<(), Error> {
|
||||
Executor::new(&choco, dry_run)
|
||||
.args(&["upgrade", "all"])
|
||||
.spawn()?
|
||||
@@ -32,7 +33,7 @@ pub fn run_scoop(dry_run: bool) -> Option<(&'static str, bool)> {
|
||||
if let Some(scoop) = utils::which("scoop") {
|
||||
print_separator("Scoop");
|
||||
|
||||
let success = || -> Result<(), failure::Error> {
|
||||
let success = || -> Result<(), Error> {
|
||||
Executor::new(&scoop, dry_run)
|
||||
.args(&["update"])
|
||||
.spawn()?
|
||||
@@ -65,10 +66,11 @@ impl Powershell {
|
||||
}
|
||||
|
||||
pub fn has_command(powershell: &PathBuf, command: &str) -> bool {
|
||||
|| -> Result<(), failure::Error> {
|
||||
|| -> Result<(), Error> {
|
||||
Command::new(&powershell)
|
||||
.args(&["-Command", &format!("Get-Command {}", command)])
|
||||
.output()?
|
||||
.output()
|
||||
.context(ErrorKind::ProcessExecution)?
|
||||
.check()?;
|
||||
Ok(())
|
||||
}()
|
||||
@@ -77,8 +79,11 @@ impl Powershell {
|
||||
|
||||
pub fn profile(&self) -> Option<PathBuf> {
|
||||
if let Some(powershell) = &self.path {
|
||||
let result = || -> Result<PathBuf, failure::Error> {
|
||||
let output = Command::new(powershell).args(&["-Command", "echo $profile"]).output()?;
|
||||
let result = || -> Result<PathBuf, Error> {
|
||||
let output = Command::new(powershell)
|
||||
.args(&["-Command", "echo $profile"])
|
||||
.output()
|
||||
.context(ErrorKind::ProcessExecution)?;
|
||||
output.status.check()?;
|
||||
Ok(PathBuf::from(
|
||||
String::from_utf8_lossy(&output.stdout).trim().to_string(),
|
||||
@@ -98,7 +103,7 @@ impl Powershell {
|
||||
if let Some(powershell) = &self.path {
|
||||
print_separator("Powershell Modules Update");
|
||||
|
||||
let success = || -> Result<(), failure::Error> {
|
||||
let success = || -> Result<(), Error> {
|
||||
Executor::new(&powershell, dry_run)
|
||||
.arg("Update-Module")
|
||||
.spawn()?
|
||||
@@ -120,7 +125,7 @@ impl Powershell {
|
||||
if Self::has_command(&powershell, "Install-WindowsUpdate") {
|
||||
print_separator("Windows Update");
|
||||
|
||||
let success = || -> Result<(), failure::Error> {
|
||||
let success = || -> Result<(), Error> {
|
||||
Executor::new(&powershell, dry_run)
|
||||
.args(&["-Command", "Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose"])
|
||||
.spawn()?
|
||||
|
||||
Reference in New Issue
Block a user