Skip to content

Commit b8eb391

Browse files
committed
add some more context to error messages on remote::run
1 parent e583132 commit b8eb391

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

src/docker/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub fn run(
4141
docker_in_docker,
4242
cwd,
4343
)
44+
.wrap_err("could not complete remote run")
4445
} else {
4546
local::run(
4647
engine,

src/docker/remote.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::path::{Path, PathBuf};
44
use std::process::ExitStatus;
55
use std::{env, fs, time};
66

7+
use eyre::Context;
8+
79
use super::engine::Engine;
810
use super::shared::*;
911
use crate::cargo::CargoMetadata;
@@ -130,7 +132,7 @@ fn copy_volume_files(
130132
.arg(src.to_utf8()?)
131133
.arg(format!("{container}:{}", dst.as_posix()?))
132134
.run_and_get_status(msg_info, false)
133-
.map_err(Into::into)
135+
.map(Into::into)
134136
}
135137

136138
fn is_cachedir_tag(path: &Path) -> Result<bool> {
@@ -221,9 +223,15 @@ pub fn copy_volume_container_cargo(
221223
} else {
222224
// can copy a limit subset of files: the rest is present.
223225
create_volume_dir(engine, container, &dst, msg_info)?;
224-
for entry in fs::read_dir(cargo_dir)? {
226+
for entry in fs::read_dir(cargo_dir)
227+
.wrap_err_with(|| format!("when reading directory {cargo_dir:?}"))?
228+
{
225229
let file = entry?;
226-
let basename = file.file_name().to_utf8()?.to_string();
230+
let basename = file
231+
.file_name()
232+
.to_utf8()
233+
.wrap_err_with(|| format!("when reading file {file:?}"))?
234+
.to_string();
227235
if !basename.starts_with('.') && !matches!(basename.as_ref(), "git" | "registry") {
228236
copy_volume_files(engine, container, &file.path(), &dst, msg_info)?;
229237
}
@@ -238,7 +246,7 @@ fn copy_dir<Skip>(src: &Path, dst: &Path, depth: u32, skip: Skip) -> Result<()>
238246
where
239247
Skip: Copy + Fn(&fs::DirEntry, u32) -> bool,
240248
{
241-
for entry in fs::read_dir(src)? {
249+
for entry in fs::read_dir(src).wrap_err_with(|| format!("when reading directory {src:?}"))? {
242250
let file = entry?;
243251
if skip(&file, depth) {
244252
continue;
@@ -247,7 +255,8 @@ where
247255
let src_path = file.path();
248256
let dst_path = dst.join(file.file_name());
249257
if file.file_type()?.is_file() {
250-
fs::copy(&src_path, &dst_path)?;
258+
fs::copy(&src_path, &dst_path)
259+
.wrap_err_with(|| format!("when copying file {src_path:?} -> {dst_path:?}"))?;
251260
} else {
252261
fs::create_dir(&dst_path).ok();
253262
copy_dir(&src_path, &dst_path, depth + 1, skip)?;
@@ -755,7 +764,7 @@ pub(crate) fn run(
755764

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

@@ -775,9 +784,11 @@ pub(crate) fn run(
775784
cwd,
776785
|_, val| mount_path(val),
777786
|(src, dst)| volumes.push((src, dst)),
778-
)?;
787+
)
788+
.wrap_err("could not determine mount points")?;
779789

780-
docker_seccomp(&mut docker, engine.kind, target, metadata)?;
790+
docker_seccomp(&mut docker, engine.kind, target, metadata)
791+
.wrap_err("when copying seccomp profile")?;
781792

782793
// Prevent `bin` from being mounted inside the Docker container.
783794
docker.args(&["-v", &format!("{mount_prefix}/cargo/bin")]);
@@ -821,15 +832,17 @@ pub(crate) fn run(
821832
target,
822833
mount_prefix_path,
823834
msg_info,
824-
)?;
835+
)
836+
.wrap_err("when copying xargo")?;
825837
copy_volume_container_cargo(
826838
engine,
827839
&container,
828840
&dirs.cargo,
829841
mount_prefix_path,
830842
false,
831843
msg_info,
832-
)?;
844+
)
845+
.wrap_err("when copying cargo")?;
833846
copy_volume_container_rust(
834847
engine,
835848
&container,
@@ -838,7 +851,8 @@ pub(crate) fn run(
838851
mount_prefix_path,
839852
false,
840853
msg_info,
841-
)?;
854+
)
855+
.wrap_err("when copying rust")?;
842856
} else {
843857
// need to copy over the target triple if it hasn't been previously copied
844858
copy_volume_container_rust_triple(
@@ -849,14 +863,16 @@ pub(crate) fn run(
849863
mount_prefix_path,
850864
true,
851865
msg_info,
852-
)?;
866+
)
867+
.wrap_err("when copying rust target files")?;
853868
}
854869
let mount_root = if mount_volumes {
855870
// cannot panic: absolute unix path, must have root
856871
let rel_mount_root = dirs.mount_root.strip_prefix('/').unwrap();
857872
let mount_root = mount_prefix_path.join(rel_mount_root);
858873
if !rel_mount_root.is_empty() {
859-
create_volume_dir(engine, &container, mount_root.parent().unwrap(), msg_info)?;
874+
create_volume_dir(engine, &container, mount_root.parent().unwrap(), msg_info)
875+
.wrap_err("when creating mount root")?;
860876
}
861877
mount_root
862878
} else {

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,8 @@ pub fn run() -> Result<ExitStatus> {
518518
args.msg_info,
519519
args.docker_in_docker,
520520
&cwd,
521-
)?;
521+
)
522+
.wrap_err("when running docker")?;
522523
let needs_host = args
523524
.subcommand
524525
.map(|sc| sc.needs_host(is_remote))

0 commit comments

Comments
 (0)