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,7 +464,9 @@ 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() | ||||||
|  |                     .with_message(error.to_string()) | ||||||
|  |                     .with_labels( | ||||||
|                         error |                         error | ||||||
|                             .spans() |                             .spans() | ||||||
|                             .map(|(span, desc)| { |                             .map(|(span, desc)| { | ||||||
| @ -472,6 +474,11 @@ fn log_shader_error(source: &ProcessedShader, error: &AsModuleDescriptorError) { | |||||||
|                                     .with_message(desc.to_owned()) |                                     .with_message(desc.to_owned()) | ||||||
|                             }) |                             }) | ||||||
|                             .collect(), |                             .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
	 Jakob Hellermann
						Jakob Hellermann