Skip to main content

typst_bake/
error.rs

1//! Error types for typst-bake.
2
3use thiserror::Error;
4
5/// Errors that can occur during document compilation and rendering.
6#[derive(Error, Debug)]
7pub enum Error {
8    /// Entry file was not found in the embedded templates.
9    #[error("entry file not found: {0}")]
10    EntryNotFound(&'static str),
11
12    /// Entry file content is not valid UTF-8.
13    #[error("entry file is not valid UTF-8")]
14    InvalidUtf8,
15
16    /// Typst compilation failed.
17    #[error("compilation failed:\n{0}")]
18    Compilation(String),
19
20    /// PDF generation failed.
21    #[error("PDF generation failed: {0}")]
22    PdfGeneration(String),
23
24    /// PNG encoding failed.
25    #[error("PNG encoding failed: {0}")]
26    PngEncoding(String),
27
28    /// Invalid file path provided for runtime file injection.
29    #[error("invalid file path: {0}")]
30    InvalidFilePath(String),
31
32    /// Invalid page selection (empty or out of range).
33    #[error("invalid page selection: {0}")]
34    InvalidPageSelection(String),
35
36    /// Decompression of embedded content failed.
37    #[error("decompression failed")]
38    Decompression(#[from] std::io::Error),
39}
40
41/// A specialized Result type for typst-bake operations.
42pub type Result<T> = std::result::Result<T, Error>;