Skip to content

Commit 9271ecd

Browse files
committed
feat: lookup_or_create_adhoc_group(): Add context to SQL errors (#7554)
1 parent 952f673 commit 9271ecd

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

STYLE.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ id INTEGER PRIMARY KEY AUTOINCREMENT,
1616
text TEXT DEFAULT '' NOT NULL -- message text
1717
) STRICT",
1818
)
19-
.await?;
19+
.await
20+
.context("CREATE TABLE messages")?;
2021
```
2122

2223
Do not use macros like [`concat!`](https://doc.rust-lang.org/std/macro.concat.html)
@@ -29,7 +30,8 @@ id INTEGER PRIMARY KEY AUTOINCREMENT, \
2930
text TEXT DEFAULT '' NOT NULL \
3031
) STRICT",
3132
)
32-
.await?;
33+
.await
34+
.context("CREATE TABLE messages")?;
3335
```
3436
Escaping newlines
3537
is prone to errors like this if space before backslash is missing:
@@ -63,6 +65,9 @@ an older version. Also don't change the column type, consider adding a new colum
6365
instead. Finally, never change column semantics, this is especially dangerous because the `STRICT`
6466
keyword doesn't help here.
6567

68+
Consider adding context to `anyhow` errors for SQL statements using `.context()` so that it's
69+
possible to understand from logs which statement failed. See [Errors](#errors) for more info.
70+
6671
## Errors
6772

6873
Delta Chat core mostly uses [`anyhow`](https://docs.rs/anyhow/) errors.

src/receive_imf.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,10 +2506,11 @@ async fn lookup_or_create_adhoc_group(
25062506
id INTEGER PRIMARY KEY
25072507
) STRICT",
25082508
(),
2509-
)?;
2509+
)
2510+
.context("CREATE TEMP TABLE temp.contacts")?;
25102511
let mut stmt = t.prepare("INSERT INTO temp.contacts(id) VALUES (?)")?;
25112512
for &id in &contact_ids {
2512-
stmt.execute((id,))?;
2513+
stmt.execute((id,)).context("INSERT INTO temp.contacts")?;
25132514
}
25142515
let val = t
25152516
.query_row(
@@ -2531,8 +2532,10 @@ async fn lookup_or_create_adhoc_group(
25312532
Ok((id, blocked))
25322533
},
25332534
)
2534-
.optional()?;
2535-
t.execute("DROP TABLE temp.contacts", ())?;
2535+
.optional()
2536+
.context("Select chat with matching name and members")?;
2537+
t.execute("DROP TABLE temp.contacts", ())
2538+
.context("DROP TABLE temp.contacts")?;
25362539
Ok(val)
25372540
};
25382541
let query_only = true;

0 commit comments

Comments
 (0)