From 1c9a12e19dbe3e092fd65f1c35e1959dd5c393b3 Mon Sep 17 00:00:00 2001 From: nicholaslyang Date: Mon, 23 Oct 2023 13:17:28 -0400 Subject: [PATCH] Reverted rename --- .../src/cache_archive/restore_symlink.rs | 8 ++--- crates/turborepo-cache/src/lib.rs | 2 +- crates/turborepo-ffi/src/lib.rs | 4 +-- crates/turborepo-fs/src/lib.rs | 2 +- crates/turborepo-globwalk/src/lib.rs | 4 +-- crates/turborepo-globwatch/src/lib.rs | 4 +-- crates/turborepo-lib/src/cli/error.rs | 2 +- crates/turborepo-lib/src/commands/prune.rs | 2 +- crates/turborepo-lib/src/config/mod.rs | 2 +- crates/turborepo-lib/src/globwatcher/mod.rs | 4 +-- .../src/package_graph/builder.rs | 2 +- crates/turborepo-lib/src/task_hash.rs | 2 +- crates/turborepo-lockfiles/src/berry/mod.rs | 2 +- crates/turborepo-lockfiles/src/error.rs | 2 +- crates/turborepo-lockfiles/src/pnpm/data.rs | 2 +- .../src/absolute_system_path.rs | 30 +++++++++---------- .../src/absolute_system_path_buf.rs | 30 +++++++++---------- .../src/anchored_system_path.rs | 6 ++-- .../src/anchored_system_path_buf.rs | 24 +++++++-------- crates/turborepo-paths/src/lib.rs | 10 +++---- .../turborepo-paths/src/relative_unix_path.rs | 10 +++---- .../src/relative_unix_path_buf.rs | 17 ++++++----- .../src/package_manager/mod.rs | 2 +- crates/turborepo-scm/src/git.rs | 30 +++++++++---------- crates/turborepo-scm/src/lib.rs | 5 +++- 25 files changed, 107 insertions(+), 101 deletions(-) diff --git a/crates/turborepo-cache/src/cache_archive/restore_symlink.rs b/crates/turborepo-cache/src/cache_archive/restore_symlink.rs index 15c009b4a55f5..2fe952e29c459 100644 --- a/crates/turborepo-cache/src/cache_archive/restore_symlink.rs +++ b/crates/turborepo-cache/src/cache_archive/restore_symlink.rs @@ -2,8 +2,8 @@ use std::backtrace::Backtrace; use camino::Utf8Path; use turbopath::{ - AbsoluteSystemPath, AbsoluteSystemPathBuf, AnchoredSystemPath, AnchoredSystemPathBuf, Error, - UnknownPathType, + AbsoluteSystemPath, AbsoluteSystemPathBuf, AnchoredSystemPath, AnchoredSystemPathBuf, + PathError, UnknownPathType, }; use crate::{cache_archive::restore_directory::CachedDirTree, CacheError}; @@ -60,7 +60,7 @@ fn actually_restore_symlink<'a>( let link_name = header.link_name()?.expect("have linkname"); let symlink_to = link_name.to_str().ok_or_else(|| { CacheError::PathError( - Error::InvalidUnicode(link_name.to_string_lossy().to_string()), + PathError::InvalidUnicode(link_name.to_string_lossy().to_string()), Backtrace::capture(), ) })?; @@ -93,7 +93,7 @@ pub fn canonicalize_linkname( ) -> Result { let linkname = linkname.try_into().map_err(|_| { CacheError::PathError( - Error::InvalidUnicode(linkname.to_string_lossy().to_string()), + PathError::InvalidUnicode(linkname.to_string_lossy().to_string()), Backtrace::capture(), ) })?; diff --git a/crates/turborepo-cache/src/lib.rs b/crates/turborepo-cache/src/lib.rs index 681d70bb5bde7..dc43ac2c73b4e 100644 --- a/crates/turborepo-cache/src/lib.rs +++ b/crates/turborepo-cache/src/lib.rs @@ -41,7 +41,7 @@ pub enum CacheError { #[error("invalid duration")] InvalidDuration(#[backtrace] Backtrace), #[error("Invalid file path: {0}")] - PathError(#[from] turbopath::Error, #[backtrace] Backtrace), + PathError(#[from] turbopath::PathError, #[backtrace] Backtrace), #[error("links in the cache are cyclic")] CycleDetected(#[backtrace] Backtrace), #[error("Invalid file path, link target does not exist: {0}")] diff --git a/crates/turborepo-ffi/src/lib.rs b/crates/turborepo-ffi/src/lib.rs index d46a38fd2e950..d20d0f3d4d936 100644 --- a/crates/turborepo-ffi/src/lib.rs +++ b/crates/turborepo-ffi/src/lib.rs @@ -8,7 +8,7 @@ use std::{collections::HashMap, mem::ManuallyDrop}; use globwalk::globwalk; pub use lockfile::{patches, subgraph, transitive_closure}; -use turbopath::{AbsoluteSystemPathBuf, AnchoredSystemPathBuf, Error}; +use turbopath::{AbsoluteSystemPathBuf, AnchoredSystemPathBuf, PathError}; use turborepo_env::EnvironmentVariableMap; mod proto { @@ -305,7 +305,7 @@ pub extern "C" fn get_hashes_for_files(buffer: Buffer) -> Buffer { .files .iter() .map(AnchoredSystemPathBuf::from_raw) - .collect::, Error>>() + .collect::, PathError>>() { Ok(files) => files, Err(err) => { diff --git a/crates/turborepo-fs/src/lib.rs b/crates/turborepo-fs/src/lib.rs index 44aca56049533..406916533d012 100644 --- a/crates/turborepo-fs/src/lib.rs +++ b/crates/turborepo-fs/src/lib.rs @@ -12,7 +12,7 @@ use walkdir::WalkDir; #[derive(Debug, thiserror::Error)] pub enum Error { #[error(transparent)] - Path(#[from] turbopath::Error), + Path(#[from] turbopath::PathError), #[error(transparent)] Io(#[from] io::Error), #[error("error walking directory during recursive copy: {0}")] diff --git a/crates/turborepo-globwalk/src/lib.rs b/crates/turborepo-globwalk/src/lib.rs index 8551de2b1dfd4..98c0631dcbf0e 100644 --- a/crates/turborepo-globwalk/src/lib.rs +++ b/crates/turborepo-globwalk/src/lib.rs @@ -16,7 +16,7 @@ use itertools::Itertools; use path_slash::PathExt; use regex::Regex; use tracing::{info_span, Span}; -use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, Error}; +use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, PathError}; use wax::{Any, BuildError, Glob, Pattern}; #[derive(Debug, PartialEq, Clone, Copy)] @@ -56,7 +56,7 @@ pub enum WalkError { #[error("walk error: {0}")] WalkError(#[from] walkdir::Error), #[error(transparent)] - Path(#[from] Error), + Path(#[from] PathError), #[error(transparent)] WaxWalk(#[from] wax::WalkError), #[error("Internal error on glob {glob}: {error}")] diff --git a/crates/turborepo-globwatch/src/lib.rs b/crates/turborepo-globwatch/src/lib.rs index 98d1d8ef01249..e4151c5fde34e 100644 --- a/crates/turborepo-globwatch/src/lib.rs +++ b/crates/turborepo-globwatch/src/lib.rs @@ -43,7 +43,7 @@ use tokio::sync::{ }; use tokio_stream::wrappers::UnboundedReceiverStream; use tracing::{error, event, span, trace, warn, Level}; -use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, Error}; +use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, PathError}; /// WatchError wraps errors produced by GlobWatcher #[derive(Debug, Error)] @@ -51,7 +51,7 @@ pub enum WatchError { // TODO: find a generic way to include the path in these errors /// PathError wraps errors encountered dealing with paths while filewatching #[error("Filewatching encountered a path error: {0}")] - PathError(#[from] Error), + PathError(#[from] PathError), /// IO wraps IO errors encountered while attempting to watch the filesystem #[error("Filewatching encountered an IO Error: {0}")] IO(#[from] io::Error), diff --git a/crates/turborepo-lib/src/cli/error.rs b/crates/turborepo-lib/src/cli/error.rs index 1c751b8c9ae8a..8ef862ff126ba 100644 --- a/crates/turborepo-lib/src/cli/error.rs +++ b/crates/turborepo-lib/src/cli/error.rs @@ -16,7 +16,7 @@ pub enum Error { #[error("{0}")] Bin(#[from] bin::Error, #[backtrace] backtrace::Backtrace), #[error(transparent)] - Path(#[from] turbopath::Error), + Path(#[from] turbopath::PathError), #[error("at least one task must be specified")] NoTasks(#[backtrace] backtrace::Backtrace), #[error(transparent)] diff --git a/crates/turborepo-lib/src/commands/prune.rs b/crates/turborepo-lib/src/commands/prune.rs index fbce8e99a48c8..a5d78468c9e82 100644 --- a/crates/turborepo-lib/src/commands/prune.rs +++ b/crates/turborepo-lib/src/commands/prune.rs @@ -25,7 +25,7 @@ pub enum Error { #[error("json error while pruning: {0}")] Json(#[from] serde_json::Error), #[error("path error while pruning: {0}")] - Path(#[from] turbopath::Error), + Path(#[from] turbopath::PathError), #[error(transparent)] PackageJson(#[from] turborepo_repository::package_json::Error), #[error(transparent)] diff --git a/crates/turborepo-lib/src/config/mod.rs b/crates/turborepo-lib/src/config/mod.rs index 6295031fbff54..e33237d850b37 100644 --- a/crates/turborepo-lib/src/config/mod.rs +++ b/crates/turborepo-lib/src/config/mod.rs @@ -43,7 +43,7 @@ pub enum Error { env_pipeline_delimiter: &'static str, }, #[error(transparent)] - PathError(#[from] turbopath::Error), + PathError(#[from] turbopath::PathError), #[error("\"{actual}\". Use \"{wanted}\" instead")] UnnecessaryPackageTaskSyntax { actual: String, wanted: String }, #[error("You can only extend from the root workspace")] diff --git a/crates/turborepo-lib/src/globwatcher/mod.rs b/crates/turborepo-lib/src/globwatcher/mod.rs index e5abcec5ef083..89c9b6ccd3c81 100644 --- a/crates/turborepo-lib/src/globwatcher/mod.rs +++ b/crates/turborepo-lib/src/globwatcher/mod.rs @@ -12,7 +12,7 @@ use notify::{EventKind, RecommendedWatcher}; use thiserror::Error; use tokio::time::timeout; use tracing::{trace, warn}; -use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, Error}; +use turbopath::{AbsoluteSystemPath, AbsoluteSystemPathBuf, PathError}; use wax::{Glob as WaxGlob, Pattern}; // these aliases are for readability, but they're just strings. it may make @@ -53,7 +53,7 @@ pub enum HashGlobSetupError { #[error("failed to start tracking hash-globs {0}")] WatchError(#[from] WatchError), #[error("failed to calculate relative path for hash-glob watching ({1}): {0}")] - PathError(Error, AbsoluteSystemPathBuf), + PathError(PathError, AbsoluteSystemPathBuf), } impl HashGlobWatcher { diff --git a/crates/turborepo-lib/src/package_graph/builder.rs b/crates/turborepo-lib/src/package_graph/builder.rs index d96d04ed4e5d2..1d2fe79ec5c71 100644 --- a/crates/turborepo-lib/src/package_graph/builder.rs +++ b/crates/turborepo-lib/src/package_graph/builder.rs @@ -45,7 +45,7 @@ pub enum Error { existing_path: String, }, #[error("path error: {0}")] - TurboPath(#[from] turbopath::Error), + TurboPath(#[from] turbopath::PathError), #[error("unable to parse workspace package.json: {0}")] PackageJson(#[from] turborepo_repository::package_json::Error), #[error("package.json must have a name field:\n{0}")] diff --git a/crates/turborepo-lib/src/task_hash.rs b/crates/turborepo-lib/src/task_hash.rs index ab26bdae23cf9..6367611678472 100644 --- a/crates/turborepo-lib/src/task_hash.rs +++ b/crates/turborepo-lib/src/task_hash.rs @@ -42,7 +42,7 @@ pub enum Error { #[error(transparent)] Regex(#[from] regex::Error), #[error(transparent)] - Path(#[from] turbopath::Error), + Path(#[from] turbopath::PathError), } impl TaskHashable<'_> { diff --git a/crates/turborepo-lockfiles/src/berry/mod.rs b/crates/turborepo-lockfiles/src/berry/mod.rs index cac80df747b3a..c1d28377230ad 100644 --- a/crates/turborepo-lockfiles/src/berry/mod.rs +++ b/crates/turborepo-lockfiles/src/berry/mod.rs @@ -543,7 +543,7 @@ impl Lockfile for BerryLockfile { .filter_map(|patch| patch.patch_file()) .filter(|path| !Locator::is_patch_builtin(path)) .map(|s| RelativeUnixPathBuf::new(s.to_string())) - .collect::, turbopath::Error>>()?; + .collect::, turbopath::PathError>>()?; patches.sort(); Ok(patches) } diff --git a/crates/turborepo-lockfiles/src/error.rs b/crates/turborepo-lockfiles/src/error.rs index d04edc3a07b5b..9a1f95928736f 100644 --- a/crates/turborepo-lockfiles/src/error.rs +++ b/crates/turborepo-lockfiles/src/error.rs @@ -23,5 +23,5 @@ pub enum Error { #[error(transparent)] Berry(#[from] crate::berry::Error), #[error("lockfile contains invalid path: {0}")] - Path(#[from] turbopath::Error), + Path(#[from] turbopath::PathError), } diff --git a/crates/turborepo-lockfiles/src/pnpm/data.rs b/crates/turborepo-lockfiles/src/pnpm/data.rs index 5b2a0b19201b0..3a8030f8225e2 100644 --- a/crates/turborepo-lockfiles/src/pnpm/data.rs +++ b/crates/turborepo-lockfiles/src/pnpm/data.rs @@ -416,7 +416,7 @@ impl crate::Lockfile for PnpmLockfile { .iter() .flatten() .map(|(_, patch)| RelativeUnixPathBuf::new(&patch.path)) - .collect::, turbopath::Error>>()?; + .collect::, turbopath::PathError>>()?; patches.sort(); Ok(patches) } diff --git a/crates/turborepo-paths/src/absolute_system_path.rs b/crates/turborepo-paths/src/absolute_system_path.rs index e009edf5f5ea3..0e23e676e55b0 100644 --- a/crates/turborepo-paths/src/absolute_system_path.rs +++ b/crates/turborepo-paths/src/absolute_system_path.rs @@ -17,7 +17,7 @@ use path_clean::PathClean; use wax::CandidatePath; use crate::{ - AbsoluteSystemPathBuf, AnchoredSystemPath, AnchoredSystemPathBuf, Error, RelativeUnixPath, + AbsoluteSystemPathBuf, AnchoredSystemPath, AnchoredSystemPathBuf, PathError, RelativeUnixPath, }; #[derive(Debug, PartialEq, Eq)] @@ -89,19 +89,19 @@ impl AbsoluteSystemPath { /// assert!(AbsoluteSystemPath::new("/foo/bar").is_err()); /// } /// ``` - pub fn new + ?Sized>(value: &P) -> Result<&Self, Error> { + pub fn new + ?Sized>(value: &P) -> Result<&Self, PathError> { let path: &Utf8Path = value.as_ref().into(); Self::from_utf8_path(path) } - pub fn from_std_path(path: &Path) -> Result<&Self, Error> { + pub fn from_std_path(path: &Path) -> Result<&Self, PathError> { let path: &Utf8Path = path.try_into()?; Self::from_utf8_path(path) } - fn from_utf8_path(path: &Utf8Path) -> Result<&Self, Error> { + fn from_utf8_path(path: &Utf8Path) -> Result<&Self, PathError> { if path.is_relative() { - return Err(Error::NotAbsolute(path.to_string())); + return Err(PathError::NotAbsolute(path.to_string())); } Ok(Self::new_unchecked(path)) } @@ -221,14 +221,14 @@ impl AbsoluteSystemPath { pub fn join_unix_path( &self, unix_path: impl AsRef, - ) -> Result { + ) -> Result { let tail = unix_path.as_ref().to_system_path_buf(); Ok(AbsoluteSystemPathBuf( self.0.join(tail).as_std_path().clean().try_into()?, )) } - pub fn anchor(&self, path: &AbsoluteSystemPath) -> Result { + pub fn anchor(&self, path: &AbsoluteSystemPath) -> Result { AnchoredSystemPathBuf::new(self, path) } @@ -240,13 +240,13 @@ impl AbsoluteSystemPath { } } - pub fn symlink_to_file>(&self, to: P) -> Result<(), Error> { + pub fn symlink_to_file>(&self, to: P) -> Result<(), PathError> { let target = to.as_ref(); symlink_file(target, &self.0)?; Ok(()) } - pub fn symlink_to_dir>(&self, to: P) -> Result<(), Error> { + pub fn symlink_to_dir>(&self, to: P) -> Result<(), PathError> { let target = to.as_ref(); symlink_dir(target, &self.0)?; @@ -258,31 +258,31 @@ impl AbsoluteSystemPath { AbsoluteSystemPathBuf(path) } - pub fn clean(&self) -> Result { + pub fn clean(&self) -> Result { let cleaned_path = self .0 .as_std_path() .clean() .try_into() - .map_err(|_| Error::InvalidUnicode(self.0.as_str().to_owned()))?; + .map_err(|_| PathError::InvalidUnicode(self.0.as_str().to_owned()))?; Ok(AbsoluteSystemPathBuf(cleaned_path)) } - pub fn to_realpath(&self) -> Result { + pub fn to_realpath(&self) -> Result { let realpath = dunce::canonicalize(&self.0)?; Ok(AbsoluteSystemPathBuf(Utf8PathBuf::try_from(realpath)?)) } // note that this is *not* lstat. If this is a symlink, it // will return metadata for the target. - pub fn stat(&self) -> Result { + pub fn stat(&self) -> Result { Ok(fs::metadata(&self.0)?) } // The equivalent of lstat. Returns the metadata for this file, // even if it is a symlink - pub fn symlink_metadata(&self) -> Result { + pub fn symlink_metadata(&self) -> Result { Ok(fs::symlink_metadata(&self.0)?) } @@ -472,7 +472,7 @@ impl PartialEq<&AbsoluteSystemPath> for PathBuf { } impl<'a> TryFrom<&'a Path> for &'a AbsoluteSystemPath { - type Error = Error; + type Error = PathError; fn try_from(value: &'a Path) -> Result { AbsoluteSystemPath::from_std_path(value) diff --git a/crates/turborepo-paths/src/absolute_system_path_buf.rs b/crates/turborepo-paths/src/absolute_system_path_buf.rs index 1c934c6fd26e2..481698ae47967 100644 --- a/crates/turborepo-paths/src/absolute_system_path_buf.rs +++ b/crates/turborepo-paths/src/absolute_system_path_buf.rs @@ -10,7 +10,7 @@ use fs_err as fs; use path_clean::PathClean; use serde::Serialize; -use crate::{AbsoluteSystemPath, AnchoredSystemPathBuf, Error}; +use crate::{AbsoluteSystemPath, AnchoredSystemPathBuf, PathError}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize)] pub struct AbsoluteSystemPathBuf(pub(crate) Utf8PathBuf); @@ -66,10 +66,10 @@ impl AbsoluteSystemPathBuf { /// #[cfg(not(windows))] /// assert_eq!(absolute_path.as_path(), Utf8Path::new("/Users/user")); /// ``` - pub fn new(unchecked_path: impl Into) -> Result { + pub fn new(unchecked_path: impl Into) -> Result { let unchecked_path = unchecked_path.into(); if !Path::new(&unchecked_path).is_absolute() { - return Err(Error::NotAbsolute(unchecked_path)); + return Err(PathError::NotAbsolute(unchecked_path)); } Ok(AbsoluteSystemPathBuf(unchecked_path.into())) } @@ -91,12 +91,12 @@ impl AbsoluteSystemPathBuf { } } - pub fn from_cwd(unknown: impl Into) -> Result { + pub fn from_cwd(unknown: impl Into) -> Result { let cwd = Self::cwd()?; Ok(Self::from_unknown(&cwd, unknown)) } - pub fn cwd() -> Result { + pub fn cwd() -> Result { // TODO(errors): Unwrap current_dir() Ok(Self(Utf8PathBuf::try_from(std::env::current_dir()?)?)) } @@ -133,7 +133,7 @@ impl AbsoluteSystemPathBuf { pub fn anchor( &self, path: impl AsRef, - ) -> Result { + ) -> Result { AnchoredSystemPathBuf::new(self, path) } @@ -173,7 +173,7 @@ impl AbsoluteSystemPathBuf { fs::remove_file(self.0.as_path()) } - pub fn set_readonly(&self) -> Result<(), Error> { + pub fn set_readonly(&self) -> Result<(), PathError> { let metadata = fs::symlink_metadata(self)?; let mut perms = metadata.permissions(); perms.set_readonly(true); @@ -181,7 +181,7 @@ impl AbsoluteSystemPathBuf { Ok(()) } - pub fn is_readonly(&self) -> Result { + pub fn is_readonly(&self) -> Result { Ok(self.0.symlink_metadata()?.permissions().readonly()) } @@ -193,7 +193,7 @@ impl AbsoluteSystemPathBuf { self.0.file_name() } - pub fn try_exists(&self) -> Result { + pub fn try_exists(&self) -> Result { // try_exists is an experimental API and not yet in fs_err Ok(std::fs::try_exists(&self.0)?) } @@ -204,7 +204,7 @@ impl AbsoluteSystemPathBuf { } impl TryFrom for AbsoluteSystemPathBuf { - type Error = Error; + type Error = PathError; fn try_from(path: PathBuf) -> Result { Self::new(Utf8PathBuf::try_from(path)?) @@ -212,7 +212,7 @@ impl TryFrom for AbsoluteSystemPathBuf { } impl TryFrom<&Path> for AbsoluteSystemPathBuf { - type Error = Error; + type Error = PathError; fn try_from(path: &Path) -> Result { let utf8_path: &Utf8Path = path.try_into()?; @@ -221,7 +221,7 @@ impl TryFrom<&Path> for AbsoluteSystemPathBuf { } impl TryFrom<&str> for AbsoluteSystemPathBuf { - type Error = Error; + type Error = PathError; fn try_from(value: &str) -> Result { Self::new(Utf8PathBuf::from(value)) @@ -250,7 +250,7 @@ impl AsRef for AbsoluteSystemPathBuf { mod tests { use std::assert_matches::assert_matches; - use crate::{AbsoluteSystemPathBuf, Error, RelativeUnixPathBuf}; + use crate::{AbsoluteSystemPathBuf, PathError, RelativeUnixPathBuf}; #[cfg(not(windows))] #[test] @@ -258,12 +258,12 @@ mod tests { assert!(AbsoluteSystemPathBuf::new("/Users/user").is_ok()); assert_matches!( AbsoluteSystemPathBuf::new("./Users/user/"), - Err(Error::NotAbsolute(_)) + Err(PathError::NotAbsolute(_)) ); assert_matches!( AbsoluteSystemPathBuf::new("Users"), - Err(Error::NotAbsolute(_)) + Err(PathError::NotAbsolute(_)) ); let tail = RelativeUnixPathBuf::new("../other").unwrap(); diff --git a/crates/turborepo-paths/src/anchored_system_path.rs b/crates/turborepo-paths/src/anchored_system_path.rs index 2c4392adf08fc..5619a755ac54c 100644 --- a/crates/turborepo-paths/src/anchored_system_path.rs +++ b/crates/turborepo-paths/src/anchored_system_path.rs @@ -3,7 +3,7 @@ use std::{fmt, path::Path}; use camino::{Utf8Component, Utf8Path}; use serde::Serialize; -use crate::{AnchoredSystemPathBuf, Error, RelativeUnixPathBuf}; +use crate::{AnchoredSystemPathBuf, PathError, RelativeUnixPathBuf}; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)] #[serde(transparent)] @@ -47,11 +47,11 @@ impl AnchoredSystemPath { unsafe { &*(path as *const Path as *const Self) } } - pub fn new<'a>(path: impl AsRef + 'a) -> Result<&'a Self, Error> { + pub fn new<'a>(path: impl AsRef + 'a) -> Result<&'a Self, PathError> { let path_str = path.as_ref(); let path = Path::new(path_str); if path.is_absolute() { - return Err(Error::NotRelative(path_str.to_string())); + return Err(PathError::NotRelative(path_str.to_string())); } Ok(unsafe { &*(path as *const Path as *const Self) }) diff --git a/crates/turborepo-paths/src/anchored_system_path_buf.rs b/crates/turborepo-paths/src/anchored_system_path_buf.rs index 2da022f1a69eb..1d55aaa8294e5 100644 --- a/crates/turborepo-paths/src/anchored_system_path_buf.rs +++ b/crates/turborepo-paths/src/anchored_system_path_buf.rs @@ -8,19 +8,19 @@ use std::{ use camino::{Utf8Component, Utf8Components, Utf8Path, Utf8PathBuf}; use serde::{Deserialize, Serialize}; -use crate::{check_path, AbsoluteSystemPath, AnchoredSystemPath, Error, PathValidation}; +use crate::{check_path, AbsoluteSystemPath, AnchoredSystemPath, PathError, PathValidation}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize)] #[serde(transparent)] pub struct AnchoredSystemPathBuf(pub(crate) Utf8PathBuf); impl TryFrom<&str> for AnchoredSystemPathBuf { - type Error = Error; + type Error = PathError; fn try_from(path: &str) -> Result { let path = Utf8Path::new(path); if path.is_absolute() { - return Err(Error::NotRelative(path.to_string())); + return Err(PathError::NotRelative(path.to_string())); } Ok(AnchoredSystemPathBuf(path.into())) @@ -48,12 +48,12 @@ impl Deref for AnchoredSystemPathBuf { } impl TryFrom<&Path> for AnchoredSystemPathBuf { - type Error = Error; + type Error = PathError; fn try_from(path: &Path) -> Result { let path = path .to_str() - .ok_or_else(|| Error::InvalidUnicode(path.to_string_lossy().to_string()))?; + .ok_or_else(|| PathError::InvalidUnicode(path.to_string_lossy().to_string()))?; Self::try_from(path) } @@ -76,13 +76,13 @@ impl AnchoredSystemPathBuf { pub fn new( root: impl AsRef, path: impl AsRef, - ) -> Result { + ) -> Result { let root = root.as_ref(); let path = path.as_ref(); let stripped_path = path .as_path() .strip_prefix(root.as_path()) - .map_err(|_| Error::NotParent(root.to_string(), path.to_string()))? + .map_err(|_| PathError::NotParent(root.to_string(), path.to_string()))? .into(); Ok(AnchoredSystemPathBuf(stripped_path)) @@ -136,7 +136,7 @@ impl AnchoredSystemPathBuf { Self(path) } - pub fn from_raw(raw: impl AsRef) -> Result { + pub fn from_raw(raw: impl AsRef) -> Result { let system_path = raw.as_ref(); Ok(Self(system_path.into())) } @@ -147,10 +147,10 @@ impl AnchoredSystemPathBuf { // Takes in a path, validates that it is anchored and constructs an // `AnchoredSystemPathBuf` with no trailing slashes. - pub fn from_system_path(path: &Path) -> Result { + pub fn from_system_path(path: &Path) -> Result { let path = path .to_str() - .ok_or_else(|| Error::InvalidUnicode(path.to_string_lossy().to_string()))?; + .ok_or_else(|| PathError::InvalidUnicode(path.to_string_lossy().to_string()))?; #[allow(unused_variables)] let PathValidation { @@ -159,13 +159,13 @@ impl AnchoredSystemPathBuf { } = check_path(path); if !well_formed { - return Err(Error::MalformedPath(path.to_string())); + return Err(PathError::MalformedPath(path.to_string())); } #[cfg(windows)] { if !windows_safe { - return Err(Error::WindowsUnsafePath(path.to_string())); + return Err(PathError::WindowsUnsafePath(path.to_string())); } } diff --git a/crates/turborepo-paths/src/lib.rs b/crates/turborepo-paths/src/lib.rs index 69be2ec35ad20..6a0025736770b 100644 --- a/crates/turborepo-paths/src/lib.rs +++ b/crates/turborepo-paths/src/lib.rs @@ -51,7 +51,7 @@ pub use relative_unix_path_buf::{RelativeUnixPathBuf, RelativeUnixPathBufTestExt pub const FILE_FLAG_SEQUENTIAL_SCAN: u32 = 0x08000000; #[derive(Debug, thiserror::Error)] -pub enum Error { +pub enum PathError { #[error("Path is non-UTF-8: {0}")] InvalidUnicode(String), #[error("Failed to convert path")] @@ -78,15 +78,15 @@ pub enum Error { PrefixError(String, String), } -impl From for Error { +impl From for PathError { fn from(value: std::string::FromUtf8Error) -> Self { - Error::InvalidUnicode(value.utf8_error().to_string()) + PathError::InvalidUnicode(value.utf8_error().to_string()) } } -impl Error { +impl PathError { pub fn is_io_error(&self, kind: io::ErrorKind) -> bool { - matches!(self, Error::IO(err) if err.kind() == kind) + matches!(self, PathError::IO(err) if err.kind() == kind) } } diff --git a/crates/turborepo-paths/src/relative_unix_path.rs b/crates/turborepo-paths/src/relative_unix_path.rs index fc9efb5cb5139..6f06eaf95d579 100644 --- a/crates/turborepo-paths/src/relative_unix_path.rs +++ b/crates/turborepo-paths/src/relative_unix_path.rs @@ -5,7 +5,7 @@ use std::{ use camino::{Utf8Path, Utf8PathBuf}; -use crate::{AnchoredSystemPathBuf, Error, RelativeUnixPathBuf}; +use crate::{AnchoredSystemPathBuf, PathError, RelativeUnixPathBuf}; #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] @@ -18,10 +18,10 @@ impl Display for RelativeUnixPath { } impl RelativeUnixPath { - pub fn new<'a, P: AsRef + 'a>(value: P) -> Result<&'a Self, Error> { + pub fn new<'a, P: AsRef + 'a>(value: P) -> Result<&'a Self, PathError> { let path = value.as_ref(); if path.starts_with('/') { - return Err(Error::NotRelative(path.to_string())); + return Err(PathError::NotRelative(path.to_string())); } // copied from stdlib path.rs: relies on the representation of // RelativeUnixPath being just a str, the same way Path relies on @@ -59,11 +59,11 @@ impl RelativeUnixPath { pub fn strip_prefix( &self, prefix: impl AsRef, - ) -> Result<&RelativeUnixPath, Error> { + ) -> Result<&RelativeUnixPath, PathError> { let stripped_path = self .0 .strip_prefix(&prefix.as_ref().0) - .ok_or_else(|| Error::NotParent(prefix.as_ref().to_string(), self.to_string()))?; + .ok_or_else(|| PathError::NotParent(prefix.as_ref().to_string(), self.to_string()))?; // Remove leading '/' if present let stripped_path = stripped_path.strip_prefix('/').unwrap_or(stripped_path); diff --git a/crates/turborepo-paths/src/relative_unix_path_buf.rs b/crates/turborepo-paths/src/relative_unix_path_buf.rs index 3f0d3b2c5b923..ce49d7a9e7d04 100644 --- a/crates/turborepo-paths/src/relative_unix_path_buf.rs +++ b/crates/turborepo-paths/src/relative_unix_path_buf.rs @@ -8,7 +8,7 @@ use std::{ use camino::Utf8Path; use serde::{Deserialize, Serialize}; -use crate::{Error, RelativeUnixPath}; +use crate::{PathError, RelativeUnixPath}; #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize)] // This is necessary to perform validation on the string during deserialization #[serde(try_from = "String", into = "String")] @@ -21,10 +21,10 @@ impl Display for RelativeUnixPathBuf { } impl RelativeUnixPathBuf { - pub fn new(path: impl Into) -> Result { + pub fn new(path: impl Into) -> Result { let path_string = path.into(); if path_string.starts_with('/') || Utf8Path::new(&path_string).is_absolute() { - return Err(Error::NotRelative(path_string)); + return Err(PathError::NotRelative(path_string)); } Ok(Self(path_string)) @@ -44,13 +44,16 @@ impl RelativeUnixPathBuf { } } - pub fn strip_prefix(&self, prefix: &RelativeUnixPathBuf) -> Result { + pub fn strip_prefix(&self, prefix: &RelativeUnixPathBuf) -> Result { let prefix_len = prefix.0.len(); if prefix_len == 0 { return Ok(self.clone()); } if !self.0.starts_with(&prefix.0) { - return Err(Error::NotParent(prefix.0.to_string(), self.0.to_string())); + return Err(PathError::NotParent( + prefix.0.to_string(), + self.0.to_string(), + )); } // Handle the case where we are stripping the entire contents of this path @@ -63,7 +66,7 @@ impl RelativeUnixPathBuf { if self.0.as_bytes()[prefix_len] != b'/' { let prefix_str = prefix.0.clone(); let this = self.0.clone(); - return Err(Error::PrefixError(prefix_str, this)); + return Err(PathError::PrefixError(prefix_str, this)); } let tail_slice = &self.0[(prefix_len + 1)..]; @@ -112,7 +115,7 @@ impl Deref for RelativeUnixPathBuf { } impl TryFrom for RelativeUnixPathBuf { - type Error = Error; + type Error = PathError; fn try_from(value: String) -> Result { Self::new(value) diff --git a/crates/turborepo-repository/src/package_manager/mod.rs b/crates/turborepo-repository/src/package_manager/mod.rs index 92ff35f47452e..0ec2895b22794 100644 --- a/crates/turborepo-repository/src/package_manager/mod.rs +++ b/crates/turborepo-repository/src/package_manager/mod.rs @@ -256,7 +256,7 @@ pub enum Error { #[error("invalid utf8: {0}")] Utf8Error(#[from] std::string::FromUtf8Error), #[error(transparent)] - Path(#[from] turbopath::Error), + Path(#[from] turbopath::PathError), #[error( "We could not parse the packageManager field in package.json, expected: {0}, received: {1}" )] diff --git a/crates/turborepo-scm/src/git.rs b/crates/turborepo-scm/src/git.rs index f4ea3a15c3831..799738da2072a 100644 --- a/crates/turborepo-scm/src/git.rs +++ b/crates/turborepo-scm/src/git.rs @@ -232,13 +232,13 @@ mod tests { use git2::{Oid, Repository}; use tempfile::TempDir; - use turbopath::{AbsoluteSystemPathBuf, Error}; + use turbopath::{AbsoluteSystemPathBuf, PathError}; use which::which; use super::previous_content; use crate::{git::changed_files, Error}; - fn setup_repository() -> Result<(TempDir, Repository), Error> { + fn setup_repository() -> Result<(TempDir, Repository), PathError> { let repo_root = tempfile::tempdir()?; let repo = Repository::init(repo_root.path()).unwrap(); let mut config = repo.config().unwrap(); @@ -294,7 +294,7 @@ mod tests { } #[test] - fn test_shallow_clone() -> Result<(), Error> { + fn test_shallow_clone() -> Result<(), PathError> { let tmp_dir = tempfile::tempdir()?; let git_binary = which("git")?; @@ -329,7 +329,7 @@ mod tests { } #[test] - fn test_deleted_files() -> Result<(), Error> { + fn test_deleted_files() -> Result<(), PathError> { let (repo_root, repo) = setup_repository()?; let file = repo_root.path().join("foo.js"); @@ -351,7 +351,7 @@ mod tests { } #[test] - fn test_merge_base() -> Result<(), Error> { + fn test_merge_base() -> Result<(), PathError> { let (repo_root, repo) = setup_repository()?; let first_file = repo_root.path().join("foo.js"); fs::write(first_file, "let z = 0;")?; @@ -398,7 +398,7 @@ mod tests { } #[test] - fn test_changed_files() -> Result<(), Error> { + fn test_changed_files() -> Result<(), PathError> { let (repo_root, repo) = setup_repository()?; let mut index = repo.index().unwrap(); let turbo_root = repo_root.path(); @@ -464,7 +464,7 @@ mod tests { } #[test] - fn test_changed_files_with_root_as_relative() -> Result<(), Error> { + fn test_changed_files_with_root_as_relative() -> Result<(), PathError> { let (repo_root, repo) = setup_repository()?; let file = repo_root.path().join("foo.js"); fs::write(file, "let z = 0;")?; @@ -492,7 +492,7 @@ mod tests { // Tests that we can use a subdir as the turbo_root path // (occurs when the monorepo is nested inside a subdirectory of git repository) #[test] - fn test_changed_files_with_subdir_as_turbo_root() -> Result<(), Error> { + fn test_changed_files_with_subdir_as_turbo_root() -> Result<(), PathError> { let (repo_root, repo) = setup_repository()?; fs::create_dir(repo_root.path().join("subdir"))?; @@ -553,7 +553,7 @@ mod tests { } #[test] - fn test_previous_content() -> Result<(), Error> { + fn test_previous_content() -> Result<(), PathError> { let (repo_root, repo) = setup_repository()?; let root = AbsoluteSystemPathBuf::try_from(repo_root.path()).unwrap(); @@ -590,7 +590,7 @@ mod tests { } #[test] - fn test_revparse() -> Result<(), Error> { + fn test_revparse() -> Result<(), PathError> { let (repo_root, repo) = setup_repository()?; let root = AbsoluteSystemPathBuf::try_from(repo_root.path()).unwrap(); @@ -635,7 +635,7 @@ mod tests { } #[test] - fn test_error_cases() -> Result<(), Error> { + fn test_error_cases() -> Result<(), PathError> { let repo_dir = tempfile::tempdir()?; let repo_does_not_exist = changed_files( repo_dir.path().to_path_buf(), @@ -644,7 +644,7 @@ mod tests { "HEAD", ); - assert_matches!(repo_does_not_exist, Err(Error::GitRequired(_))); + assert_matches!(repo_does_not_exist, Err(PathError::GitRequired(_))); let (repo_root, _repo) = setup_repository()?; let root = AbsoluteSystemPathBuf::try_from(repo_root.path()).unwrap(); @@ -656,14 +656,14 @@ mod tests { "does-not-exist", ); - assert_matches!(commit_does_not_exist, Err(Error::Git(_, _))); + assert_matches!(commit_does_not_exist, Err(PathError::Git(_, _))); let file_does_not_exist = previous_content( repo_root.path().to_path_buf(), "HEAD", root.join_component("does-not-exist").to_string(), ); - assert_matches!(file_does_not_exist, Err(Error::Git(_, _))); + assert_matches!(file_does_not_exist, Err(PathError::Git(_, _))); let turbo_root = tempfile::tempdir()?; let turbo_root_is_not_subdir_of_git_root = changed_files( @@ -675,7 +675,7 @@ mod tests { assert_matches!( turbo_root_is_not_subdir_of_git_root, - Err(Error::Path(Error::NotParent(_, _), _)) + Err(PathError::Path(PathError::NotParent(_, _), _)) ); Ok(()) diff --git a/crates/turborepo-scm/src/lib.rs b/crates/turborepo-scm/src/lib.rs index df553e27505a8..78f1f2c61fda4 100644 --- a/crates/turborepo-scm/src/lib.rs +++ b/crates/turborepo-scm/src/lib.rs @@ -39,7 +39,10 @@ pub enum Error { #[error("io error: {0}")] Io(#[from] std::io::Error, #[backtrace] backtrace::Backtrace), #[error("path error: {0}")] - Path(#[from] turbopath::Error, #[backtrace] backtrace::Backtrace), + Path( + #[from] turbopath::PathError, + #[backtrace] backtrace::Backtrace, + ), #[error("could not find git binary")] GitBinaryNotFound(#[from] which::Error), #[error("encoding error: {0}")]