Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve errors related to services #26

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions crates/test-environment/src/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn get_builtin_service_definitions(
return Ok(Vec::new());
}

std::fs::read_dir(service_definitions_path)
let result = std::fs::read_dir(service_definitions_path)
.with_context(|| {
format!(
"no service definitions found at '{}'",
Expand All @@ -147,7 +147,7 @@ fn get_builtin_service_definitions(
Ok((file_name.to_owned(), file_extension.to_owned()))
})
.filter(|r| !matches!(r, Ok((_, extension)) if extension == "lock"))
.filter(move |r| match r {
.filter(|r| match r {
Ok((service, _)) => builtins.remove(service.as_str()),
_ => false,
})
Expand All @@ -157,18 +157,22 @@ fn get_builtin_service_definitions(
name: name.clone(),
kind: match extension.as_str() {
"py" => ServiceKind::Python {
script: service_definitions_path.join(format!("{}.py", name)),
script: service_definitions_path.join(format!("{name}.py")),
},
"Dockerfile" => ServiceKind::Docker {
image: docker::DockerImage::FromDockerfile(
service_definitions_path.join(format!("{}.Dockerfile", name)),
service_definitions_path.join(format!("{name}.Dockerfile")),
),
},
_ => bail!("unsupported service definition extension '{}'", extension),
_ => bail!("unsupported service definition extension '{extension}'"),
},
})
})
.collect()
.collect();
if !builtins.is_empty() {
bail!("no service definitions found for: {builtins:?}",);
}
result
}

/// A service definition.
Expand Down
9 changes: 7 additions & 2 deletions crates/test-environment/src/services/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,12 @@ fn build_image(dockerfile_path: &Path, image_name: &String) -> anyhow::Result<()
.stdout(Stdio::null())
.stderr(Stdio::piped())
.output()
.context("service failed to spawn")?;
.with_context(|| {
format!(
"docker build failed to spawn for Dockerfile '{}'",
dockerfile_path.display()
)
})?;

if !output.status.success() {
let stderr = std::str::from_utf8(&output.stderr).unwrap_or("<non-utf8>");
Expand Down Expand Up @@ -196,7 +201,7 @@ fn run_container(image_name: &str) -> anyhow::Result<Container> {
.arg("--health-start-period=1s")
.arg(image_name)
.output()
.context("service failed to spawn")?;
.with_context(|| format!("docker run failed to spawn for image '{image_name}'"))?;
if !output.status.success() {
bail!("failed to run docker image");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/test-environment/src/services/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl PythonService {
.arg(script_path.display().to_string())
.stdout(Stdio::piped())
.spawn()
.context("service failed to spawn")?;
.with_context(|| format!("python failed to spawn for '{}'", script_path.display()))?;
std::thread::sleep(std::time::Duration::from_millis(1000));
Ok(Self {
stdout: OutputStream::new(
Expand Down