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
use std::path::PathBuf;
/// A `ctypst` policy, compilation, or export failure.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// A virtual path is not valid in Typst's project namespace.
#[error("invalid virtual Typst path: {0}")]
InvalidVirtualPath(String),
/// The configured filesystem root could not be canonicalized.
#[error("filesystem root does not exist or cannot be resolved: {path}")]
InvalidRoot {
/// Requested filesystem root.
path: PathBuf,
#[source]
/// Canonicalization failure.
source: std::io::Error,
},
/// No supplied bytes contained a valid font face.
#[error("no valid embedded font was provided")]
NoValidFont,
/// One supplied font file contained no valid font face.
#[error("embedded font file {index} contains no valid font face")]
InvalidFont {
/// Zero-based position of the invalid font file.
index: usize,
},
/// A configured finite resource limit was exceeded.
#[error("{resource} exceeds the {limit_name} limit: {actual} > {maximum}")]
Limit {
/// Resource that was rejected.
resource: String,
/// Stable name of the enforced limit.
limit_name: &'static str,
/// Observed resource size or count.
actual: usize,
/// Configured maximum.
maximum: usize,
},
/// Typst could not compile the requested document.
#[error("Typst compilation failed for {document}: {diagnostics}")]
Compile {
/// Requested source path.
document: String,
/// Human-readable Typst diagnostics.
diagnostics: String,
},
/// Typst emitted warnings under the deny-warnings policy.
#[error("Typst emitted warnings for {document}: {diagnostics}")]
Warnings {
/// Requested source path.
document: String,
/// Human-readable Typst diagnostics.
diagnostics: String,
},
/// The rendered page count violated its contract.
#[error("{document} rendered {actual} pages; expected {expected}")]
PageCount {
/// Requested source path.
document: String,
/// Rendered page count.
actual: usize,
/// Human-readable expected count or range.
expected: String,
},
/// A synchronization primitive was poisoned by a panic.
#[error("the embedded Typst engine lock is poisoned")]
Poisoned,
/// Metadata queries require a non-empty label.
#[error("Typst query label is empty")]
EmptyLabel,
/// Typst metadata could not be serialized as JSON.
#[error("Typst metadata query failed: {0}")]
Query(String),
/// A measurement request or response failed validation.
#[error("measurement failed: {0}")]
Measure(String),
#[cfg(feature = "pdf")]
/// The requested deterministic PDF timestamp is outside Typst's range.
#[error("invalid deterministic PDF timestamp {0}")]
Timestamp(i64),
#[cfg(feature = "pdf")]
/// Typst failed to export a PDF.
#[error("Typst PDF export failed: {0}")]
Pdf(String),
/// A zero-based page index was unavailable.
#[error("page {page} is unavailable; document has {pages} pages")]
MissingPage {
/// Requested zero-based page index.
page: usize,
/// Number of pages in the document.
pages: usize,
},
#[cfg(feature = "raster")]
/// Typst produced an invalid or oversized raster buffer.
#[error("Typst raster export failed: {0}")]
Raster(String),
#[cfg(feature = "format")]
/// Typstyle failed to format source text.
#[error("Typst source formatting failed: {0}")]
Format(String),
}
/// Result type used by `ctypst`.
pub type Result<T> = std::result::Result<T, Error>;