Skip to content

Commit 81dbed4

Browse files
committed
feat: migrate anywho to thiserror
1 parent 55f4e2c commit 81dbed4

File tree

10 files changed

+27
-11
lines changed

10 files changed

+27
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ sqlx = { version = "0.8", features = [
2323
tokio = { version = "1", features = ["full"] }
2424
clap = { version = "4", features = ["derive", "env"] }
2525
heck = "0.5"
26-
anyhow = "1"
26+
thiserror = "2"
2727
quote = "1"
2828
proc-macro2 = "1"
2929
syn = "2"

src/cli.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub enum DatabaseKind {
5454
}
5555

5656
impl Args {
57-
pub fn database_kind(&self) -> anyhow::Result<DatabaseKind> {
57+
pub fn database_kind(&self) -> crate::error::Result<DatabaseKind> {
5858
let url = &self.database_url;
5959
if url.starts_with("postgres://") || url.starts_with("postgresql://") {
6060
Ok(DatabaseKind::Postgres)
@@ -63,9 +63,9 @@ impl Args {
6363
} else if url.starts_with("sqlite://") || url.starts_with("sqlite:") {
6464
Ok(DatabaseKind::Sqlite)
6565
} else {
66-
anyhow::bail!(
67-
"Cannot detect database type from URL. Expected postgres://, mysql://, or sqlite:// prefix."
68-
)
66+
Err(crate::error::Error::Config(
67+
"Cannot detect database type from URL. Expected postgres://, mysql://, or sqlite:// prefix.".to_string(),
68+
))
6969
}
7070
}
7171

src/error.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std::io;
2+
3+
#[derive(Debug, thiserror::Error)]
4+
pub enum Error {
5+
#[error("Database error: {0}")]
6+
Database(#[from] sqlx::Error),
7+
8+
#[error("IO error: {0}")]
9+
Io(#[from] io::Error),
10+
11+
#[error("{0}")]
12+
Config(String),
13+
}
14+
15+
pub type Result<T> = std::result::Result<T, Error>;

src/introspect/mysql.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use crate::error::Result;
22
use sqlx::MySqlPool;
33

44
use super::{ColumnInfo, EnumInfo, SchemaInfo, TableInfo};

src/introspect/postgres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use crate::error::Result;
22
use sqlx::PgPool;
33

44
use super::{ColumnInfo, CompositeTypeInfo, DomainInfo, EnumInfo, SchemaInfo, TableInfo};

src/introspect/sqlite.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use crate::error::Result;
22
use sqlx::SqlitePool;
33

44
use super::{ColumnInfo, SchemaInfo, TableInfo};

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod cli;
22
pub mod codegen;
3+
pub mod error;
34
pub mod introspect;
45
pub mod typemap;
56
pub mod writer;

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Result;
1+
use sqlx_gen::error::Result;
22
use clap::Parser;
33
use sqlx::{MySqlPool, PgPool, SqlitePool};
44

src/writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::path::Path;
22

3-
use anyhow::Result;
3+
use crate::error::Result;
44

55
use crate::codegen::GeneratedFile;
66

0 commit comments

Comments
 (0)