From 848461175314b5149e28ae09a35371052dfcbdf3 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 18 Jul 2024 00:13:45 -0400 Subject: [PATCH] Rename `Error::IO` to `Error::Io` (#5174) ## Summary I believe this is by convention (see, e.g., in Rust itself: https://github.com/search?q=repo%3Arust-lang%2Frust+%2F%28%3F-i%29Io%2F&type=code). --- crates/requirements-txt/src/lib.rs | 16 ++++++++-------- crates/uv-build/src/lib.rs | 2 +- crates/uv-python/src/discovery.rs | 2 +- crates/uv-python/src/downloads.rs | 2 +- crates/uv-python/src/managed.rs | 2 +- crates/uv-python/src/virtualenv.rs | 4 ++-- crates/uv-tool/src/lib.rs | 4 ++-- crates/uv-virtualenv/src/lib.rs | 2 +- crates/uv-virtualenv/src/virtualenv.rs | 6 +++--- crates/uv/src/commands/tool/list.rs | 2 +- crates/uv/src/commands/tool/uninstall.rs | 4 ++-- 11 files changed, 23 insertions(+), 23 deletions(-) diff --git a/crates/requirements-txt/src/lib.rs b/crates/requirements-txt/src/lib.rs index e69964a40..4fe254dfa 100644 --- a/crates/requirements-txt/src/lib.rs +++ b/crates/requirements-txt/src/lib.rs @@ -169,7 +169,7 @@ impl RequirementsTxt { { return Err(RequirementsTxtFileError { file: requirements_txt.to_path_buf(), - error: RequirementsTxtParserError::IO(io::Error::new( + error: RequirementsTxtParserError::Io(io::Error::new( io::ErrorKind::InvalidInput, "Remote file not supported without `http` feature", )), @@ -182,7 +182,7 @@ impl RequirementsTxt { if client_builder.is_offline() { return Err(RequirementsTxtFileError { file: requirements_txt.to_path_buf(), - error: RequirementsTxtParserError::IO(io::Error::new( + error: RequirementsTxtParserError::Io(io::Error::new( io::ErrorKind::InvalidInput, format!("Network connectivity is disabled, but a remote requirements file was requested: {}", requirements_txt.display()), )), @@ -196,7 +196,7 @@ impl RequirementsTxt { // Ex) `file:///home/ferris/project/requirements.txt` uv_fs::read_to_string_transcode(&requirements_txt) .await - .map_err(RequirementsTxtParserError::IO) + .map_err(RequirementsTxtParserError::Io) } .map_err(|err| RequirementsTxtFileError { file: requirements_txt.to_path_buf(), @@ -800,7 +800,7 @@ pub struct RequirementsTxtFileError { /// Error parsing requirements.txt, error disambiguation #[derive(Debug)] pub enum RequirementsTxtParserError { - IO(io::Error), + Io(io::Error), Url { source: url::ParseError, url: String, @@ -877,7 +877,7 @@ pub enum RequirementsTxtParserError { impl Display for RequirementsTxtParserError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { - Self::IO(err) => err.fmt(f), + Self::Io(err) => err.fmt(f), Self::Url { url, start, .. } => { write!(f, "Invalid URL at position {start}: `{url}`") } @@ -945,7 +945,7 @@ impl Display for RequirementsTxtParserError { impl std::error::Error for RequirementsTxtParserError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match &self { - Self::IO(err) => err.source(), + Self::Io(err) => err.source(), Self::Url { source, .. } => Some(source), Self::FileUrl { .. } => None, Self::VerbatimUrl { source, .. } => Some(source), @@ -971,7 +971,7 @@ impl std::error::Error for RequirementsTxtParserError { impl Display for RequirementsTxtFileError { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match &self.error { - RequirementsTxtParserError::IO(err) => err.fmt(f), + RequirementsTxtParserError::Io(err) => err.fmt(f), RequirementsTxtParserError::Url { url, start, .. } => { write!( f, @@ -1108,7 +1108,7 @@ impl std::error::Error for RequirementsTxtFileError { impl From for RequirementsTxtParserError { fn from(err: io::Error) -> Self { - Self::IO(err) + Self::Io(err) } } diff --git a/crates/uv-build/src/lib.rs b/crates/uv-build/src/lib.rs index a774da42a..c9a98a694 100644 --- a/crates/uv-build/src/lib.rs +++ b/crates/uv-build/src/lib.rs @@ -87,7 +87,7 @@ static SETUP_PY_REQUIREMENTS: Lazy<[Requirement; 2]> = Lazy::new(|| { #[derive(Error, Debug)] pub enum Error { #[error(transparent)] - IO(#[from] io::Error), + Io(#[from] io::Error), #[error("Invalid source distribution: {0}")] InvalidSourceDist(String), #[error("Invalid `pyproject.toml`")] diff --git a/crates/uv-python/src/discovery.rs b/crates/uv-python/src/discovery.rs index 60b76666b..53ca7106f 100644 --- a/crates/uv-python/src/discovery.rs +++ b/crates/uv-python/src/discovery.rs @@ -149,7 +149,7 @@ pub enum PythonSource { #[derive(Error, Debug)] pub enum Error { #[error(transparent)] - IO(#[from] io::Error), + Io(#[from] io::Error), /// An error was encountering when retrieving interpreter information. #[error(transparent)] diff --git a/crates/uv-python/src/downloads.rs b/crates/uv-python/src/downloads.rs index 45bf71ae3..86dd495e3 100644 --- a/crates/uv-python/src/downloads.rs +++ b/crates/uv-python/src/downloads.rs @@ -28,7 +28,7 @@ use crate::{Interpreter, PythonRequest, PythonVersion, VersionRequest}; #[derive(Error, Debug)] pub enum Error { #[error(transparent)] - IO(#[from] io::Error), + Io(#[from] io::Error), #[error(transparent)] ImplementationError(#[from] ImplementationError), #[error("Invalid Python version: {0}")] diff --git a/crates/uv-python/src/managed.rs b/crates/uv-python/src/managed.rs index 6e87c40b3..6c8a8041f 100644 --- a/crates/uv-python/src/managed.rs +++ b/crates/uv-python/src/managed.rs @@ -24,7 +24,7 @@ use uv_fs::{LockedFile, Simplified}; #[derive(Error, Debug)] pub enum Error { #[error(transparent)] - IO(#[from] io::Error), + Io(#[from] io::Error), #[error(transparent)] Download(#[from] DownloadError), #[error(transparent)] diff --git a/crates/uv-python/src/virtualenv.rs b/crates/uv-python/src/virtualenv.rs index f4737d950..ed9a862a7 100644 --- a/crates/uv-python/src/virtualenv.rs +++ b/crates/uv-python/src/virtualenv.rs @@ -32,12 +32,12 @@ pub struct PyVenvConfiguration { #[derive(Debug, Error)] pub enum Error { + #[error(transparent)] + Io(#[from] io::Error), #[error("Broken virtualenv `{0}`: `pyvenv.cfg` is missing")] MissingPyVenvCfg(PathBuf), #[error("Broken virtualenv `{0}`: `pyvenv.cfg` could not be parsed")] ParsePyVenvCfg(PathBuf, #[source] io::Error), - #[error(transparent)] - IO(#[from] io::Error), } /// Locate an active virtual environment by inspecting environment variables. diff --git a/crates/uv-tool/src/lib.rs b/crates/uv-tool/src/lib.rs index 468fca7ae..fd438759f 100644 --- a/crates/uv-tool/src/lib.rs +++ b/crates/uv-tool/src/lib.rs @@ -30,7 +30,7 @@ mod tool; #[derive(Error, Debug)] pub enum Error { #[error(transparent)] - IO(#[from] io::Error), + Io(#[from] io::Error), #[error("Failed to update `uv-receipt.toml` at {0}")] ReceiptWrite(PathBuf, #[source] Box), #[error("Failed to read `uv-receipt.toml` at {0}")] @@ -121,7 +121,7 @@ impl InstalledTools { let path = self.tool_dir(name).join("uv-receipt.toml"); match ToolReceipt::from_path(&path) { Ok(tool_receipt) => Ok(Some(tool_receipt.tool)), - Err(Error::IO(err)) if err.kind() == io::ErrorKind::NotFound => Ok(None), + Err(Error::Io(err)) if err.kind() == io::ErrorKind::NotFound => Ok(None), Err(err) => Err(err), } } diff --git a/crates/uv-virtualenv/src/lib.rs b/crates/uv-virtualenv/src/lib.rs index a3c3a17ab..6983284d6 100644 --- a/crates/uv-virtualenv/src/lib.rs +++ b/crates/uv-virtualenv/src/lib.rs @@ -11,7 +11,7 @@ mod virtualenv; #[derive(Debug, Error)] pub enum Error { #[error(transparent)] - IO(#[from] io::Error), + Io(#[from] io::Error), #[error("Failed to determine Python interpreter to use")] Discovery(#[from] uv_python::DiscoveryError), #[error("Failed to determine Python interpreter to use")] diff --git a/crates/uv-virtualenv/src/virtualenv.rs b/crates/uv-virtualenv/src/virtualenv.rs index 8230774c7..ae4696dd8 100644 --- a/crates/uv-virtualenv/src/virtualenv.rs +++ b/crates/uv-virtualenv/src/virtualenv.rs @@ -86,7 +86,7 @@ pub(crate) fn create( match location.metadata() { Ok(metadata) => { if metadata.is_file() { - return Err(Error::IO(io::Error::new( + return Err(Error::Io(io::Error::new( io::ErrorKind::AlreadyExists, format!("File exists at `{}`", location.user_display()), ))); @@ -103,7 +103,7 @@ pub(crate) fn create( { info!("Ignoring empty directory"); } else { - return Err(Error::IO(io::Error::new( + return Err(Error::Io(io::Error::new( io::ErrorKind::AlreadyExists, format!( "The directory `{}` exists, but it's not a virtualenv", @@ -116,7 +116,7 @@ pub(crate) fn create( Err(err) if err.kind() == io::ErrorKind::NotFound => { fs::create_dir_all(location)?; } - Err(err) => return Err(Error::IO(err)), + Err(err) => return Err(Error::Io(err)), } let location = location.canonicalize()?; diff --git a/crates/uv/src/commands/tool/list.rs b/crates/uv/src/commands/tool/list.rs index 9698f6468..55a157cee 100644 --- a/crates/uv/src/commands/tool/list.rs +++ b/crates/uv/src/commands/tool/list.rs @@ -26,7 +26,7 @@ pub(crate) async fn list( let installed_tools = InstalledTools::from_settings()?; let _lock = match installed_tools.acquire_lock() { Ok(lock) => lock, - Err(uv_tool::Error::IO(err)) if err.kind() == std::io::ErrorKind::NotFound => { + Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => { writeln!(printer.stderr(), "No tools installed")?; return Ok(ExitStatus::Success); } diff --git a/crates/uv/src/commands/tool/uninstall.rs b/crates/uv/src/commands/tool/uninstall.rs index 3fd35d979..faf028364 100644 --- a/crates/uv/src/commands/tool/uninstall.rs +++ b/crates/uv/src/commands/tool/uninstall.rs @@ -27,7 +27,7 @@ pub(crate) async fn uninstall( let installed_tools = InstalledTools::from_settings()?.init()?; let _lock = match installed_tools.acquire_lock() { Ok(lock) => lock, - Err(uv_tool::Error::IO(err)) if err.kind() == std::io::ErrorKind::NotFound => { + Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => { if let Some(name) = name { bail!("`{name}` is not installed"); } @@ -48,7 +48,7 @@ pub(crate) async fn uninstall( )?; return Ok(ExitStatus::Success); } - Err(uv_tool::Error::IO(err)) if err.kind() == std::io::ErrorKind::NotFound => { + Err(uv_tool::Error::Io(err)) if err.kind() == std::io::ErrorKind::NotFound => { bail!("`{name}` is not installed"); } Err(err) => {