serde_hkx_features/
error.rs

1//! `serde_hkx_features`'s errors
2use std::{io, path::PathBuf};
3
4/// Cli error
5#[allow(clippy::enum_variant_names)]
6#[derive(Debug, snafu::Snafu)]
7#[snafu(visibility(pub))]
8pub enum Error {
9    /// The only supported extension is `.hkx` or `.xml`. But this path is neither: {path}.
10    #[cfg(not(feature = "extra_fmt"))]
11    #[snafu(display("The only supported extension is `.hkx` or `.xml`. But this path is neither: {}.", path.display()))]
12    UnsupportedExtensionPath { path: PathBuf },
13    #[cfg(feature = "extra_fmt")]
14    /// The only supported extension is  `.hkx`, `.xml`, `.json`, `yaml`. But this path is neither: {path}.
15    #[snafu(display("The only supported extension is `.hkx`, `.xml`, `.json`, `yaml`. But this path is neither: {}.", path.display()))]
16    UnsupportedExtensionPath { path: PathBuf },
17
18    /// The only supported extension is `.hkx` or `.xml`. But this is neither: {ext}.
19    #[cfg(not(feature = "extra_fmt"))]
20    UnsupportedExtension { ext: String },
21    #[cfg(feature = "extra_fmt")]
22    /// The only supported extension is  `.hkx`, `.xml`, `.json`, `.toml`, `.yaml`. But this is neither: {ext}.
23    UnsupportedExtension { ext: String },
24
25    /// This path has a missing extension.
26    #[snafu(display("This path has a missing extension.: {}.", path.display()))]
27    MissingExtension { path: PathBuf },
28
29    /// Failed to read file from
30    #[snafu(display("{source}: {}", path.display()))]
31    FailedReadFile { source: io::Error, path: PathBuf },
32
33    /// Please specify the output path.(OS cannot output bytes as stdout.)
34    InvalidStdout,
35
36    /// hkx conversion error
37    #[snafu(display("Failed to convert the following paths (error count: {}/{total_files}) in {}: \n{err_paths:#?}", err_paths.len(), path.display()))]
38    FailedConvertFiles {
39        path: PathBuf,
40        total_files: usize,
41        err_paths: Vec<PathBuf>,
42    },
43
44    /// Reproduce file error
45    #[snafu(display("Failed to reproduce (-: input / +: output) {}: \n{diff}", path.display()))]
46    FailedReproduceFile { path: PathBuf, diff: String },
47
48    /// hkx reproduce error
49    #[snafu(display("Failed to reproduce the following paths (error count: {}/{total_files}) in {}: \n{err_paths:#?}", err_paths.len(), path.display()))]
50    FailedReproduceFiles {
51        path: PathBuf,
52        total_files: usize,
53        err_paths: Vec<PathBuf>,
54    },
55
56    /// Serialize error
57    #[snafu(display("{}:\n {source}", input.display()))]
58    SerError {
59        input: PathBuf,
60        source: serde_hkx::errors::ser::Error,
61    },
62
63    /// Deserialize error
64    #[snafu(display("{}:\n {source}", input.display()))]
65    DeError {
66        input: PathBuf,
67        source: serde_hkx::errors::de::Error,
68    },
69
70    /// Standard io error
71    #[snafu(transparent)]
72    IoError { source: std::io::Error },
73
74    /// dir strip error
75    #[snafu(transparent)]
76    StripPrefixError { source: std::path::StripPrefixError },
77
78    /// jwalk path error
79    #[snafu(transparent)]
80    JwalkError { source: jwalk::Error },
81
82    /// Tracing log error
83    #[cfg(feature = "tracing")]
84    #[snafu(transparent)]
85    TracingError {
86        source: tracing::subscriber::SetGlobalDefaultError,
87    },
88
89    #[snafu(transparent)]
90    FailedThreadJoin { source: tokio::task::JoinError },
91
92    /// Error when converting from `ClassMap` of String key to `ClassMap` of [`usize`] key.
93    #[snafu(display("Failed to parse key '{key}' into usize"))]
94    KeyParse {
95        key: String,
96        source: std::num::ParseIntError,
97    },
98
99    // Extra formats
100    #[cfg(feature = "extra_fmt")]
101    #[snafu(transparent)]
102    ExtraSerdeError {
103        source: crate::serde_extra::error::ExtraSerdeError,
104    },
105
106    // Extra formats
107    #[cfg(feature = "json_schema")]
108    #[snafu(transparent)]
109    JsonError { source: simd_json::Error },
110}
111
112/// `Result` for `serde_hkx_features` crate.
113pub type Result<T, E = Error> = core::result::Result<T, E>;