summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-07-18 01:12:36 -0400
committerOwen Jacobson <owen@grimoire.ca>2025-07-22 18:19:15 -0400
commit792de8e49fa8a3c04bfb747adadf71572d753055 (patch)
tree98b1c0f92a35d91dafc2dd7b56b32260a3d2b6d9
parenta5df5a88400e64ea752c396bfbea868df2f3f714 (diff)
Remove `pilcrow::cli::Error` from the lib crate's public interface.
This might be the pettiest rude change I've ever made to a Rust program. If I saw this - or did this - in code _intend_ to be used as a library, I'd be appalled.
-rw-r--r--src/cli.rs13
-rw-r--r--src/db/mod.rs8
-rw-r--r--src/main.rs2
-rw-r--r--src/umask.rs4
4 files changed, 5 insertions, 22 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 8dac8ff..703bf19 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -84,11 +84,10 @@ impl Args {
/// # Errors
///
/// Will return `Err` if the server is unable to start, or terminates
- /// prematurely. The specific [`Error`] variant will expose the cause
+ /// prematurely. The returned error contains a user-facing explanation
/// of the failure.
- pub async fn run(self) -> Result<(), Error> {
+ pub async fn run(self) -> Result<(), impl std::error::Error> {
self.umask.set();
-
let pool = self.pool().await?;
let app = App::from(pool);
@@ -104,7 +103,7 @@ impl Args {
println!("{started_msg}");
serve.await?;
- Ok(())
+ Result::<_, Error>::Ok(())
}
async fn listener(&self) -> io::Result<net::TcpListener> {
@@ -138,14 +137,10 @@ fn started_msg(listener: &net::TcpListener) -> io::Result<String> {
Ok(format!("listening on http://{local_addr}/"))
}
-/// Errors that can be raised by [`Args::run`].
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
-pub enum Error {
- /// Failure due to an I/O-related error.
+enum Error {
Io(#[from] io::Error),
- /// Failure due to a database initialization error.
Database(#[from] db::Error),
- /// Failure due to invalid umask-related options.
Umask(#[from] umask::Error),
}
diff --git a/src/db/mod.rs b/src/db/mod.rs
index 632cd9c..99b8986 100644
--- a/src/db/mod.rs
+++ b/src/db/mod.rs
@@ -102,16 +102,12 @@ async fn migration_replaced(
Ok(())
}
-/// Errors occurring during database setup.
#[derive(Debug, thiserror::Error)]
pub enum Error {
- /// Failure due to a database error. See [`sqlx::Error`].
#[error(transparent)]
Database(#[from] sqlx::Error),
- /// Failure because an existing database backup already exists.
#[error("backup from a previous failed migration already exists: {0}")]
BackupExists(String),
- /// Failure due to a database backup error. See [`backup::Error`].
#[error(transparent)]
Backup(#[from] backup::Error),
#[error("migration failed: {1}\nrestoring backup failed: {0}")]
@@ -120,12 +116,8 @@ pub enum Error {
"migration failed: {1}\nrestoring from backup succeeded, but deleting backup failed: {0}"
)]
Drop(sqlx::Error, sqlx::migrate::MigrateError),
- /// Failure due to a database migration error. See
- /// [`sqlx::migrate::MigrateError`].
#[error(transparent)]
Migration(#[from] sqlx::migrate::MigrateError),
- /// Failure because the database contains a migration from an unsupported
- /// schema version.
#[error("database contains rejected migration {0}:{1}, move it aside")]
Rejected(String, String),
}
diff --git a/src/main.rs b/src/main.rs
index 427294e..b8981d0 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,7 +3,7 @@ use clap::Parser;
use pilcrow::cli;
#[tokio::main]
-async fn main() -> Result<(), cli::Error> {
+async fn main() -> Result<(), impl std::error::Error> {
let args = cli::Args::parse();
args.run().await
}
diff --git a/src/umask.rs b/src/umask.rs
index 32a82ad..6aef33a 100644
--- a/src/umask.rs
+++ b/src/umask.rs
@@ -100,15 +100,11 @@ impl fmt::Display for Umask {
}
}
-/// Errors occurring during umask option parsing.
#[derive(Debug, thiserror::Error)]
pub enum Error {
- /// Failed to parse a umask value from the input.
#[error(transparent)]
Parse(#[from] std::num::ParseIntError),
- /// The provided umask contained invalid bits. (See the constants associated with [`Mode`] for
- /// valid umask bits.)
// We dont need to hold onto the actual umask value here - Clap does that for us, and prints
// the value as the user input it, which beats anything we could do here.
#[error("unknown bits in umask")]