-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathlib.rs
More file actions
179 lines (127 loc) · 5.44 KB
/
lib.rs
File metadata and controls
179 lines (127 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
use std::{ffi::OsString, path::Path, sync::Arc};
use petgraph::graph::NodeIndex;
use thiserror::Error;
use vite_path::{
AbsolutePath, AbsolutePathBuf, RelativePathBuf,
absolute::StripPrefixError,
relative::{FromPathError, InvalidPathDataError},
};
use vite_str::Str;
#[derive(Error, Debug)]
pub enum Error {
#[error(transparent)]
Sqlite(#[from] rusqlite::Error),
#[error(transparent)]
BincodeEncode(#[from] bincode::error::EncodeError),
#[error(transparent)]
BincodeDecode(#[from] bincode::error::DecodeError),
#[error("Unrecognized db version: {0}")]
UnrecognizedDbVersion(u32),
#[error(transparent)]
Io(#[from] std::io::Error),
#[error("IO error: {err} at {path:?}")]
IoWithPath { err: std::io::Error, path: Arc<AbsolutePath> },
#[error(transparent)]
JoinPathsError(#[from] std::env::JoinPathsError),
#[cfg(unix)]
#[error(transparent)]
Nix(#[from] nix::Error),
#[error(transparent)]
Serde(#[from] serde_json::Error),
#[error("Env value is not valid unicode: {key} = {value:?}")]
EnvValueIsNotValidUnicode { key: Str, value: OsString },
#[cfg(unix)]
#[error("Unsupported file type: {0:?}")]
UnsupportedFileType(nix::dir::Type),
#[cfg(windows)]
#[error("Unsupported file type: {0:?}")]
UnsupportedFileType(std::fs::FileType),
#[error(transparent)]
Utf8Error(#[from] bstr::Utf8Error),
#[error(transparent)]
WaxBuild(#[from] wax::BuildError),
#[error(transparent)]
WaxWalk(#[from] wax::WalkError),
#[error("Duplicated task name: {0}")]
DuplicatedTask(Str),
#[error("Duplicated package name: {name} at {path1} and {path2}")]
DuplicatedPackageName { name: Str, path1: RelativePathBuf, path2: RelativePathBuf },
#[error("Circular dependency found : {0:?}")]
CycleDependencies(petgraph::algo::Cycle<NodeIndex>),
#[error("The package.json name is empty at {0:?}/package.json")]
EmptyPackageName(AbsolutePathBuf),
#[error("Package {0} not found in workspace")]
PackageNotFound(Str),
#[error("The package.json file is not found at {0:?}")]
PackageJsonNotFound(AbsolutePathBuf),
#[error("Task '{task_request}' not found in workspace")]
TaskNotFound { task_request: Str },
#[error("Dependency Task '{name}' not found in package located at {package_path}")]
TaskDependencyNotFound { name: Str, package_path: RelativePathBuf },
#[error("{task_request} should not contain multiple '#'")]
AmbiguousTaskRequest { task_request: Str },
#[error("Only one task request is allowed when running in implicit mode: {0}")]
OnlyOneTaskRequest(Str),
#[error("Recursive run is not allowed when task name contains '#': {0}")]
RecursiveRunWithScope(Str),
#[error(transparent)]
SerdeYml(#[from] serde_yml::Error),
#[error("Lint failed, reason: {reason}")]
LintFailed { status: Str, reason: Str },
#[error("Fmt failed")]
FmtFailed { status: Str, reason: Str },
#[error("Vite failed")]
Vite { status: Str, reason: Str },
#[error("Test failed")]
TestFailed { status: Str, reason: Str },
#[error("Lib failed")]
LibFailed { status: Str, reason: Str },
#[error("Doc failed, reason: {reason}")]
DocFailed { status: Str, reason: Str },
#[error("Resolve universal vite config failed")]
ResolveUniversalViteConfigFailed { status: Str, reason: Str },
#[error(
"The stripped path ({stripped_path:?}) is not a valid relative path because: {invalid_path_data_error}"
)]
StripPath { stripped_path: Box<Path>, invalid_path_data_error: InvalidPathDataError },
#[error("The path ({path:?}) is not a valid relative path because: {reason}")]
InvalidRelativePath { path: Box<Path>, reason: FromPathError },
#[error("The package at {package_path:?} is outside the workspace at {workspace_root:?}")]
PackageOutsideWorkspace { package_path: AbsolutePathBuf, workspace_root: AbsolutePathBuf },
#[error("Unsupported package manager: {0}")]
UnsupportedPackageManager(Str),
#[error("Unrecognized any package manager, please specify the package manager")]
UnrecognizedPackageManager,
#[error("No packages specified. Usage: vite add <packages>...")]
NoPackagesSpecified,
#[error(
"Package manager {name}@{version} in {package_json_path:?} is invalid, expected format: 'package-manager-name@major.minor.patch'"
)]
PackageManagerVersionInvalid { name: Str, version: Str, package_json_path: AbsolutePathBuf },
#[error("Package manager {name}@{version} not found on {url}")]
PackageManagerVersionNotFound { name: Str, version: Str, url: Str },
#[error(transparent)]
Semver(#[from] semver::Error),
#[error(transparent)]
Reqwest(#[from] reqwest::Error),
#[error(transparent)]
JoinError(#[from] tokio::task::JoinError),
#[error("User cancelled by Ctrl+C")]
UserCancelled,
#[error("Hash mismatch: expected {expected}, got {actual}")]
HashMismatch { expected: Str, actual: Str },
#[error("Invalid hash format: {0}")]
InvalidHashFormat(Str),
#[error("Unsupported hash algorithm: {0}")]
UnsupportedHashAlgorithm(Str),
#[error(transparent)]
Anyhow(#[from] anyhow::Error),
}
impl From<StripPrefixError<'_>> for Error {
fn from(value: StripPrefixError<'_>) -> Self {
Self::StripPath {
stripped_path: Box::from(value.stripped_path),
invalid_path_data_error: value.invalid_path_data_error,
}
}
}