fyrox_impl/resource/fbx/error.rs
1// Copyright (c) 2019-present Dmitry Stepanov and Fyrox Engine contributors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in all
11// copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19// SOFTWARE.
20
21//! Contains all possible errors that can occur during FBX parsing and conversion.
22
23use crate::core::io::FileLoadError;
24use std::fmt::{Display, Formatter};
25
26/// See module docs.
27#[derive(Debug)]
28pub enum FbxError {
29 /// An input/output error has occurred (unexpected end of file, etc.)
30 Io(std::io::Error),
31
32 /// Type of attribute is unknown or not supported.
33 UnknownAttributeType(u8),
34
35 /// Corrupted null record of binary FBX.
36 InvalidNullRecord,
37
38 /// A string has invalid content (non UTF8-compliant)
39 InvalidString,
40
41 /// Arbitrary error that can have any meaning.
42 Custom(Box<String>),
43
44 /// Version is not supported.
45 UnsupportedVersion(i32),
46
47 /// Internal handle is invalid.
48 InvalidPoolHandle,
49
50 /// Attempt to "cast" enum to unexpected variant.
51 UnexpectedType,
52
53 /// Internal error that means some index was out of bounds. Probably a bug in implementation.
54 IndexOutOfBounds,
55
56 /// Vertex references non existing bone.
57 UnableToFindBone,
58
59 /// There is no corresponding scene node for a FBX model.
60 UnableToRemapModelToNode,
61
62 /// Unknown or unsupported mapping.
63 InvalidMapping,
64
65 /// Unknown or unsupported reference.
66 InvalidReference,
67
68 /// An error occurred during file loading.
69 FileLoadError(FileLoadError),
70}
71
72impl Display for FbxError {
73 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
74 match self {
75 FbxError::Io(v) => {
76 write!(f, "FBX: Io error: {v}")
77 }
78 FbxError::UnknownAttributeType(v) => {
79 write!(f, "FBX: Unknown or unsupported attribute type {v}")
80 }
81 FbxError::InvalidNullRecord => {
82 write!(f, "FBX: Corrupted null record of binary FBX")
83 }
84 FbxError::InvalidString => {
85 write!(f, "FBX: A string has invalid content (non UTF8-compliant)")
86 }
87 FbxError::Custom(v) => {
88 write!(f, "FBX: An error has occurred: {v}")
89 }
90 FbxError::UnsupportedVersion(v) => {
91 write!(f, "FBX: Version is not supported: {v}")
92 }
93 FbxError::InvalidPoolHandle => {
94 write!(f, "FBX: Internal handle is invalid.")
95 }
96 FbxError::UnexpectedType => {
97 write!(f, "FBX: Internal invalid cast.")
98 }
99 FbxError::IndexOutOfBounds => {
100 write!(f, "FBX: Index is out-of-bounds.")
101 }
102 FbxError::UnableToFindBone => {
103 write!(f, "FBX: Vertex references non existing bone.")
104 }
105 FbxError::UnableToRemapModelToNode => {
106 write!(
107 f,
108 "FBX: There is no corresponding scene node for a FBX model."
109 )
110 }
111 FbxError::InvalidMapping => {
112 write!(f, "FBX: Unknown or unsupported mapping.")
113 }
114 FbxError::InvalidReference => {
115 write!(f, "FBX: Unknown or unsupported reference.")
116 }
117 FbxError::FileLoadError(v) => {
118 write!(f, "FBX: File load error {v:?}.")
119 }
120 }
121 }
122}
123
124impl From<FileLoadError> for FbxError {
125 fn from(err: FileLoadError) -> Self {
126 FbxError::FileLoadError(err)
127 }
128}
129
130impl From<std::io::Error> for FbxError {
131 fn from(err: std::io::Error) -> Self {
132 FbxError::Io(err)
133 }
134}
135
136impl From<String> for FbxError {
137 fn from(err: String) -> Self {
138 FbxError::Custom(Box::new(err))
139 }
140}
141
142impl From<std::string::FromUtf8Error> for FbxError {
143 fn from(_: std::string::FromUtf8Error) -> Self {
144 FbxError::InvalidString
145 }
146}