Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/vite_error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ anyhow = { workspace = true }
bincode = { workspace = true }
bstr = { workspace = true }
nix = { workspace = true }
petgraph = { workspace = true }
rusqlite = { workspace = true }
semver = { workspace = true }
serde_json = { workspace = true }
Expand All @@ -21,6 +20,8 @@ thiserror = { workspace = true }
tokio = { workspace = true }
vite_path = { workspace = true }
vite_str = { workspace = true }
vite_task = { workspace = true }
vite_workspace = { workspace = true }
wax = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies]
Expand Down
61 changes: 6 additions & 55 deletions crates/vite_error/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
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_path::{AbsolutePath, AbsolutePathBuf, relative::FromPathError};
use vite_str::Str;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -59,41 +54,14 @@ pub enum Error {
#[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(transparent)]
SerdeYml(#[from] serde_yml::Error),

#[error("Recursive run is not allowed when task name contains '#': {0}")]
RecursiveRunWithScope(Str),
#[error(transparent)]
TaskError(#[from] vite_task::Error),

#[error(transparent)]
SerdeYml(#[from] serde_yml::Error),
WorkspaceError(#[from] vite_workspace::Error),

#[error("Lint failed, reason: {reason}")]
LintFailed { status: Str, reason: Str },
Expand All @@ -116,17 +84,9 @@ pub enum Error {
#[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),

Expand Down Expand Up @@ -168,12 +128,3 @@ pub enum Error {
#[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,
}
}
}
2 changes: 1 addition & 1 deletion crates/vite_glob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ publish = false
rust-version.workspace = true

[dependencies]
vite_error = { workspace = true }
thiserror = { workspace = true }
wax = { workspace = true }

[dev-dependencies]
Expand Down
7 changes: 7 additions & 0 deletions crates/vite_glob/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use wax;

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)]
WaxBuild(#[from] wax::BuildError),
}
4 changes: 3 additions & 1 deletion crates/vite_glob/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod error;

use std::path::Path;

use vite_error::Error;
pub use error::Error;
use wax::{Glob, Pattern};

/// If there are no negated patterns, it will follow the first match wins semantics.
Expand Down
4 changes: 2 additions & 2 deletions crates/vite_install/src/package_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ mod tests {
fs::create_dir_all(&root_dir).unwrap();
let found = find_package_root(&root_dir);
let err = found.unwrap_err();
assert!(matches!(err, Error::PackageJsonNotFound(_)));
assert!(matches!(err, vite_workspace::Error::PackageJsonNotFound(_)));
}

#[test]
Expand Down Expand Up @@ -683,7 +683,7 @@ mod tests {
// Should return PackageJsonNotFound error if no package.json found
let found = find_workspace_root(&nested_dir);
let err = found.unwrap_err();
assert!(matches!(err, Error::PackageJsonNotFound(_)));
assert!(matches!(err, vite_workspace::Error::PackageJsonNotFound(_)));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/vite_task/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ sha2 = { workspace = true }
shell-escape = { workspace = true }
supports-color = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["rt-multi-thread", "io-std", "macros"] }
tracing = { workspace = true }
twox-hash = { workspace = true }
uuid = { workspace = true, features = ["v4"] }
vite_error = { workspace = true }
vite_glob = { workspace = true }
vite_path = { workspace = true }
vite_str = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/vite_task/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use diff::Diff;
use serde::{Deserialize, Serialize};
pub use task_command::*;
pub use task_graph_builder::*;
use vite_error::Error;
use vite_path::{self, RelativePath, RelativePathBuf};
use vite_str::Str;
pub use workspace::*;

use crate::{
Error,
cmd::TaskParsedCommand,
collections::{HashMap, HashSet},
config::name::TaskName,
Expand Down
116 changes: 116 additions & 0 deletions crates/vite_task/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
use std::{ffi::OsString, io, path::Path, sync::Arc};

use petgraph::algo::Cycle;
use vite_path::{
AbsolutePath, RelativePathBuf,
absolute::StripPrefixError,
relative::{FromPathError, InvalidPathDataError},
};
use vite_str::Str;

#[derive(Debug, thiserror::Error)]
pub enum Error {
// Task-specific errors (constructed in vite_task only)
#[error("Duplicate package name `{name}` found at `{path1}` and `{path2}`")]
DuplicatedPackageName { name: Str, path1: RelativePathBuf, path2: RelativePathBuf },
Comment thread
branchseer marked this conversation as resolved.

#[error("Package not found in workspace: `{0}`")]
PackageNotFound(Str),

#[error("Duplicate task: `{0}`")]
DuplicatedTask(Str),

#[error("Cycle dependencies detected: {0:?}")]
CycleDependencies(Cycle<petgraph::graph::NodeIndex>),

#[error("Task not found: `{task_request}`")]
TaskNotFound { task_request: Str },

#[error("Task dependency `{name}` not found in package at `{package_path}`")]
TaskDependencyNotFound { name: Str, package_path: RelativePathBuf },

#[error("Ambiguous task request: `{task_request}` (contains multiple '#')")]
AmbiguousTaskRequest { task_request: Str },

#[error("Only one task is allowed in implicit mode (got: `{0}`)")]
OnlyOneTaskRequest(Str),

#[error("Recursive run with scoped task name is not supported: `{0}`")]
RecursiveRunWithScope(Str),

// Errors used by vite_task but not task-specific
#[error("Unrecognized db version: {0}")]
UnrecognizedDbVersion(u32),

#[error("Env value is not valid unicode: {key} = {value:?}")]
EnvValueIsNotValidUnicode { key: Str, value: OsString },

#[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("IO error: {err} at {path:?}")]
IoWithPath { err: io::Error, path: Arc<AbsolutePath> },

#[cfg(unix)]
#[error("Unsupported file type: {0:?}")]
UnsupportedFileType(nix::dir::Type),

#[cfg(windows)]
#[error("Unsupported file type: {0:?}")]
UnsupportedFileType(std::fs::FileType),

// External library errors
#[error(transparent)]
Io(#[from] io::Error),

#[error(transparent)]
JoinPathsError(#[from] std::env::JoinPathsError),

#[error(transparent)]
WaxBuild(#[from] wax::BuildError),

#[error(transparent)]
WaxWalk(#[from] wax::WalkError),

#[error(transparent)]
Utf8Error(#[from] bstr::Utf8Error),

#[error(transparent)]
Serde(#[from] serde_json::Error),

#[error(transparent)]
Sqlite(#[from] rusqlite::Error),

#[error(transparent)]
BincodeEncode(#[from] bincode::error::EncodeError),

#[error(transparent)]
BincodeDecode(#[from] bincode::error::DecodeError),

#[error(transparent)]
Anyhow(#[from] anyhow::Error),

#[error(transparent)]
Glob(#[from] vite_glob::Error),

#[error(transparent)]
Workspace(#[from] vite_workspace::Error),

#[cfg(unix)]
#[error(transparent)]
Nix(#[from] nix::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,
}
}
}
3 changes: 2 additions & 1 deletion crates/vite_task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod cache;
mod cmd;
mod collections;
mod config;
mod error;
mod execute;
mod fingerprint;
mod fs;
Expand All @@ -16,7 +17,7 @@ mod test_utils;
// Public exports for vite-plus-cli to use
pub use cache::TaskCache;
pub use config::{ResolvedTask, Workspace};
pub use error::Error;
pub use execute::{CURRENT_EXECUTION_ID, EXECUTION_SUMMARY_DIR};
pub use schedule::{ExecutionPlan, ExecutionStatus, ExecutionSummary};
pub use types::ResolveCommandResult;
pub(crate) use vite_error::Error;
2 changes: 1 addition & 1 deletion crates/vite_workspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ serde = { workspace = true, features = ["derive"] }
# use `preserve_order` feature to preserve the order of the fields in `package.json`
serde_json = { workspace = true, features = ["preserve_order"] }
serde_yml = { workspace = true }
vite_error = { workspace = true }
thiserror = { workspace = true }
vite_glob = { workspace = true }
vite_path = { workspace = true }
vite_str = { workspace = true }
Expand Down
Loading
Loading