Skip to main content

flm_core/stdlib/backends/pieces/
error.rs

1//! This module defines the diagnostic conditions that the pieces stage of a
2//! backend ([`PiecesStage`](super::PiecesStage)) reports.
3
4use techy::error::DiagnosticInfo;
5
6/// The warning that is reported when a piece listed in the setting `include` or
7/// `exclude` of the `pieces` feature is not defined in any feature (id
8/// `flm.pieces.unknown-piece`).
9///
10/// The settings `include` and `exclude` are the fields of
11/// [`PiecesRenderOptions`](super::PiecesRenderOptions). They accept the names
12/// of the pieces declared in the registry
13/// ([`declared_pieces`](super::declared_pieces)), as in
14/// `pieces.include=[flm.toc]`.
15///
16/// Reported by the pieces stage of each backend when it runs. The unknown name
17/// is ignored, and the output is the same as without it.
18#[derive(Debug, Clone, PartialEq, Eq, DiagnosticInfo)]
19#[diagnostic(
20    id = "flm.pieces.unknown-piece",
21    message = "Unknown piece ‘{piece}’ in setting ‘pieces.include’ or \
22               ‘pieces.exclude’"
23)]
24pub struct UnknownPiece {
25    /// The piece name, as written in the setting.
26    pub piece: String,
27}
28
29/// The error that is reported when a piece cannot be rendered for a backend
30/// (id `flm.pieces.lowering-failed`).
31///
32/// The pieces stage of a backend renders a piece in two steps. First, it
33/// brings the content of the piece up to date ([value
34/// catch-up](crate::guide::concepts_overview#value-catch-up)). Then, it lowers
35/// the content with the lowering rules selected for the backend. Either step
36/// can fail. For instance, no label may be defined in the content of a piece.
37/// If a label is defined there, the first step fails.
38///
39/// Reported by the pieces stage of the backend when it runs, once for each
40/// piece that fails. The piece is left out of the output of this backend, and
41/// the rest of the document is written. The diagnostics that describe the
42/// cause of the failure, if any, are reported as well.
43#[derive(Debug, Clone, PartialEq, Eq, DiagnosticInfo)]
44#[diagnostic(
45    id = "flm.pieces.lowering-failed",
46    message = "Failed to render piece ‘{piece}’ for backend \
47               ‘{backend}’: {detail}"
48)]
49pub struct PieceLoweringFailed {
50    /// The name of the piece.
51    pub piece: String,
52    /// The name of the backend.
53    pub backend: String,
54    /// A description of the cause of the failure.
55    pub detail: String,
56}