citum_engine/error.rs
1/*
2SPDX-License-Identifier: MIT OR Apache-2.0
3SPDX-FileCopyrightText: © 2023-2026 Bruce D'Arcus and Citum contributors
4*/
5
6use thiserror::Error;
7
8/// Errors produced while resolving or rendering citations and bibliographies.
9#[derive(Error, Debug)]
10pub enum ProcessorError {
11 /// A citation referenced an item ID that is not present in the bibliography.
12 #[error("Reference not found: {0}")]
13 ReferenceNotFound(String),
14
15 /// Date parsing or normalization failed for a reference field.
16 #[error("Date parse error: {0}")]
17 DateParseError(String),
18
19 /// Locale data could not be loaded or did not contain a required term.
20 #[error("Locale error: {0}")]
21 LocaleError(String),
22
23 /// Contributor or title substitution logic failed.
24 #[error("Substitution error: {0}")]
25 SubstitutionError(String),
26
27 /// Reading an input file from disk failed.
28 #[error("File I/O error: {0}")]
29 FileIO(#[from] std::io::Error),
30
31 /// Frontmatter parsing failed for a document input.
32 #[error("Frontmatter parse error: {0}")]
33 FrontmatterParse(String),
34
35 /// Compound-set validation failed for a bibliography input.
36 #[error("Compound set validation error: {0}")]
37 CompoundSetValidation(String),
38
39 /// Parsing a named reference input failed with a message describing the problem.
40 #[error("Parse error ({name}): {message}")]
41 RefsParse {
42 /// Name of the input format or source that failed to parse.
43 name: String,
44 /// Human-readable parser message.
45 message: String,
46 },
47}
48
49impl From<citum_refs::RefsError> for ProcessorError {
50 fn from(e: citum_refs::RefsError) -> Self {
51 match e {
52 citum_refs::RefsError::FileIO(io) => ProcessorError::FileIO(io),
53 citum_refs::RefsError::ParseError(name, message) => {
54 ProcessorError::RefsParse { name, message }
55 }
56 }
57 }
58}