webserver_base/templates/
error.rs1use std::path::PathBuf;
4
5use handlebars::{RenderError, TemplateError as HandlebarsTemplateError};
6
7#[derive(Debug, thiserror::Error)]
9pub enum TemplateError {
10 #[error("failed to read template directory `{path}`")]
12 ReadDirectory {
13 path: PathBuf,
14 #[source]
15 source: std::io::Error,
16 },
17
18 #[error(
20 "`{path}` shadows the built-in `{name}` layout, which webserver-base \
21 embeds and every page extends. Rename it — a project may add any other \
22 layout, just not this one."
23 )]
24 ReservedName { name: &'static str, path: PathBuf },
25
26 #[error(
28 "the helper `{name}` is already defined by webserver-base or Handlebars. \
29 Rename the project's helper; if several projects need the same one, \
30 it belongs in the library."
31 )]
32 ReservedHelper { name: String },
33
34 #[error(
36 "`{path}` contains no `.hbs` pages. A frontend must serve at least one \
37 page; add `html/pages/home.hbs`."
38 )]
39 NoPages { path: PathBuf },
40
41 #[error(
43 "`{path}` is missing. Every frontend serves a 404 with a real 404 \
44 status, so the library declares and routes it — but the page itself \
45 is yours to design."
46 )]
47 MissingNotFoundPage { path: PathBuf },
48
49 #[error("failed to compile template `{name}`")]
51 Compile {
52 name: String,
53 #[source]
54 source: Box<HandlebarsTemplateError>,
55 },
56
57 #[error("failed to render template `{name}`")]
60 Render {
61 name: String,
62 #[source]
63 source: Box<RenderError>,
64 },
65
66 #[error("failed to serialize the JSON-LD document for page `{page}`")]
68 JsonLd {
69 page: String,
70 #[source]
71 source: serde_json::Error,
72 },
73
74 #[error("failed to serialize template data for page `{page}`")]
76 Serialize {
77 page: String,
78 #[source]
79 source: serde_json::Error,
80 },
81}