1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use std::sync::Arc;
use write_fonts::{read::ReadError, validate::ValidationReport};
use crate::{
parse::{SourceList, SourceLoadError},
Diagnostic,
};
#[derive(Clone, Debug, thiserror::Error)]
pub enum UfoGlyphOrderError {
#[error("No public.glyphOrder key in lib.plist")]
KeyNotSet,
#[error("public.glyphOrder exists, but is not an array of strings")]
Malformed,
}
#[derive(Clone, Debug, thiserror::Error)]
pub enum FontGlyphOrderError {
#[error("Failed to read font data: '{0}'")]
ReadError(
#[from]
#[source]
ReadError,
),
#[error("The post table exists, but did not include all glyph names")]
MissingNames,
}
#[derive(Clone, Debug, thiserror::Error)]
pub enum GlyphOrderError {
#[error("Invalid name '{name}' in glyph order")]
#[allow(missing_docs)]
NameError { name: String },
#[error("The first glyph must be '.notdef'")]
MissingNotDef,
}
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum CompilerError {
#[error("{0}")]
SourceLoad(
#[from]
#[source]
SourceLoadError,
),
#[error("Parsing failed with {} errors\n{0}", .0.messages.len())]
ParseFail(DiagnosticSet),
#[error("Validation failed with {} errors\n{0}", .0.messages.len())]
ValidationFail(DiagnosticSet),
#[error("Compilation failed with {} errors\n{0}", .0.messages.len())]
CompilationFail(DiagnosticSet),
#[error("Binary generation failed: '{0}'")]
WriteFail(#[from] BinaryCompilationError),
}
#[derive(Debug, thiserror::Error)]
#[error("Binary generation failed: '{0}'")]
pub struct BinaryCompilationError(ValidationReport);
#[derive(Clone)]
pub struct DiagnosticSet {
pub(crate) messages: Vec<Diagnostic>,
pub(crate) sources: Arc<SourceList>,
}
impl std::fmt::Display for DiagnosticSet {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let mut first = true;
for err in &self.messages {
if !first {
writeln!(f)?;
}
write!(f, "{}", self.sources.format_diagnostic(err))?;
first = false;
}
Ok(())
}
}
impl std::fmt::Debug for DiagnosticSet {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DiagnosticSet")
.field("messages", &self.messages)
.field("tree", &"ParseTree")
.finish()
}
}
impl From<ValidationReport> for BinaryCompilationError {
fn from(src: ValidationReport) -> BinaryCompilationError {
BinaryCompilationError(src)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn assert_compiler_error_is_send() {
fn send_me_baby<T: Send>() {}
send_me_baby::<CompilerError>();
}
}