Skip to content

Commit b651341

Browse files
committed
spirv-builder: improve metadata error messages
1 parent 894d638 commit b651341

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
@@ -118,10 +118,12 @@ pub enum SpirvBuilderError {
118118
"`multimodule: true` build cannot be used together with `build_script.env_shader_spv_path: true`"
119119
)]
120120
MultiModuleWithEnvShaderSpvPath,
121-
#[error("some metadata file is missing")]
122-
MetadataFileMissing(#[from] std::io::Error),
123-
#[error("unable to parse some metadata file")]
124-
MetadataFileMalformed(#[from] serde_json::Error),
121+
#[error("Metadata file emitted by codegen backend is missing: {0}")]
122+
MetadataFileMissing(std::io::Error),
123+
#[error("Metadata file emitted by codegen backend contains invalid json: {0}")]
124+
MetadataFileMalformed(serde_json::Error),
125+
#[error("Couldn't parse rustc dependency files: {0}")]
126+
DepFileParseError(std::io::Error),
125127
#[error(
126128
"`{ARTIFACT_SUFFIX}` artifact not found in (supposedly successful) build output.\n--- build output ---\n{stdout}"
127129
)]
@@ -131,6 +133,8 @@ pub enum SpirvBuilderError {
131133
#[cfg(feature = "watch")]
132134
#[error(transparent)]
133135
WatchFailed(#[from] SpirvWatcherError),
136+
#[error("IO Error: {0}")]
137+
IoError(#[from] std::io::Error),
134138
}
135139

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

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

768769
if self.build_script.get_env_shader_spv_path() {
@@ -1162,8 +1163,7 @@ impl SpirvBuilder {
11621163
let mut deps = Vec::new();
11631164
leaf_deps(&metadata_file, |artifact| {
11641165
deps.push(RawString::from(artifact));
1165-
})
1166-
.map_err(SpirvBuilderError::MetadataFileMissing)?;
1166+
})?;
11671167
Ok(RustcOutput {
11681168
compile_result,
11691169
deps,
@@ -1212,13 +1212,14 @@ fn get_sole_artifact(out: &str) -> Option<PathBuf> {
12121212
}
12131213

12141214
/// Internally iterate through the leaf dependencies of the artifact at `artifact`
1215-
fn leaf_deps(artifact: &Path, mut handle: impl FnMut(&RawStr)) -> std::io::Result<()> {
1215+
fn leaf_deps(artifact: &Path, mut handle: impl FnMut(&RawStr)) -> Result<(), SpirvBuilderError> {
12161216
let deps_file = artifact.with_extension("d");
12171217
let mut deps_map = HashMap::new();
12181218
depfile::read_deps_file(&deps_file, |item, deps| {
12191219
deps_map.insert(item, deps);
12201220
Ok(())
1221-
})?;
1221+
})
1222+
.map_err(SpirvBuilderError::DepFileParseError)?;
12221223
fn recurse(
12231224
map: &HashMap<RawString, Vec<RawString>>,
12241225
artifact: &RawStr,

0 commit comments

Comments
 (0)