Skip to content

Commit f059d1a

Browse files
Merge #884
884: add some more context to error messages r=Alexhuszagh a=Emilgardis Co-authored-by: Emil Gardström <[email protected]>
2 parents 5a55c2e + 621a20f commit f059d1a

File tree

4 files changed

+36
-21
lines changed

4 files changed

+36
-21
lines changed

src/docker/local.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ pub(crate) fn run(
4646

4747
docker.arg("--rm");
4848

49-
docker_seccomp(&mut docker, engine.kind, target, metadata)?;
49+
docker_seccomp(&mut docker, engine.kind, target, metadata)
50+
.wrap_err("when copying seccomp profile")?;
5051
docker_user_id(&mut docker, engine.kind);
5152

5253
docker

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: 31 additions & 19 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;
@@ -114,7 +116,6 @@ fn create_volume_dir(
114116
.arg(container)
115117
.args(&["sh", "-c", &format!("mkdir -p '{}'", dir.as_posix()?)])
116118
.run_and_get_status(msg_info, false)
117-
.map_err(Into::into)
118119
}
119120

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

136136
fn is_cachedir_tag(path: &Path) -> Result<bool> {
@@ -223,9 +223,15 @@ pub fn copy_volume_container_cargo(
223223
} else {
224224
// can copy a limit subset of files: the rest is present.
225225
create_volume_dir(engine, container, &dst, msg_info)?;
226-
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+
{
227229
let file = entry?;
228-
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();
229235
if !basename.starts_with('.') && !matches!(basename.as_ref(), "git" | "registry") {
230236
copy_volume_files(engine, container, &file.path(), &dst, msg_info)?;
231237
}
@@ -248,7 +254,7 @@ where
248254
{
249255
let mut had_symlinks = false;
250256

251-
for entry in fs::read_dir(src)? {
257+
for entry in fs::read_dir(src).wrap_err_with(|| format!("when reading directory {src:?}"))? {
252258
let file = entry?;
253259
if skip(&file, depth) {
254260
continue;
@@ -257,7 +263,8 @@ where
257263
let src_path = file.path();
258264
let dst_path = dst.join(file.file_name());
259265
if file.file_type()?.is_file() {
260-
fs::copy(&src_path, &dst_path)?;
266+
fs::copy(&src_path, &dst_path)
267+
.wrap_err_with(|| format!("when copying file {src_path:?} -> {dst_path:?}"))?;
261268
} else if file.file_type()?.is_dir() {
262269
fs::create_dir(&dst_path).ok();
263270
had_symlinks = copy_dir(&src_path, &dst_path, copy_symlinks, depth + 1, skip)?;
@@ -604,7 +611,6 @@ rm \"{PATH}\"
604611
.arg(container)
605612
.args(&["sh", "-c", &script.join("\n")])
606613
.run_and_get_status(msg_info, true)
607-
.map_err(Into::into)
608614
}
609615

610616
fn copy_volume_container_project(
@@ -657,7 +663,6 @@ fn run_and_get_status(engine: &Engine, args: &[&str], msg_info: MessageInfo) ->
657663
command(engine)
658664
.args(args)
659665
.run_and_get_status(msg_info, true)
660-
.map_err(Into::into)
661666
}
662667

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

679683
pub fn container_stop(
@@ -805,7 +809,7 @@ pub(crate) fn run(
805809

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

@@ -825,9 +829,11 @@ pub(crate) fn run(
825829
cwd,
826830
|_, val| mount_path(val),
827831
|(src, dst)| volumes.push((src, dst)),
828-
)?;
832+
)
833+
.wrap_err("could not determine mount points")?;
829834

830-
docker_seccomp(&mut docker, engine.kind, target, metadata)?;
835+
docker_seccomp(&mut docker, engine.kind, target, metadata)
836+
.wrap_err("when copying seccomp profile")?;
831837

832838
// Prevent `bin` from being mounted inside the Docker container.
833839
docker.args(&["-v", &format!("{mount_prefix}/cargo/bin")]);
@@ -871,15 +877,17 @@ pub(crate) fn run(
871877
target,
872878
mount_prefix_path,
873879
msg_info,
874-
)?;
880+
)
881+
.wrap_err("when copying xargo")?;
875882
copy_volume_container_cargo(
876883
engine,
877884
&container,
878885
&dirs.cargo,
879886
mount_prefix_path,
880887
false,
881888
msg_info,
882-
)?;
889+
)
890+
.wrap_err("when copying cargo")?;
883891
copy_volume_container_rust(
884892
engine,
885893
&container,
@@ -888,7 +896,8 @@ pub(crate) fn run(
888896
mount_prefix_path,
889897
false,
890898
msg_info,
891-
)?;
899+
)
900+
.wrap_err("when copying rust")?;
892901
} else {
893902
// need to copy over the target triple if it hasn't been previously copied
894903
copy_volume_container_rust_triple(
@@ -899,14 +908,16 @@ pub(crate) fn run(
899908
mount_prefix_path,
900909
true,
901910
msg_info,
902-
)?;
911+
)
912+
.wrap_err("when copying rust target files")?;
903913
}
904914
let mount_root = if mount_volumes {
905915
// cannot panic: absolute unix path, must have root
906916
let rel_mount_root = dirs.mount_root.strip_prefix('/').unwrap();
907917
let mount_root = mount_prefix_path.join(rel_mount_root);
908918
if !rel_mount_root.is_empty() {
909-
create_volume_dir(engine, &container, mount_root.parent().unwrap(), msg_info)?;
919+
create_volume_dir(engine, &container, mount_root.parent().unwrap(), msg_info)
920+
.wrap_err("when creating mount root")?;
910921
}
911922
mount_root
912923
} else {
@@ -920,7 +931,8 @@ pub(crate) fn run(
920931
&volume,
921932
copy_cache,
922933
msg_info,
923-
)?;
934+
)
935+
.wrap_err("when copying project")?;
924936

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

10341046
// 6. execute our cargo command inside the container
10351047
let mut docker = subcommand(engine, "exec");

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("could not run container")?;
522523
let needs_host = args
523524
.subcommand
524525
.map(|sc| sc.needs_host(is_remote))

0 commit comments

Comments
 (0)