diff --git a/postgresql_archive/src/archive.rs b/postgresql_archive/src/archive.rs index 02da282..3451aee 100644 --- a/postgresql_archive/src/archive.rs +++ b/postgresql_archive/src/archive.rs @@ -1,6 +1,6 @@ //! Manage PostgreSQL archive #![allow(dead_code)] -use crate::error::ArchiveError::{AssetHashNotFound, AssetNotFound, ReleaseNotFound, Unexpected}; +use crate::error::Error::{AssetHashNotFound, AssetNotFound, ReleaseNotFound, Unexpected}; use crate::error::Result; use crate::github::{Asset, Release}; use crate::version::Version; @@ -145,7 +145,7 @@ pub async fn get_version(version: &Version) -> Result { /// Gets the assets for a given [version](Version) of PostgreSQL and /// [target](https://doc.rust-lang.org/nightly/rustc/platform-support.html). /// If the [version](Version) or [target](https://doc.rust-lang.org/nightly/rustc/platform-support.html) -/// is not found, then an [error](crate::error::ArchiveError) is returned. +/// is not found, then an [error](crate::error::Error) is returned. /// /// Two assets are returned. The first [asset](Asset) is the archive, and the second [asset](Asset) is the archive hash. async fn get_asset>(version: &Version, target: S) -> Result<(Version, Asset, Asset)> { @@ -177,7 +177,7 @@ async fn get_asset>(version: &Version, target: S) -> Result<(Versi /// Gets the archive for a given [version](Version) of PostgreSQL for the current target. /// If the [version](Version) is not found for this target, then an -/// [error](crate::error::ArchiveError) is returned. +/// [error](crate::error::Error) is returned. /// /// Returns the archive bytes and the archive hash. pub async fn get_archive(version: &Version) -> Result<(Version, Bytes, String)> { @@ -187,7 +187,7 @@ pub async fn get_archive(version: &Version) -> Result<(Version, Bytes, String)> /// Gets the archive for a given [version](Version) of PostgreSQL and /// [target](https://doc.rust-lang.org/nightly/rustc/platform-support.html). /// If the [version](Version) or [target](https://doc.rust-lang.org/nightly/rustc/platform-support.html) -/// is not found, then an [error](crate::error::ArchiveError) is returned. +/// is not found, then an [error](crate::error::Error) is returned. /// /// Returns the archive bytes and the archive hash. pub async fn get_archive_for_target>( diff --git a/postgresql_archive/src/blocking/mod.rs b/postgresql_archive/src/blocking/mod.rs index ea2f377..5cfd662 100644 --- a/postgresql_archive/src/blocking/mod.rs +++ b/postgresql_archive/src/blocking/mod.rs @@ -9,7 +9,7 @@ lazy_static! { /// Gets the version of PostgreSQL for the specified [version](Version). If the version minor or release is not /// specified, then the latest version is returned. If a release for the [version](Version) is not found, then a -/// [ReleaseNotFound](crate::ArchiveError::ReleaseNotFound) error is returned. +/// [ReleaseNotFound](crate::Error::ReleaseNotFound) error is returned. pub fn get_version(version: &Version) -> crate::Result { RUNTIME .handle() @@ -18,7 +18,7 @@ pub fn get_version(version: &Version) -> crate::Result { /// Gets the archive for a given [version](Version) of PostgreSQL for the current target. /// If the [version](Version) is not found for this target, then an -/// [error](crate::ArchiveError) is returned. +/// [error](crate::Error) is returned. /// /// Returns the archive bytes and the archive hash. pub fn get_archive(version: &Version) -> crate::Result<(Version, Bytes, String)> { @@ -30,7 +30,7 @@ pub fn get_archive(version: &Version) -> crate::Result<(Version, Bytes, String)> /// Gets the archive for a given [version](Version) of PostgreSQL and /// [target](https://doc.rust-lang.org/nightly/rustc/platform-support.html). /// If the [version](Version) or [target](https://doc.rust-lang.org/nightly/rustc/platform-support.html) -/// is not found, then an [error](crate::error::ArchiveError) is returned. +/// is not found, then an [error](crate::error::Error) is returned. /// /// Returns the archive bytes and the archive hash. pub fn get_archive_for_target>( diff --git a/postgresql_archive/src/error.rs b/postgresql_archive/src/error.rs index 848a887..def996a 100644 --- a/postgresql_archive/src/error.rs +++ b/postgresql_archive/src/error.rs @@ -1,11 +1,9 @@ -use thiserror::Error; - /// PostgreSQL archive result type -pub type Result = core::result::Result; +pub type Result = core::result::Result; /// PostgreSQL archive errors -#[derive(Debug, Error)] -pub enum ArchiveError { +#[derive(Debug, thiserror::Error)] +pub enum Error { /// Asset not found #[error("asset [{0}] not found")] AssetNotFound(String), @@ -29,45 +27,45 @@ pub enum ArchiveError { Unexpected(String), } -/// Converts a [`regex::Error`] into an [`ParseError`](ArchiveError::ParseError) -impl From for ArchiveError { +/// Converts a [`regex::Error`] into an [`ParseError`](Error::ParseError) +impl From for Error { fn from(error: regex::Error) -> Self { - ArchiveError::ParseError(error.into()) + Error::ParseError(error.into()) } } -/// Converts a [`reqwest::Error`] into an [`IoError`](ArchiveError::IoError) -impl From for ArchiveError { +/// Converts a [`reqwest::Error`] into an [`IoError`](Error::IoError) +impl From for Error { fn from(error: reqwest::Error) -> Self { - ArchiveError::IoError(error.into()) + Error::IoError(error.into()) } } -/// Converts a [`std::io::Error`] into an [`IoError`](ArchiveError::IoError) -impl From for ArchiveError { +/// Converts a [`std::io::Error`] into an [`IoError`](Error::IoError) +impl From for Error { fn from(error: std::io::Error) -> Self { - ArchiveError::IoError(error.into()) + Error::IoError(error.into()) } } -/// Converts a [`std::num::ParseIntError`] into an [`ParseError`](ArchiveError::ParseError) -impl From for ArchiveError { +/// Converts a [`std::num::ParseIntError`] into an [`ParseError`](Error::ParseError) +impl From for Error { fn from(error: std::num::ParseIntError) -> Self { - ArchiveError::ParseError(error.into()) + Error::ParseError(error.into()) } } -/// Converts a [`std::path::StripPrefixError`] into an [`ParseError`](ArchiveError::ParseError) -impl From for ArchiveError { +/// Converts a [`std::path::StripPrefixError`] into an [`ParseError`](Error::ParseError) +impl From for Error { fn from(error: std::path::StripPrefixError) -> Self { - ArchiveError::ParseError(error.into()) + Error::ParseError(error.into()) } } -/// Converts a [`anyhow::Error`] into an [`Unexpected`](ArchiveError::Unexpected) -impl From for ArchiveError { +/// Converts a [`anyhow::Error`] into an [`Unexpected`](Error::Unexpected) +impl From for Error { fn from(error: anyhow::Error) -> Self { - ArchiveError::Unexpected(error.to_string()) + Error::Unexpected(error.to_string()) } } @@ -82,7 +80,7 @@ mod test { #[test] fn test_from_regex_error() { let regex_error = regex::Error::Syntax("test".to_string()); - let error = ArchiveError::from(regex_error); + let error = Error::from(regex_error); assert_eq!(error.to_string(), "test"); } @@ -91,7 +89,7 @@ mod test { let result = reqwest::get("https://a.com").await; assert!(result.is_err()); if let Err(error) = result { - let error = ArchiveError::from(error); + let error = Error::from(error); assert!(error.to_string().contains("https://a.com")); } } @@ -99,7 +97,7 @@ mod test { #[test] fn test_from_io_error() { let io_error = std::io::Error::new(std::io::ErrorKind::NotFound, "test"); - let error = ArchiveError::from(io_error); + let error = Error::from(io_error); assert_eq!(error.to_string(), "test"); } @@ -108,7 +106,7 @@ mod test { let result = u64::from_str("test"); assert!(result.is_err()); if let Err(error) = result { - let error = ArchiveError::from(error); + let error = Error::from(error); assert_eq!(error.to_string(), "invalid digit found in string"); } } @@ -119,7 +117,7 @@ mod test { let result = path.strip_prefix("foo"); assert!(result.is_err()); if let Err(error) = result { - let error = ArchiveError::from(error); + let error = Error::from(error); assert_eq!(error.to_string(), "prefix not found"); } } @@ -127,7 +125,7 @@ mod test { #[test] fn test_from_anyhow_error() { let anyhow_error = anyhow::Error::msg("test"); - let error = ArchiveError::from(anyhow_error); + let error = Error::from(anyhow_error); assert_eq!(error.to_string(), "test"); } } diff --git a/postgresql_archive/src/lib.rs b/postgresql_archive/src/lib.rs index ac2ac8d..c1f8103 100644 --- a/postgresql_archive/src/lib.rs +++ b/postgresql_archive/src/lib.rs @@ -114,6 +114,6 @@ mod github; mod version; pub use archive::{extract, get_archive, get_archive_for_target, get_version}; -pub use error::{ArchiveError, Result}; +pub use error::{Error, Result}; #[allow(deprecated)] pub use version::{Version, LATEST, V12, V13, V14, V15, V16}; diff --git a/postgresql_archive/src/version.rs b/postgresql_archive/src/version.rs index b38a161..f0c1466 100644 --- a/postgresql_archive/src/version.rs +++ b/postgresql_archive/src/version.rs @@ -1,8 +1,8 @@ //! PostgreSQL version #![allow(dead_code)] -use crate::error::ArchiveError::InvalidVersion; -use crate::error::{ArchiveError, Result}; +use crate::error::Error::InvalidVersion; +use crate::error::{Error, Result}; use serde::{Deserialize, Serialize}; use std::fmt; use std::str::FromStr; @@ -98,7 +98,7 @@ impl fmt::Display for Version { } impl FromStr for Version { - type Err = ArchiveError; + type Err = Error; fn from_str(version: &str) -> Result { let parts: Vec<&str> = version.split('.').collect(); diff --git a/postgresql_embedded/src/command/traits.rs b/postgresql_embedded/src/command/traits.rs index e985b9e..5fc8d7b 100644 --- a/postgresql_embedded/src/command/traits.rs +++ b/postgresql_embedded/src/command/traits.rs @@ -103,7 +103,7 @@ impl CommandExecutor for std::process::Command { if output.status.success() { Ok((stdout, stderr)) } else { - Err(crate::EmbeddedError::CommandError { stdout, stderr }) + Err(crate::Error::CommandError { stdout, stderr }) } } } @@ -137,7 +137,7 @@ impl CommandExecutor for tokio::process::Command { if output.status.success() { Ok((stdout, stderr)) } else { - Err(crate::EmbeddedError::CommandError { stdout, stderr }) + Err(crate::Error::CommandError { stdout, stderr }) } } } diff --git a/postgresql_embedded/src/error.rs b/postgresql_embedded/src/error.rs index a4de67c..dbb7328 100644 --- a/postgresql_embedded/src/error.rs +++ b/postgresql_embedded/src/error.rs @@ -1,13 +1,11 @@ -use postgresql_archive::ArchiveError; use std::string::FromUtf8Error; -use thiserror::Error; /// PostgreSQL embedded result type -pub type Result = core::result::Result; +pub type Result = core::result::Result; /// Errors that can occur when using PostgreSQL embedded -#[derive(Debug, Error)] -pub enum EmbeddedError { +#[derive(Debug, thiserror::Error)] +pub enum Error { /// Error when PostgreSQL archive operations fail #[error(transparent)] ArchiveError(anyhow::Error), @@ -46,32 +44,32 @@ pub enum EmbeddedError { TimeoutError(anyhow::Error), } -/// Convert PostgreSQL [archive errors](ArchiveError) to an [embedded errors](EmbeddedError::ArchiveError) -impl From for EmbeddedError { - fn from(error: ArchiveError) -> Self { - EmbeddedError::ArchiveError(error.into()) +/// Convert PostgreSQL [archive errors](postgresql_archive::Error) to an [embedded errors](Error::ArchiveError) +impl From for Error { + fn from(error: postgresql_archive::Error) -> Self { + Error::ArchiveError(error.into()) } } -/// Convert [standard IO errors](std::io::Error) to a [embedded errors](EmbeddedError::IoError) -impl From for EmbeddedError { +/// Convert [standard IO errors](std::io::Error) to a [embedded errors](Error::IoError) +impl From for Error { fn from(error: std::io::Error) -> Self { - EmbeddedError::IoError(error.into()) + Error::IoError(error.into()) } } -/// Convert [utf8 errors](FromUtf8Error) to [embedded errors](EmbeddedError::IoError) -impl From for EmbeddedError { +/// Convert [utf8 errors](FromUtf8Error) to [embedded errors](Error::IoError) +impl From for Error { fn from(error: FromUtf8Error) -> Self { - EmbeddedError::IoError(error.into()) + Error::IoError(error.into()) } } #[cfg(feature = "tokio")] -/// Convert [elapsed time errors](tokio::time::error::Elapsed) to [embedded errors](EmbeddedError::TimeoutError) -impl From for EmbeddedError { +/// Convert [elapsed time errors](tokio::time::error::Elapsed) to [embedded errors](Error::TimeoutError) +impl From for Error { fn from(error: tokio::time::error::Elapsed) -> Self { - EmbeddedError::TimeoutError(error.into()) + Error::TimeoutError(error.into()) } } @@ -83,15 +81,15 @@ mod test { #[test] fn test_from_archive_error() { - let archive_error = ArchiveError::ReleaseNotFound("test".to_string()); - let error = EmbeddedError::from(archive_error); + let archive_error = postgresql_archive::Error::ReleaseNotFound("test".to_string()); + let error = Error::from(archive_error); assert_eq!(error.to_string(), "release not found for version [test]"); } #[test] fn test_from_io_error() { let io_error = std::io::Error::new(std::io::ErrorKind::Other, "test"); - let error = EmbeddedError::from(io_error); + let error = Error::from(io_error); assert_eq!(error.to_string(), "test"); } @@ -101,7 +99,7 @@ mod test { let result = String::from_utf8(invalid_utf8); assert!(result.is_err()); if let Err(error) = result { - let error = EmbeddedError::from(error); + let error = Error::from(error); assert_eq!( error.to_string(), "invalid utf-8 sequence of 1 bytes from index 1" @@ -118,7 +116,7 @@ mod test { .await; assert!(result.is_err()); if let Err(elapsed_error) = result { - let error = EmbeddedError::from(elapsed_error); + let error = Error::from(elapsed_error); assert_eq!(error.to_string(), "deadline has elapsed"); } } diff --git a/postgresql_embedded/src/lib.rs b/postgresql_embedded/src/lib.rs index 00e46ec..59ce166 100644 --- a/postgresql_embedded/src/lib.rs +++ b/postgresql_embedded/src/lib.rs @@ -115,6 +115,6 @@ mod error; mod postgresql; mod settings; -pub use error::{EmbeddedError, Result}; +pub use error::{Error, Result}; pub use postgresql::{PostgreSQL, Status}; pub use settings::Settings; diff --git a/postgresql_embedded/src/postgresql.rs b/postgresql_embedded/src/postgresql.rs index a425959..60c83c6 100644 --- a/postgresql_embedded/src/postgresql.rs +++ b/postgresql_embedded/src/postgresql.rs @@ -3,7 +3,7 @@ use crate::command::pg_ctl::Mode::{Start, Stop}; use crate::command::pg_ctl::PgCtlBuilder; use crate::command::pg_ctl::ShutdownMode::Fast; use crate::command::traits::{CommandBuilder, CommandExecutor}; -use crate::error::EmbeddedError::{ +use crate::error::Error::{ ArchiveHashMismatch, ArchiveNotFound, DatabaseInitializationError, DatabaseStartError, DatabaseStopError, }; @@ -23,7 +23,7 @@ use std::str::FromStr; use tracing::{debug, info}; use crate::command::psql::PsqlBuilder; -use crate::EmbeddedError::{CreateDatabaseError, DatabaseExistsError, DropDatabaseError}; +use crate::Error::{CreateDatabaseError, DatabaseExistsError, DropDatabaseError}; #[cfg(feature = "bundled")] lazy_static::lazy_static! {