|
1 | 1 | use crate::{Compile, LanguageMethods, Runner, Verify}; |
2 | | -use anyhow::Result; |
| 2 | +use anyhow::{Context as _, Result}; |
3 | 3 | use std::env; |
4 | 4 | use std::fs; |
5 | 5 | use std::path::{Path, PathBuf}; |
@@ -63,14 +63,15 @@ impl LanguageMethods for Go { |
63 | 63 | // convention. For example, if the filename is `test.go`, then we'll |
64 | 64 | // also include `${prefix}+test.go` for any value of `${prefix}`. |
65 | 65 | for path in all_paths(&compile.component.path)? { |
66 | | - let test = fs::read_to_string(&path)?; |
| 66 | + let test = fs::read_to_string(&path) |
| 67 | + .with_context(|| format!("unable to read `{}`", path.display()))?; |
67 | 68 | let package_name = package_name(&test); |
68 | 69 | let package_dir = compile.bindings_dir.join(package_name); |
69 | | - fs::create_dir_all(&package_dir)?; |
70 | | - fs::write( |
71 | | - &package_dir.join(path.file_name().unwrap()), |
72 | | - test.as_bytes(), |
73 | | - )?; |
| 70 | + fs::create_dir_all(&package_dir) |
| 71 | + .with_context(|| format!("unable to create `{}`", package_dir.display()))?; |
| 72 | + let output = &package_dir.join(path.file_name().unwrap()); |
| 73 | + fs::write(output, test.as_bytes()) |
| 74 | + .with_context(|| format!("unable to write `{}`", output.display()))?; |
74 | 75 | } |
75 | 76 |
|
76 | 77 | runner.run_command( |
@@ -124,7 +125,11 @@ fn all_paths(path: &Path) -> Result<Vec<PathBuf>> { |
124 | 125 | .and_then(|name| name.strip_suffix(suffix)) |
125 | 126 | { |
126 | 127 | let suffix = &format!("+{name}{suffix}"); |
127 | | - for entry in path.parent().unwrap().read_dir()? { |
| 128 | + let parent = path.parent().unwrap(); |
| 129 | + for entry in parent |
| 130 | + .read_dir() |
| 131 | + .with_context(|| format!("unable to read dir `{}`", parent.display()))? |
| 132 | + { |
128 | 133 | let entry = entry?; |
129 | 134 | if entry |
130 | 135 | .file_name() |
|
0 commit comments