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

add some more context to error messages #884

Merged
merged 1 commit into from
Jun 30, 2022
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
3 changes: 2 additions & 1 deletion src/docker/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ pub(crate) fn run(

docker.arg("--rm");

docker_seccomp(&mut docker, engine.kind, target, metadata)?;
docker_seccomp(&mut docker, engine.kind, target, metadata)
.wrap_err("when copying seccomp profile")?;
docker_user_id(&mut docker, engine.kind);

docker
Expand Down
1 change: 1 addition & 0 deletions src/docker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn run(
docker_in_docker,
cwd,
)
.wrap_err("could not complete remote run")
} else {
local::run(
engine,
Expand Down
50 changes: 31 additions & 19 deletions src/docker/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::path::{Path, PathBuf};
use std::process::ExitStatus;
use std::{env, fs, time};

use eyre::Context;

use super::engine::Engine;
use super::shared::*;
use crate::cargo::CargoMetadata;
Expand Down Expand Up @@ -114,7 +116,6 @@ fn create_volume_dir(
.arg(container)
.args(&["sh", "-c", &format!("mkdir -p '{}'", dir.as_posix()?)])
.run_and_get_status(msg_info, false)
.map_err(Into::into)
}

// copy files for a docker volume, for remote host support
Expand All @@ -130,7 +131,6 @@ fn copy_volume_files(
.arg(src.to_utf8()?)
.arg(format!("{container}:{}", dst.as_posix()?))
.run_and_get_status(msg_info, false)
.map_err(Into::into)
}

fn is_cachedir_tag(path: &Path) -> Result<bool> {
Expand Down Expand Up @@ -223,9 +223,15 @@ pub fn copy_volume_container_cargo(
} else {
// can copy a limit subset of files: the rest is present.
create_volume_dir(engine, container, &dst, msg_info)?;
for entry in fs::read_dir(cargo_dir)? {
for entry in fs::read_dir(cargo_dir)
.wrap_err_with(|| format!("when reading directory {cargo_dir:?}"))?
{
let file = entry?;
let basename = file.file_name().to_utf8()?.to_string();
let basename = file
.file_name()
.to_utf8()
.wrap_err_with(|| format!("when reading file {file:?}"))?
.to_string();
if !basename.starts_with('.') && !matches!(basename.as_ref(), "git" | "registry") {
copy_volume_files(engine, container, &file.path(), &dst, msg_info)?;
}
Expand All @@ -248,7 +254,7 @@ where
{
let mut had_symlinks = false;

for entry in fs::read_dir(src)? {
for entry in fs::read_dir(src).wrap_err_with(|| format!("when reading directory {src:?}"))? {
let file = entry?;
if skip(&file, depth) {
continue;
Expand All @@ -257,7 +263,8 @@ where
let src_path = file.path();
let dst_path = dst.join(file.file_name());
if file.file_type()?.is_file() {
fs::copy(&src_path, &dst_path)?;
fs::copy(&src_path, &dst_path)
.wrap_err_with(|| format!("when copying file {src_path:?} -> {dst_path:?}"))?;
} else if file.file_type()?.is_dir() {
fs::create_dir(&dst_path).ok();
had_symlinks = copy_dir(&src_path, &dst_path, copy_symlinks, depth + 1, skip)?;
Expand Down Expand Up @@ -604,7 +611,6 @@ rm \"{PATH}\"
.arg(container)
.args(&["sh", "-c", &script.join("\n")])
.run_and_get_status(msg_info, true)
.map_err(Into::into)
}

fn copy_volume_container_project(
Expand Down Expand Up @@ -657,7 +663,6 @@ fn run_and_get_status(engine: &Engine, args: &[&str], msg_info: MessageInfo) ->
command(engine)
.args(args)
.run_and_get_status(msg_info, true)
.map_err(Into::into)
}

pub fn volume_create(engine: &Engine, volume: &str, msg_info: MessageInfo) -> Result<ExitStatus> {
Expand All @@ -673,7 +678,6 @@ pub fn volume_exists(engine: &Engine, volume: &str, msg_info: MessageInfo) -> Re
.args(&["volume", "inspect", volume])
.run_and_get_output(msg_info)
.map(|output| output.status.success())
.map_err(Into::into)
}

pub fn container_stop(
Expand Down Expand Up @@ -805,7 +809,7 @@ pub(crate) fn run(

// 2. create our volume to copy all our data over to
if let VolumeId::Discard(ref id) = volume {
volume_create(engine, id, msg_info)?;
volume_create(engine, id, msg_info).wrap_err("when creating volume")?;
}
let _volume_deletter = DeleteVolume(engine, &volume, msg_info);

Expand All @@ -825,9 +829,11 @@ pub(crate) fn run(
cwd,
|_, val| mount_path(val),
|(src, dst)| volumes.push((src, dst)),
)?;
)
.wrap_err("could not determine mount points")?;

docker_seccomp(&mut docker, engine.kind, target, metadata)?;
docker_seccomp(&mut docker, engine.kind, target, metadata)
.wrap_err("when copying seccomp profile")?;

// Prevent `bin` from being mounted inside the Docker container.
docker.args(&["-v", &format!("{mount_prefix}/cargo/bin")]);
Expand Down Expand Up @@ -871,15 +877,17 @@ pub(crate) fn run(
target,
mount_prefix_path,
msg_info,
)?;
)
.wrap_err("when copying xargo")?;
copy_volume_container_cargo(
engine,
&container,
&dirs.cargo,
mount_prefix_path,
false,
msg_info,
)?;
)
.wrap_err("when copying cargo")?;
copy_volume_container_rust(
engine,
&container,
Expand All @@ -888,7 +896,8 @@ pub(crate) fn run(
mount_prefix_path,
false,
msg_info,
)?;
)
.wrap_err("when copying rust")?;
} else {
// need to copy over the target triple if it hasn't been previously copied
copy_volume_container_rust_triple(
Expand All @@ -899,14 +908,16 @@ pub(crate) fn run(
mount_prefix_path,
true,
msg_info,
)?;
)
.wrap_err("when copying rust target files")?;
}
let mount_root = if mount_volumes {
// cannot panic: absolute unix path, must have root
let rel_mount_root = dirs.mount_root.strip_prefix('/').unwrap();
let mount_root = mount_prefix_path.join(rel_mount_root);
if !rel_mount_root.is_empty() {
create_volume_dir(engine, &container, mount_root.parent().unwrap(), msg_info)?;
create_volume_dir(engine, &container, mount_root.parent().unwrap(), msg_info)
.wrap_err("when creating mount root")?;
}
mount_root
} else {
Expand All @@ -920,7 +931,8 @@ pub(crate) fn run(
&volume,
copy_cache,
msg_info,
)?;
)
.wrap_err("when copying project")?;

let mut copied = vec![
(&dirs.xargo, mount_prefix_path.join("xargo")),
Expand Down Expand Up @@ -1029,7 +1041,7 @@ symlink_recurse \"${{prefix}}\"
.arg(&container)
.args(&["sh", "-c", &symlink.join("\n")])
.run_and_get_status(msg_info, false)
.map_err::<eyre::ErrReport, _>(Into::into)?;
.wrap_err("when creating symlinks to provide consistent host/mount paths")?;

// 6. execute our cargo command inside the container
let mut docker = subcommand(engine, "exec");
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ pub fn run() -> Result<ExitStatus> {
args.msg_info,
args.docker_in_docker,
&cwd,
)?;
)
.wrap_err("could not run container")?;
let needs_host = args
.subcommand
.map(|sc| sc.needs_host(is_remote))
Expand Down