Skip to content

Commit

Permalink
Merge pull request #501 from stepchowfun/output-paths-shell
Browse files Browse the repository at this point in the history
Respect `--shell` when a task fails due to `output_paths` not existing in the container
  • Loading branch information
stepchowfun authored Feb 22, 2024
2 parents 6837e79 + 7ff464b commit 7693ee7
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.47.6] - 2024-02-21

### Fixed
- When a task fails due to `output_paths` not existing in the container, the `--shell` flag is no longer ignored.

## [0.47.5] - 2023-06-18

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "toast"
version = "0.47.5"
version = "0.47.6"
authors = ["Stephan Boyer <[email protected]>"]
edition = "2021"
description = "Containerize your development and continuous integration environments."
Expand Down
30 changes: 30 additions & 0 deletions src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub fn image_exists(
.into_iter()
.map(std::borrow::ToOwned::to_owned)
.collect::<Vec<_>>(),
false,
interrupted,
) {
Ok(_) => Ok(true),
Expand All @@ -62,6 +63,7 @@ pub fn push_image(
.into_iter()
.map(std::borrow::ToOwned::to_owned)
.collect::<Vec<_>>(),
false,
interrupted,
)
.map(|_| ())
Expand All @@ -83,6 +85,7 @@ pub fn pull_image(
.into_iter()
.map(std::borrow::ToOwned::to_owned)
.collect::<Vec<_>>(),
false,
interrupted,
)
.map(|_| ())
Expand All @@ -104,6 +107,7 @@ pub fn delete_image(
.into_iter()
.map(std::borrow::ToOwned::to_owned)
.collect::<Vec<_>>(),
false,
interrupted,
)
.map(|_| ())
Expand Down Expand Up @@ -154,6 +158,7 @@ pub fn create_container(
"Creating container\u{2026}",
"Unable to create container.",
&args,
false,
interrupted,
)?
.trim()
Expand Down Expand Up @@ -182,6 +187,7 @@ pub fn copy_into_container<R: Read>(
"-".to_owned(),
format!("{container}:/"),
],
false,
|mut stdin| {
io::copy(&mut tar, &mut stdin)
.map_err(failure::system("Unable to copy files into the container."))?;
Expand Down Expand Up @@ -296,6 +302,7 @@ pub fn copy_from_container(
format!("{}:{}", container, source.to_string_lossy()),
intermediate.to_string_lossy().into_owned(),
],
true,
interrupted,
)
.map(|_| ())?;
Expand Down Expand Up @@ -379,6 +386,7 @@ pub fn start_container(
.into_iter()
.map(std::borrow::ToOwned::to_owned)
.collect::<Vec<_>>(),
true,
interrupted,
)
.map(|()| ())
Expand All @@ -400,6 +408,7 @@ pub fn stop_container(
.into_iter()
.map(std::borrow::ToOwned::to_owned)
.collect::<Vec<_>>(),
false,
interrupted,
)
.map(|_| ())
Expand All @@ -426,6 +435,7 @@ pub fn commit_container(
.into_iter()
.map(std::borrow::ToOwned::to_owned)
.collect::<Vec<_>>(),
false,
interrupted,
)
.map(|_| ())
Expand All @@ -447,6 +457,7 @@ pub fn delete_container(
.into_iter()
.map(std::borrow::ToOwned::to_owned)
.collect::<Vec<_>>(),
false,
interrupted,
)
.map(|_| ())
Expand Down Expand Up @@ -498,6 +509,7 @@ pub fn spawn_shell(
docker_cli,
"The shell exited with a failure.",
&args,
true,
interrupted,
)
}
Expand Down Expand Up @@ -600,6 +612,7 @@ fn run_quiet(
spinner_message: &str,
error: &str,
args: &[String],
user_command: bool,
interrupted: &Arc<AtomicBool>,
) -> Result<String, Failure> {
// Render a spinner animation and clear it when we're done.
Expand All @@ -626,6 +639,11 @@ fn run_quiet(
{
interrupted.store(true, Ordering::SeqCst);
Failure::Interrupted
} else if user_command {
Failure::User(
format!("{}\n{}", error, String::from_utf8_lossy(&child.stderr)),
None,
)
} else {
Failure::System(
format!("{}\n{}", error, String::from_utf8_lossy(&child.stderr)),
Expand All @@ -643,6 +661,7 @@ fn run_quiet_stdin<W: FnOnce(&mut ChildStdin) -> Result<(), Failure>>(
spinner_message: &str,
error: &str,
args: &[String],
user_command: bool,
writer: W,
interrupted: &Arc<AtomicBool>,
) -> Result<String, Failure> {
Expand Down Expand Up @@ -681,6 +700,11 @@ fn run_quiet_stdin<W: FnOnce(&mut ChildStdin) -> Result<(), Failure>>(
{
interrupted.store(true, Ordering::SeqCst);
Failure::Interrupted
} else if user_command {
Failure::User(
format!("{}\n{}", error, String::from_utf8_lossy(&output.stderr)),
None,
)
} else {
Failure::System(
format!("{}\n{}", error, String::from_utf8_lossy(&output.stderr)),
Expand All @@ -696,6 +720,7 @@ fn run_loud(
docker_cli: &str,
error: &str,
args: &[String],
user_command: bool,
interrupted: &Arc<AtomicBool>,
) -> Result<(), Failure> {
// This is used to determine whether the user interrupted the program during the execution of
Expand Down Expand Up @@ -723,6 +748,8 @@ fn run_loud(
if status.code().is_none() || (!was_interrupted && interrupted.load(Ordering::SeqCst)) {
interrupted.store(true, Ordering::SeqCst);
Failure::Interrupted
} else if user_command {
Failure::User(error.to_owned(), None)
} else {
Failure::System(error.to_owned(), None)
},
Expand All @@ -735,6 +762,7 @@ fn run_attach(
docker_cli: &str,
error: &str,
args: &[String],
user_command: bool,
interrupted: &Arc<AtomicBool>,
) -> Result<(), Failure> {
// This is used to determine whether the user interrupted the program during the execution of
Expand All @@ -756,6 +784,8 @@ fn run_attach(
if child.code().is_none() || (!was_interrupted && interrupted.load(Ordering::SeqCst)) {
interrupted.store(true, Ordering::SeqCst);
Failure::Interrupted
} else if user_command {
Failure::User(error.to_owned(), None)
} else {
Failure::System(error.to_owned(), None)
},
Expand Down
2 changes: 1 addition & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub fn run(
.map_err(|e| match e {
Failure::Interrupted => e,
Failure::System(_, _) | Failure::User(_, _) => {
Failure::User("Command failed.".to_owned(), None)
Failure::User("Task failed.".to_owned(), None)
}
});

Expand Down

0 comments on commit 7693ee7

Please sign in to comment.