include sources in shader validation error (#3724)
## Objective When print shader validation error messages, we didn't print the sources and error message text, which led to some confusing error messages. ```cs error: ┌─ wgsl:15:11 │ 15 │ return material.color + 1u; │ ^^^^^^^^^^^^^^^^^^^^ naga::Expression [11] ``` ## Solution New error message: ```cs error: Entry point fragment at Vertex is invalid ┌─ wgsl:15:11 │ 15 │ return material.color + 1u; │ ^^^^^^^^^^^^^^^^^^^^ naga::Expression [11] │ = Expression [11] is invalid = Operation Add can't work with [8] and [10] ```
This commit is contained in:
parent
aa7b158893
commit
b7dfe1677f
@ -464,15 +464,22 @@ fn log_shader_error(source: &ProcessedShader, error: &AsModuleDescriptorError) {
|
|||||||
let config = term::Config::default();
|
let config = term::Config::default();
|
||||||
let mut writer = term::termcolor::Ansi::new(Vec::new());
|
let mut writer = term::termcolor::Ansi::new(Vec::new());
|
||||||
|
|
||||||
let diagnostic = Diagnostic::error().with_labels(
|
let diagnostic = Diagnostic::error()
|
||||||
error
|
.with_message(error.to_string())
|
||||||
.spans()
|
.with_labels(
|
||||||
.map(|(span, desc)| {
|
error
|
||||||
Label::primary((), span.to_range().unwrap())
|
.spans()
|
||||||
.with_message(desc.to_owned())
|
.map(|(span, desc)| {
|
||||||
})
|
Label::primary((), span.to_range().unwrap())
|
||||||
.collect(),
|
.with_message(desc.to_owned())
|
||||||
);
|
})
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
.with_notes(
|
||||||
|
ErrorSources::of(error)
|
||||||
|
.map(|source| source.to_string())
|
||||||
|
.collect(),
|
||||||
|
);
|
||||||
|
|
||||||
term::emit(&mut writer, &config, &files, &diagnostic).expect("cannot write error");
|
term::emit(&mut writer, &config, &files, &diagnostic).expect("cannot write error");
|
||||||
|
|
||||||
@ -490,3 +497,25 @@ fn log_shader_error(source: &ProcessedShader, error: &AsModuleDescriptorError) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ErrorSources<'a> {
|
||||||
|
current: Option<&'a (dyn std::error::Error + 'static)>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> ErrorSources<'a> {
|
||||||
|
fn of(error: &'a dyn std::error::Error) -> Self {
|
||||||
|
Self {
|
||||||
|
current: error.source(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Iterator for ErrorSources<'a> {
|
||||||
|
type Item = &'a (dyn std::error::Error + 'static);
|
||||||
|
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
let current = self.current;
|
||||||
|
self.current = self.current.and_then(std::error::Error::source);
|
||||||
|
current
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user