diff options
| author | John Oxley <john.oxley@gmail.com> | 2026-05-14 22:53:32 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-14 14:53:32 -0700 |
| commit | d98ecd58af9f6d850461b8bef430dfef70111692 (patch) | |
| tree | 7b83a7718fa3b3a742134a9700b29330deafc400 /scripts/release.sh | |
| parent | fix(ci): fossier install in scan workflow (#3485) (diff) | |
| download | atuin-d98ecd58af9f6d850461b8bef430dfef70111692.zip | |
refactor: Implement From<sqlx::Error> and clean up fix_error (#3484)
In the database crates for atuin-server, there is `fn fix_error`. This
PR implements `From<sqlx::Error>` on `DbError` which makes it possible
to mostly use `?` to bubble up the errors.
There are cases where `?` is not being used e.g.
```rust
async fn get_session(&self, token: &str) -> DbResult<Session> {
sqlx::query_as("select id, user_id, token from sessions where token = $1")
.bind(token)
.fetch_one(&self.pool)
.await
.map_err(fix_error)
.map(|DbSession(session)| session)
}
```
There are two options
## 1. Use `Into::into`
```rust
async fn get_session(&self, token: &str) -> DbResult<Session> {
sqlx::query_as("select id, user_id, token from sessions where token = $1")
.bind(token)
.fetch_one(&self.pool)
.await
.map_err(fix_error)
.map(|DbSession(session)| session)
}
```
## 2. Create a variable and use `?`
```rust
async fn get_session(&self, token: &str) -> DbResult<Session> {
let session = sqlx::query_as("select id, user_id, token from sessions where token = $1")
.bind(token)
.fetch_one(&self.pool)
.await
.map(|DbSession(session)| session)?;
Ok(session)
}
```
I chose to do option 1 as it was just a find/replace but say the word
and I'll convert them all to option 2
## Checks
- [X] I am happy for maintainers to push small adjustments to this PR,
to speed up the review cycle
- [X] I have checked that there are no existing pull requests for the
same thing
Diffstat (limited to 'scripts/release.sh')
0 files changed, 0 insertions, 0 deletions
