Skip to main content

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::FileError;
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(FileError),
70}
71
72impl std::error::Error for FbxError {}
73
74impl Display for FbxError {
75    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
76        match self {
77            FbxError::Io(v) => {
78                write!(f, "FBX: Io error: {v}")
79            }
80            FbxError::UnknownAttributeType(v) => {
81                write!(f, "FBX: Unknown or unsupported attribute type {v}")
82            }
83            FbxError::InvalidNullRecord => {
84                write!(f, "FBX: Corrupted null record of binary FBX")
85            }
86            FbxError::InvalidString => {
87                write!(f, "FBX: A string has invalid content (non UTF8-compliant)")
88            }
89            FbxError::Custom(v) => {
90                write!(f, "FBX: An error has occurred: {v}")
91            }
92            FbxError::UnsupportedVersion(v) => {
93                write!(f, "FBX: Version is not supported: {v}")
94            }
95            FbxError::InvalidPoolHandle => {
96                write!(f, "FBX: Internal handle is invalid.")
97            }
98            FbxError::UnexpectedType => {
99                write!(f, "FBX: Internal invalid cast.")
100            }
101            FbxError::IndexOutOfBounds => {
102                write!(f, "FBX: Index is out-of-bounds.")
103            }
104            FbxError::UnableToFindBone => {
105                write!(f, "FBX: Vertex references non existing bone.")
106            }
107            FbxError::UnableToRemapModelToNode => {
108                write!(
109                    f,
110                    "FBX: There is no corresponding scene node for a FBX model."
111                )
112            }
113            FbxError::InvalidMapping => {
114                write!(f, "FBX: Unknown or unsupported mapping.")
115            }
116            FbxError::InvalidReference => {
117                write!(f, "FBX: Unknown or unsupported reference.")
118            }
119            FbxError::FileLoadError(v) => {
120                write!(f, "FBX: File load error {v:?}.")
121            }
122        }
123    }
124}
125
126impl From<FileError> for FbxError {
127    fn from(err: FileError) -> Self {
128        FbxError::FileLoadError(err)
129    }
130}
131
132impl From<std::io::Error> for FbxError {
133    fn from(err: std::io::Error) -> Self {
134        FbxError::Io(err)
135    }
136}
137
138impl From<String> for FbxError {
139    fn from(err: String) -> Self {
140        FbxError::Custom(Box::new(err))
141    }
142}
143
144impl From<std::string::FromUtf8Error> for FbxError {
145    fn from(_: std::string::FromUtf8Error) -> Self {
146        FbxError::InvalidString
147    }
148}