semantic_scene/error.rs
1//! Error types returned by parsers and loaders.
2use thiserror::Error;
3
4/// Error returned while parsing one descriptor record.
5#[derive(Debug, Error)]
6pub enum ParseError {
7 /// A required whitespace-delimited field was absent.
8 #[error("missing field {field}")]
9 MissingField {
10 /// Zero-based field index in the record.
11 field: usize,
12 },
13 /// A field existed but could not be parsed as the expected type.
14 #[error("bad field {field}: {value}")]
15 BadField {
16 /// Zero-based field index in the record.
17 field: usize,
18 /// Original field text.
19 value: String,
20 },
21 /// The record shape is not valid for its tag.
22 #[error("bad line: {0}")]
23 BadLine(String),
24}
25
26/// Error returned while loading and validating a semantic scene descriptor.
27#[derive(Debug, Error)]
28pub enum LoadError {
29 /// The descriptor could not be read.
30 #[error(transparent)]
31 Io(#[from] std::io::Error),
32 /// The file header is not supported by the selected loader.
33 #[error("bad MP3D house header: {found}")]
34 BadHeader {
35 /// Header text found in the file.
36 found: String,
37 },
38 /// A line failed to parse.
39 #[error("parse error on line {line_number}: {source}; line: {line}")]
40 ParseLine {
41 /// One-based line number in the source file.
42 line_number: usize,
43 /// Original line text.
44 line: String,
45 /// Structured parse failure.
46 source: ParseError,
47 },
48 /// A record referenced a parent record that does not exist.
49 #[error("missing {kind} parent index {index} on line {line_number}")]
50 MissingParent {
51 /// One-based line number in the source file.
52 line_number: usize,
53 /// Parent kind, such as `level`, `region`, or `object`.
54 kind: &'static str,
55 /// Source-format parent index.
56 index: i32,
57 },
58 /// An object referenced a category that does not exist.
59 #[error("missing category index {index} on line {line_number}")]
60 MissingCategory {
61 /// One-based line number in the source file.
62 line_number: usize,
63 /// Source-format category index.
64 index: i32,
65 },
66 /// Two segment records used the same semantic segment id.
67 #[error("duplicate semantic segment id {segment_id} on line {line_number}")]
68 DuplicateSegmentId {
69 /// One-based line number in the source file.
70 line_number: usize,
71 /// Duplicate semantic mesh segment id.
72 segment_id: i32,
73 },
74 /// The loader option is recognized but not implemented yet.
75 #[error("unsupported option: {0}")]
76 UnsupportedOption(&'static str),
77}