Skip to content

Commit

Permalink
remove a bunch of needless map_err(Into::into) and workaround wrong…
Browse files Browse the repository at this point in the history
… assumptions about location tracking over `map_err(Into::into)`
  • Loading branch information
Emilgardis committed Dec 27, 2023
1 parent 23fc877 commit 44524f3
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/bin/commands/containers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ pub fn remove_all_volumes(
if volumes.is_empty() {
Ok(())
} else if execute {
command.run(msg_info, false).map_err(Into::into)
command.run(msg_info, false)
} else {
msg_info.note("this is a dry run. to remove the volumes, pass the `--execute` flag.")?;
command.print(msg_info)?;
Expand All @@ -374,7 +374,7 @@ pub fn prune_volumes(
let mut command = engine.subcommand("volume");
command.args(["prune", "--force"]);
if execute {
command.run(msg_info, false).map_err(Into::into)
command.run(msg_info, false)
} else {
msg_info.note("this is a dry run. to prune the volumes, pass the `--execute` flag.")?;
command.print(msg_info)?;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/commands/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ fn remove_images(
if images.is_empty() {
Ok(())
} else if execute {
command.run(msg_info, false).map_err(Into::into)
command.run(msg_info, false)
} else {
msg_info.note("this is a dry run. to remove the images, pass the `--execute` flag.")?;
command.print(msg_info)?;
Expand Down
3 changes: 1 addition & 2 deletions src/docker/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ pub(crate) fn run(
let status = docker
.arg(&image_name)
.add_build_command(toolchain_dirs, &cmd)
.run_and_get_status(msg_info, false)
.map_err(Into::into);
.run_and_get_status(msg_info, false);

// `cargo` generally returns 0 or 101 on completion, but isn't guaranteed
// to. `ExitStatus::code()` may be None if a signal caused the process to
Expand Down
4 changes: 1 addition & 3 deletions src/docker/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,9 +983,7 @@ symlink_recurse \"${{prefix}}\"
}

bail_container_exited!();
let status = docker
.run_and_get_status(msg_info, false)
.map_err(Into::into);
let status = docker.run_and_get_status(msg_info, false);

// 7. copy data from our target dir back to host
// this might not exist if we ran `clean`.
Expand Down
2 changes: 1 addition & 1 deletion src/docker/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ impl Engine {
docker.arg(UBUNTU_BASE);
docker.args(["sh", "-c", cmd]);

docker.run(msg_info, false).map_err(Into::into)
docker.run(msg_info, false)
}
}

Expand Down
19 changes: 9 additions & 10 deletions src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl CommandExt for Command {
string
}

#[track_caller]
fn status_result(
&self,
msg_info: &mut MessageInfo,
Expand All @@ -140,10 +141,11 @@ impl CommandExt for Command {
}

/// Runs the command to completion
#[track_caller]
fn run(&mut self, msg_info: &mut MessageInfo, silence_stdout: bool) -> Result<()> {
let status = self.run_and_get_status(msg_info, silence_stdout)?;
self.status_result(msg_info, status, None)
.map_err(Into::into)
#[warn(clippy::nursery)]
Ok(self.status_result(msg_info, status, None)?)
}

/// Runs the command to completion
Expand All @@ -157,13 +159,10 @@ impl CommandExt for Command {
if silence_stdout && !msg_info.is_verbose() {
self.stdout(std::process::Stdio::null());
}
self.status()
.map_err(|e| CommandError::CouldNotExecute {
source: Box::new(e),
command: self
.command_pretty(msg_info, |cmd| STRIPPED_BINS.iter().any(|f| f == &cmd)),
})
.map_err(Into::into)
Ok(self.status().map_err(|e| CommandError::CouldNotExecute {
source: Box::new(e),
command: self.command_pretty(msg_info, |cmd| STRIPPED_BINS.iter().any(|f| f == &cmd)),
})?)
}

/// Runs the command to completion and returns its stdout
Expand All @@ -172,7 +171,7 @@ impl CommandExt for Command {
let out = self.run_and_get_output(msg_info)?;
self.status_result(msg_info, out.status, Some(&out))
.map_err(CommandError::to_section_report)?;
out.stdout().map_err(Into::into)
Ok(out.stdout()?)
}

/// Runs the command to completion and returns the status and its [output](std::process::Output).
Expand Down
12 changes: 6 additions & 6 deletions xtask/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ pub struct Test {
tox: Option<String>,
}

#[track_caller]
fn cargo_fmt(msg_info: &mut MessageInfo, channel: Option<&str>) -> cross::Result<()> {
cargo(channel)
.args(["fmt", "--", "--check"])
.run(msg_info, false)
.map_err(Into::into)
}

#[track_caller]
fn cargo_clippy(msg_info: &mut MessageInfo, channel: Option<&str>) -> cross::Result<()> {
cargo(channel)
.arg("clippy")
.args(CARGO_FLAGS)
.args(["--", "--deny", "warnings"])
.run(msg_info, false)
.map_err(Into::into)
}

#[track_caller]
fn cargo_test(msg_info: &mut MessageInfo, channel: Option<&str>) -> cross::Result<()> {
cargo(channel)
.arg("test")
.args(CARGO_FLAGS)
.run(msg_info, false)
.map_err(Into::into)
}

fn splitlines(string: String) -> Vec<String> {
Expand Down Expand Up @@ -194,9 +194,9 @@ pub fn check(
msg_info.info(format_args!("Running {} checks.", checks.join(", ")))?;

let channel = get_channel_prefer_nightly(msg_info, toolchain)?;
cargo_fmt(msg_info, channel)?;
cargo_clippy(msg_info, channel)?;
shellcheck(all, msg_info)?;
cargo_fmt(msg_info, channel).wrap_err("fmt failed")?;
cargo_clippy(msg_info, channel).wrap_err("clippy failed")?;
shellcheck(all, msg_info).wrap_err("shellcheck failed")?;
if python {
python_lint(flake8.as_deref(), msg_info)?;
}
Expand Down
4 changes: 1 addition & 3 deletions xtask/src/target_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ fn image_info(
}
command.arg(image);
command.args(["bash", "-c", TARGET_INFO_SCRIPT]);
command
.run(msg_info, msg_info.is_verbose())
.map_err(Into::into)
command.run(msg_info, msg_info.is_verbose())
}

pub fn target_info(
Expand Down
1 change: 0 additions & 1 deletion xtask/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ pub fn has_nightly(msg_info: &mut MessageInfo) -> cross::Result<bool> {
.arg("+nightly")
.run_and_get_output(msg_info)
.map(|o| o.status.success())
.map_err(Into::into)
}

pub fn get_channel_prefer_nightly<'a>(
Expand Down

0 comments on commit 44524f3

Please sign in to comment.