Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - include sources in shader validation error #3724

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions crates/bevy_render/src/render_resource/pipeline_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,15 +464,22 @@ fn log_shader_error(source: &ProcessedShader, error: &AsModuleDescriptorError) {
let config = term::Config::default();
let mut writer = term::termcolor::Ansi::new(Vec::new());

let diagnostic = Diagnostic::error().with_labels(
error
.spans()
.map(|(span, desc)| {
Label::primary((), span.to_range().unwrap())
.with_message(desc.to_owned())
})
.collect(),
);
let diagnostic = Diagnostic::error()
.with_message(error.to_string())
.with_labels(
error
.spans()
.map(|(span, desc)| {
Label::primary((), span.to_range().unwrap())
.with_message(desc.to_owned())
})
.collect(),
)
.with_notes(
error_sources(error)
.map(|source| source.to_string())
.collect(),
);

term::emit(&mut writer, &config, &files, &diagnostic).expect("cannot write error");

Expand All @@ -490,3 +497,24 @@ fn log_shader_error(source: &ProcessedShader, error: &AsModuleDescriptorError) {
}
}
}

fn error_sources(
jakobhellermann marked this conversation as resolved.
Show resolved Hide resolved
error: &dyn std::error::Error,
) -> impl Iterator<Item = &(dyn std::error::Error + 'static)> {
ErrorSources {
current: error.source(),
}
}

struct ErrorSources<'a> {
current: Option<&'a (dyn std::error::Error + 'static)>,
}
impl<'a> Iterator for ErrorSources<'a> {
jakobhellermann marked this conversation as resolved.
Show resolved Hide resolved
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
}
}