Skip to content

Commit 39ab3f1

Browse files
committed
add some more context to error messages
1 parent 5a55c2e commit 39ab3f1

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
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 & 18 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,7 @@ 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)
134+
.map(Into::into)
134135
}
135136

136137
fn is_cachedir_tag(path: &Path) -> Result<bool> {
@@ -223,9 +224,15 @@ pub fn copy_volume_container_cargo(
223224
} else {
224225
// can copy a limit subset of files: the rest is present.
225226
create_volume_dir(engine, container, &dst, msg_info)?;
226-
for entry in fs::read_dir(cargo_dir)? {
227+
for entry in fs::read_dir(cargo_dir)
228+
.wrap_err_with(|| format!("when reading directory {cargo_dir:?}"))?
229+
{
227230
let file = entry?;
228-
let basename = file.file_name().to_utf8()?.to_string();
231+
let basename = file
232+
.file_name()
233+
.to_utf8()
234+
.wrap_err_with(|| format!("when reading file {file:?}"))?
235+
.to_string();
229236
if !basename.starts_with('.') && !matches!(basename.as_ref(), "git" | "registry") {
230237
copy_volume_files(engine, container, &file.path(), &dst, msg_info)?;
231238
}
@@ -248,7 +255,7 @@ where
248255
{
249256
let mut had_symlinks = false;
250257

251-
for entry in fs::read_dir(src)? {
258+
for entry in fs::read_dir(src).wrap_err_with(|| format!("when reading directory {src:?}"))? {
252259
let file = entry?;
253260
if skip(&file, depth) {
254261
continue;
@@ -257,7 +264,8 @@ where
257264
let src_path = file.path();
258265
let dst_path = dst.join(file.file_name());
259266
if file.file_type()?.is_file() {
260-
fs::copy(&src_path, &dst_path)?;
267+
fs::copy(&src_path, &dst_path)
268+
.wrap_err_with(|| format!("when copying file {src_path:?} -> {dst_path:?}"))?;
261269
} else if file.file_type()?.is_dir() {
262270
fs::create_dir(&dst_path).ok();
263271
had_symlinks = copy_dir(&src_path, &dst_path, copy_symlinks, depth + 1, skip)?;
@@ -604,7 +612,6 @@ rm \"{PATH}\"
604612
.arg(container)
605613
.args(&["sh", "-c", &script.join("\n")])
606614
.run_and_get_status(msg_info, true)
607-
.map_err(Into::into)
608615
}
609616

610617
fn copy_volume_container_project(
@@ -657,7 +664,6 @@ fn run_and_get_status(engine: &Engine, args: &[&str], msg_info: MessageInfo) ->
657664
command(engine)
658665
.args(args)
659666
.run_and_get_status(msg_info, true)
660-
.map_err(Into::into)
661667
}
662668

663669
pub fn volume_create(engine: &Engine, volume: &str, msg_info: MessageInfo) -> Result<ExitStatus> {
@@ -673,7 +679,6 @@ pub fn volume_exists(engine: &Engine, volume: &str, msg_info: MessageInfo) -> Re
673679
.args(&["volume", "inspect", volume])
674680
.run_and_get_output(msg_info)
675681
.map(|output| output.status.success())
676-
.map_err(Into::into)
677682
}
678683

679684
pub fn container_stop(
@@ -805,7 +810,7 @@ pub(crate) fn run(
805810

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

@@ -825,9 +830,11 @@ pub(crate) fn run(
825830
cwd,
826831
|_, val| mount_path(val),
827832
|(src, dst)| volumes.push((src, dst)),
828-
)?;
833+
)
834+
.wrap_err("could not determine mount points")?;
829835

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

832839
// Prevent `bin` from being mounted inside the Docker container.
833840
docker.args(&["-v", &format!("{mount_prefix}/cargo/bin")]);
@@ -871,15 +878,17 @@ pub(crate) fn run(
871878
target,
872879
mount_prefix_path,
873880
msg_info,
874-
)?;
881+
)
882+
.wrap_err("when copying xargo")?;
875883
copy_volume_container_cargo(
876884
engine,
877885
&container,
878886
&dirs.cargo,
879887
mount_prefix_path,
880888
false,
881889
msg_info,
882-
)?;
890+
)
891+
.wrap_err("when copying cargo")?;
883892
copy_volume_container_rust(
884893
engine,
885894
&container,
@@ -888,7 +897,8 @@ pub(crate) fn run(
888897
mount_prefix_path,
889898
false,
890899
msg_info,
891-
)?;
900+
)
901+
.wrap_err("when copying rust")?;
892902
} else {
893903
// need to copy over the target triple if it hasn't been previously copied
894904
copy_volume_container_rust_triple(
@@ -899,14 +909,16 @@ pub(crate) fn run(
899909
mount_prefix_path,
900910
true,
901911
msg_info,
902-
)?;
912+
)
913+
.wrap_err("when copying rust target files")?;
903914
}
904915
let mount_root = if mount_volumes {
905916
// cannot panic: absolute unix path, must have root
906917
let rel_mount_root = dirs.mount_root.strip_prefix('/').unwrap();
907918
let mount_root = mount_prefix_path.join(rel_mount_root);
908919
if !rel_mount_root.is_empty() {
909-
create_volume_dir(engine, &container, mount_root.parent().unwrap(), msg_info)?;
920+
create_volume_dir(engine, &container, mount_root.parent().unwrap(), msg_info)
921+
.wrap_err("when creating mount root")?;
910922
}
911923
mount_root
912924
} else {
@@ -920,7 +932,8 @@ pub(crate) fn run(
920932
&volume,
921933
copy_cache,
922934
msg_info,
923-
)?;
935+
)
936+
.wrap_err("when copying project")?;
924937

925938
let mut copied = vec![
926939
(&dirs.xargo, mount_prefix_path.join("xargo")),

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)