| 41 | |
| 42 | impl Display for ErrorMessage { |
| 43 | fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
| 44 | // https://github.com/zesterer/ariadne/issues/52 |
| 45 | if let Some(display) = &self.display { |
| 46 | let message_without_trailing_spaces = display |
| 47 | .split('\n') |
| 48 | .map(str::trim_end) |
| 49 | .collect::<Vec<_>>() |
| 50 | .join("\n"); |
| 51 | f.write_str(&message_without_trailing_spaces)?; |
| 52 | } else { |
| 53 | let code = (self.code.as_ref()) |
| 54 | .map(|c| format!("[{c}] ")) |
| 55 | .unwrap_or_default(); |
| 56 | |
| 57 | writeln!(f, "{}Error: {}", code, &self.reason)?; |
| 58 | for hint in &self.hints { |
| 59 | // TODO: consider alternative formatting for hints. |
| 60 | writeln!(f, "↳ Hint: {hint}")?; |
| 61 | } |
| 62 | } |
| 63 | Ok(()) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl Debug for ErrorMessage { |