[naga] Include path in HLSL validation error messages. (#10404)

This commit is contained in:
Jim Blandy authored and GitHub committed 2026-09-25 05:12:39 +00:00
1 parent 7c8eee4744
commit d8548d5991
1 file changed
+29 -11
+29 -11
View File
@@ -1,20 +1,27 @@
use std::{error::Error, fmt::Display, fs, io, path::Path};
use std::{error::Error, fmt::Display, fs, io, path::Path, path::PathBuf};
use anyhow::{anyhow, ensure};
use anyhow::anyhow;
use nanoserde::{self, DeRon, DeRonErr, SerRon};
#[derive(Debug)]
struct BadRonParse(BadRonParseKind);
struct BadRonParse {
path: PathBuf,
kind: BadRonParseKind,
}
impl Display for BadRonParse {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "failed to read RON configuration of HLSL snapshot test")
write!(
f,
"failed to read HLSL snapshot test RON configuration file `{}`",
self.path.display()
)
}
}
impl Error for BadRonParse {
fn source(&self) -> Option<&(dyn Error + 'static)> {
Some(&self.0)
Some(&self.kind)
}
}
@@ -68,12 +75,23 @@ impl Config {
pub fn from_path(path: impl AsRef<Path>) -> anyhow::Result<Config> {
let path = path.as_ref();
let raw_config = fs::read_to_string(path)
.map_err(|source| BadRonParse(BadRonParseKind::Read { source }))?;
let config = Config::deserialize_ron(&raw_config)
.map_err(|source| BadRonParse(BadRonParseKind::Parse { source }))?;
ensure!(!config.is_empty(), BadRonParse(BadRonParseKind::Empty));
Ok(config)
(|| -> Result<Config, BadRonParseKind> {
let raw_config =
fs::read_to_string(path).map_err(|source| BadRonParseKind::Read { source })?;
let config = Config::deserialize_ron(&raw_config)
.map_err(|source| BadRonParseKind::Parse { source })?;
if config.is_empty() {
return Err(BadRonParseKind::Empty);
}
Ok(config)
})()
.map_err(|kind| {
BadRonParse {
path: path.to_owned(),
kind,
}
.into()
})
}
pub fn to_file(&self, path: impl AsRef<Path>) -> anyhow::Result<()> {