assemble_core/project/
error.rs1use crate::__export::TaskId;
4use crate::dependencies::project_dependency::ProjectUrlError;
5use crate::dependencies::AcquisitionError;
6use crate::error::PayloadError;
7use crate::exception::{BuildError, BuildException};
8use crate::identifier::InvalidId;
9use crate::lazy_evaluation;
10use crate::lazy_evaluation::ProviderError;
11use crate::plugins::extensions::ExtensionError;
12use crate::plugins::PluginError;
13use crate::project::finder::{ProjectPathBuf, TaskPath, TaskPathBuf};
14use crate::resources::InvalidResourceLocation;
15use crate::task::flags::{OptionsDecoderError, OptionsSlurperError};
16use crate::workspace::WorkspaceError;
17use std::any::Any;
18use std::convert::Infallible;
19use std::fmt::Display;
20use std::string::FromUtf8Error;
21use std::sync::PoisonError;
22use std::{fmt, io};
23
24#[derive(Debug, thiserror::Error)]
25pub enum ProjectError {
26 #[error("Extension with name {0} not registered")]
27 ExtensionNotRegistered(String),
28 #[error("No task identifier could be found for {0:?}")]
29 NoIdentifiersFound(String),
30 #[error("Too many task identifiers found for {1}. Found {0:?}")]
31 TooManyIdentifiersFound(Vec<TaskId>, String),
32 #[error("Identifier Missing: {0}")]
33 IdentifierMissing(TaskId),
34 #[error("Identifier Missing: {0} (were you looking for {1:?}?)")]
35 IdentifierMissingWithMaybes(TaskId, Vec<TaskId>),
36 #[error("No task could be found for {0:?}")]
37 TaskNotFound(TaskPathBuf),
38 #[error("no project could be found for {0:?}")]
39 ProjectNotFound(ProjectPathBuf),
40 #[error(transparent)]
41 InvalidIdentifier(#[from] InvalidId),
42 #[error(transparent)]
43 PluginError(#[from] PluginError),
44 #[error(transparent)]
45 IoError(#[from] io::Error),
46 #[error("Inner Error {{ ... }}")]
47 SomeError {},
48 #[error("Infallible error occurred")]
49 Infallible(#[from] Infallible),
50 #[error(transparent)]
51 PropertyError(#[from] lazy_evaluation::Error),
52 #[error(transparent)]
53 WorkspaceError(#[from] WorkspaceError),
54 #[error("Invalid Type for file: {0}")]
55 InvalidFileType(String),
56 #[error("RwLock poisoned")]
57 PoisonError,
58 #[error("Actions already queried")]
59 ActionsAlreadyQueried,
60 #[error("No shared project was set")]
61 NoSharedProjectSet,
62 #[error(transparent)]
63 OptionsDecoderError(#[from] OptionsDecoderError),
64 #[error(transparent)]
65 OptionsSlurperError(#[from] OptionsSlurperError),
66 #[error(transparent)]
67 ProjectUrlError(#[from] ProjectUrlError),
68 #[error(transparent)]
69 InvalidResourceLocation(#[from] InvalidResourceLocation),
70 #[error(transparent)]
71 AcquisitionError(#[from] AcquisitionError),
72 #[error("{0}")]
73 CustomError(String),
74 #[error(transparent)]
75 ProviderError(#[from] ProviderError),
76 #[error(transparent)]
77 ExtensionError(#[from] ExtensionError),
78 #[error(transparent)]
79 FromUtf8Error(#[from] FromUtf8Error),
80}
81
82impl<G> From<PoisonError<G>> for ProjectError {
83 fn from(_: PoisonError<G>) -> Self {
84 Self::PoisonError
85 }
86}
87
88impl ProjectError {
89 pub fn invalid_file_type<T>() -> Self {
90 Self::InvalidFileType(std::any::type_name::<T>().to_string())
91 }
92
93 pub fn custom<E: Display + Send + Sync + 'static>(error: E) -> Self {
94 Self::CustomError(error.to_string())
95 }
96}
97
98impl From<Box<dyn Any + Send>> for ProjectError {
99 fn from(_e: Box<dyn Any + Send>) -> Self {
100 Self::SomeError {}
101 }
102}
103
104#[macro_export]
112macro_rules! payload_from {
113 ($from:ty, $ty:ty) => {
114 impl From<$from> for $crate::error::PayloadError<$ty>
115 where
116 $from: Into<$ty>,
117 {
118 fn from(e: $from) -> Self {
119 let err: $ty = e.into();
120 $crate::error::PayloadError::new(err)
121 }
122 }
123 };
124}
125
126payload_from!(InvalidId, ProjectError);
127payload_from!(lazy_evaluation::Error, ProjectError);
128payload_from!(ExtensionError, ProjectError);
129
130impl From<PayloadError<ProjectError>> for PayloadError<BuildException> {
131 fn from(e: PayloadError<ProjectError>) -> Self {
132 e.into()
133 }
134}
135
136pub type Result<T> = std::result::Result<T, PayloadError<ProjectError>>;
137pub type ProjectResult<T = ()> = Result<T>;