feat: lookup_or_create_adhoc_group(): Add context to SQL errors (#7554)

This commit is contained in:
iequidoo
2025-12-04 06:03:41 -03:00
committed by iequidoo
parent 952f6735a2
commit 9271ecd208
2 changed files with 14 additions and 6 deletions

View File

@@ -16,7 +16,8 @@ id INTEGER PRIMARY KEY AUTOINCREMENT,
text TEXT DEFAULT '' NOT NULL -- message text
) STRICT",
)
.await?;
.await
.context("CREATE TABLE messages")?;
```
Do not use macros like [`concat!`](https://doc.rust-lang.org/std/macro.concat.html)
@@ -29,7 +30,8 @@ id INTEGER PRIMARY KEY AUTOINCREMENT, \
text TEXT DEFAULT '' NOT NULL \
) STRICT",
)
.await?;
.await
.context("CREATE TABLE messages")?;
```
Escaping newlines
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
instead. Finally, never change column semantics, this is especially dangerous because the `STRICT`
keyword doesn't help here.
Consider adding context to `anyhow` errors for SQL statements using `.context()` so that it's
possible to understand from logs which statement failed. See [Errors](#errors) for more info.
## Errors
Delta Chat core mostly uses [`anyhow`](https://docs.rs/anyhow/) errors.

View File

@@ -2506,10 +2506,11 @@ async fn lookup_or_create_adhoc_group(
id INTEGER PRIMARY KEY
) STRICT",
(),
)?;
)
.context("CREATE TEMP TABLE temp.contacts")?;
let mut stmt = t.prepare("INSERT INTO temp.contacts(id) VALUES (?)")?;
for &id in &contact_ids {
stmt.execute((id,))?;
stmt.execute((id,)).context("INSERT INTO temp.contacts")?;
}
let val = t
.query_row(
@@ -2531,8 +2532,10 @@ async fn lookup_or_create_adhoc_group(
Ok((id, blocked))
},
)
.optional()?;
t.execute("DROP TABLE temp.contacts", ())?;
.optional()
.context("Select chat with matching name and members")?;
t.execute("DROP TABLE temp.contacts", ())
.context("DROP TABLE temp.contacts")?;
Ok(val)
};
let query_only = true;