1use serde::{self, Deserialize, Serialize};
3use settings_manager::prelude::Error as SettingsError;
4use std::io;
5use std::path::PathBuf;
6use std::result::Result as StdResult;
7use thot_core::result::Error as CoreError;
8
9#[derive(Debug)]
14pub enum SettingsFileError {
15 CouldNotLoad(SettingsError),
16 CouldNotSave(SettingsError),
17}
18
19#[derive(Serialize, Deserialize, Debug)]
20pub enum SettingsValidationError {
21 InvalidSetting,
22}
23
24#[derive(Serialize, Deserialize, Debug)]
29pub enum ProjectError {
30 DuplicatePath(PathBuf),
31 PathNotAProjectRoot(PathBuf),
32 PathNotInProject(PathBuf),
33 PathNotAResource(PathBuf),
34}
35
36#[derive(Serialize, Deserialize, Debug)]
41pub enum ContainerError {
42 InvalidChildPath(PathBuf),
43 PathNotAContainer(PathBuf),
44}
45
46#[derive(Serialize, Deserialize, Debug)]
51pub enum AssetError {
52 PathNotAContainer(PathBuf),
53 FileAlreadyAsset(PathBuf),
54 ContainerNotFound(PathBuf),
55 InvalidPath(PathBuf, String),
56}
57
58#[derive(Serialize, Deserialize, Debug)]
63pub enum UsersError {
64 DuplicateEmail(String),
65 InvalidEmail(String),
66}
67
68#[derive(Debug)]
73pub enum Error {
74 AssetError(AssetError),
75 ContainerError(ContainerError),
76 CoreError(CoreError),
77 ProjectError(ProjectError),
78 SettingsError(SettingsError),
79 SettingsFileError(SettingsFileError),
80 SettingsValidationError(SettingsValidationError),
81 UsersError(UsersError),
82}
83
84impl From<CoreError> for Error {
85 fn from(err: CoreError) -> Self {
86 Error::CoreError(err)
87 }
88}
89
90impl From<SettingsError> for Error {
91 fn from(err: SettingsError) -> Self {
92 Error::SettingsError(err)
93 }
94}
95
96impl From<io::Error> for Error {
97 fn from(err: io::Error) -> Self {
98 Error::CoreError(CoreError::IoError(err))
99 }
100}
101
102impl From<serde_json::Error> for Error {
103 fn from(err: serde_json::Error) -> Self {
104 Error::CoreError(CoreError::SerdeError(err))
105 }
106}
107
108impl Serialize for Error {
110 fn serialize<S>(&self, serializer: S) -> StdResult<S::Ok, S::Error>
111 where
112 S: serde::ser::Serializer,
113 {
114 let msg = format!("{:?}", self);
115 serializer.serialize_str(msg.as_ref())
116 }
117}
118
119pub type Result<T = ()> = StdResult<T, Error>;
124
125impl From<Error> for Result {
126 fn from(err: Error) -> Self {
127 Err(err)
128 }
129}
130
131#[cfg(test)]
132#[path = "./result_test.rs"]
133mod result_test;