Skip to content

Commit 81e6deb

Browse files
committed
Provide more context for errors while generating an installer
1 parent 5254dbf commit 81e6deb

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/generator.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ impl Generator {
7878

7979
// Copy the overlay
8080
if !self.non_installed_overlay.is_empty() {
81-
copy_recursive(self.non_installed_overlay.as_ref(), &package_dir)?;
81+
copy_recursive(self.non_installed_overlay.as_ref(), &package_dir)
82+
.context("failed to copy overlay")?;
8283
}
8384

8485
// Generate the install script

src/util.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64> {
2828
} else {
2929
let amt = fs::copy(&from, &to).with_context(|| {
3030
format!(
31-
"failed to copy '{}' to '{}'",
31+
"failed to copy '{}' ({}) to '{}' ({}, parent {})",
3232
from.as_ref().display(),
33-
to.as_ref().display()
33+
if from.as_ref().exists() { "exists" } else { "doesn't exist" },
34+
to.as_ref().display(),
35+
if to.as_ref().exists() { "exists" } else { "doesn't exist" },
36+
if to.as_ref().parent().unwrap_or_else(|| Path::new("")).exists() {
37+
"exists"
38+
} else {
39+
"doesn't exist"
40+
},
3441
)
3542
})?;
3643
Ok(amt)
@@ -97,7 +104,20 @@ pub fn remove_file<P: AsRef<Path>>(path: P) -> Result<()> {
97104
/// Copies the `src` directory recursively to `dst`. Both are assumed to exist
98105
/// when this function is called.
99106
pub fn copy_recursive(src: &Path, dst: &Path) -> Result<()> {
100-
copy_with_callback(src, dst, |_, _| Ok(()))
107+
copy_with_callback(src, dst, |_, _| Ok(())).with_context(|| {
108+
format!(
109+
"failed to recursively copy '{}' ({}) to '{}' ({}, parent {})",
110+
src.display(),
111+
if src.exists() { "exists" } else { "doesn't exist" },
112+
dst.display(),
113+
if dst.exists() { "exists" } else { "doesn't exist" },
114+
if dst.parent().unwrap_or_else(|| Path::new("")).exists() {
115+
"exists"
116+
} else {
117+
"doesn't exist"
118+
},
119+
)
120+
})
101121
}
102122

103123
/// Copies the `src` directory recursively to `dst`. Both are assumed to exist

0 commit comments

Comments
 (0)