Skip to content

Commit 78ccfde

Browse files
committed
spirv-builder: improve metadata error messages
1 parent 6ea9b9c commit 78ccfde

File tree

1 file changed

+13
-12
lines changed
  • crates/spirv-builder/src

1 file changed

+13
-12
lines changed

crates/spirv-builder/src/lib.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ pub enum SpirvBuilderError {
117117
"`multimodule: true` build cannot be used together with `build_script.env_shader_spv_path: true`"
118118
)]
119119
MultiModuleWithEnvShaderSpvPath,
120-
#[error("some metadata file is missing")]
121-
MetadataFileMissing(#[from] std::io::Error),
122-
#[error("unable to parse some metadata file")]
123-
MetadataFileMalformed(#[from] serde_json::Error),
120+
#[error("Metadata files emitted by codegen backend are missing: {0}")]
121+
MetadataFileMissing(std::io::Error),
122+
#[error("Metadata files emitted by codegen backend are invalid json: {0}")]
123+
MetadataFileMalformed(serde_json::Error),
124+
#[error("Couldn't parse rustc dependency files: {0}")]
125+
DepFileParseError(std::io::Error),
124126
#[error(
125127
"`{ARTIFACT_SUFFIX}` artifact not found in (supposedly successful) build output.\n--- build output ---\n{stdout}"
126128
)]
@@ -130,6 +132,8 @@ pub enum SpirvBuilderError {
130132
#[cfg(feature = "watch")]
131133
#[error(transparent)]
132134
WatchFailed(#[from] SpirvWatcherError),
135+
#[error("IO Error: {0}")]
136+
IoError(#[from] std::io::Error),
133137
}
134138

135139
#[derive(Debug, PartialEq, Eq, Clone, Copy, Default, serde::Deserialize, serde::Serialize)]
@@ -758,10 +762,7 @@ impl SpirvBuilder {
758762
rustc_codegen_spirv_types::serde_json::from_reader(BufReader::new(metadata_contents))
759763
.map_err(SpirvBuilderError::MetadataFileMalformed)?;
760764

761-
let is_multimodule = match &metadata.module {
762-
ModuleResult::SingleModule(_) => false,
763-
ModuleResult::MultiModule(_) => true,
764-
};
765+
let is_multimodule = matches!(&metadata.module, ModuleResult::MultiModule(_));
765766
assert_eq!(self.multimodule, is_multimodule);
766767

767768
if self.build_script.get_env_shader_spv_path() {
@@ -1110,8 +1111,7 @@ impl SpirvBuilder {
11101111
let mut deps = Vec::new();
11111112
leaf_deps(&metadata_file, |artifact| {
11121113
deps.push(RawString::from(artifact));
1113-
})
1114-
.map_err(SpirvBuilderError::MetadataFileMissing)?;
1114+
})?;
11151115
Ok(RustcOutput {
11161116
compile_result,
11171117
deps,
@@ -1160,13 +1160,14 @@ fn get_sole_artifact(out: &str) -> Option<PathBuf> {
11601160
}
11611161

11621162
/// Internally iterate through the leaf dependencies of the artifact at `artifact`
1163-
fn leaf_deps(artifact: &Path, mut handle: impl FnMut(&RawStr)) -> std::io::Result<()> {
1163+
fn leaf_deps(artifact: &Path, mut handle: impl FnMut(&RawStr)) -> Result<(), SpirvBuilderError> {
11641164
let deps_file = artifact.with_extension("d");
11651165
let mut deps_map = HashMap::new();
11661166
depfile::read_deps_file(&deps_file, |item, deps| {
11671167
deps_map.insert(item, deps);
11681168
Ok(())
1169-
})?;
1169+
})
1170+
.map_err(|e| SpirvBuilderError::DepFileParseError(e))?;
11701171
fn recurse(
11711172
map: &HashMap<RawString, Vec<RawString>>,
11721173
artifact: &RawStr,

0 commit comments

Comments
 (0)