wasmer_wast/error.rs
1use std::fmt;
2use thiserror::Error;
3
4/// A Directive Error
5#[derive(Debug)]
6pub struct DirectiveError {
7 /// The line where the directive is defined
8 pub line: usize,
9 /// The column where the directive is defined
10 pub col: usize,
11 /// The failing message received when running the directive
12 pub message: String,
13}
14
15/// A structure holding the list of all executed directives
16#[derive(Error, Debug)]
17pub struct DirectiveErrors {
18 /// The filename where the error occured
19 pub filename: String,
20 /// The list of errors
21 pub errors: Vec<DirectiveError>,
22}
23
24impl fmt::Display for DirectiveErrors {
25 // This trait requires `fmt` with this exact signature.
26 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27 // Write strictly the first element into the supplied output
28 // stream: `f`. Returns `fmt::Result` which indicates whether the
29 // operation succeeded or failed. Note that `write!` uses syntax which
30 // is very similar to `println!`.
31 writeln!(f, "Failed directives on {}:", self.filename)?;
32 for error in self.errors.iter() {
33 writeln!(f, " • {} ({}:{})", error.message, error.line, error.col)?;
34 }
35 Ok(())
36 }
37}