energyml_export/error.rs
1//! What can go wrong writing geometry out.
2
3use thiserror::Error;
4
5/// The result of an export.
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Everything an exporter refuses to do rather than do wrongly.
9#[derive(Debug, Error)]
10pub enum Error {
11 /// No exporter in the registry writes this format.
12 #[error("no exporter for `{name}` (this build has: {available})")]
13 UnknownFormat {
14 /// What was asked for.
15 name: String,
16 /// What the registry holds, comma separated.
17 available: String,
18 },
19
20 /// The object cannot be written in this format.
21 ///
22 /// A point cloud has no place in a format that only carries triangles, and
23 /// writing an empty file would be worse than saying so.
24 #[error("{format} cannot write {what}")]
25 Unsuitable {
26 /// The format that refused.
27 format: &'static str,
28 /// What it was given.
29 what: String,
30 },
31
32 /// The coordinates could not be put where the format needs them.
33 #[error("{0}")]
34 Placement(String),
35
36 /// Reading the geometry failed.
37 #[error(transparent)]
38 Geometry(#[from] energyml_geometry::Error),
39
40 /// A unit, a coordinate system or a reprojection failed.
41 #[error(transparent)]
42 Domain(#[from] energyml_domain::Error),
43
44 /// Writing failed.
45 #[error(transparent)]
46 Io(#[from] std::io::Error),
47}
48
49impl Error {
50 /// This format cannot represent that.
51 pub fn unsuitable(format: &'static str, what: impl Into<String>) -> Self {
52 Error::Unsuitable {
53 format,
54 what: what.into(),
55 }
56 }
57}