mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
feat: lookup_or_create_adhoc_group(): Add context to SQL errors (#7554)
This commit is contained in:
9
STYLE.md
9
STYLE.md
@@ -16,7 +16,8 @@ id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|||||||
text TEXT DEFAULT '' NOT NULL -- message text
|
text TEXT DEFAULT '' NOT NULL -- message text
|
||||||
) STRICT",
|
) STRICT",
|
||||||
)
|
)
|
||||||
.await?;
|
.await
|
||||||
|
.context("CREATE TABLE messages")?;
|
||||||
```
|
```
|
||||||
|
|
||||||
Do not use macros like [`concat!`](https://doc.rust-lang.org/std/macro.concat.html)
|
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 \
|
text TEXT DEFAULT '' NOT NULL \
|
||||||
) STRICT",
|
) STRICT",
|
||||||
)
|
)
|
||||||
.await?;
|
.await
|
||||||
|
.context("CREATE TABLE messages")?;
|
||||||
```
|
```
|
||||||
Escaping newlines
|
Escaping newlines
|
||||||
is prone to errors like this if space before backslash is missing:
|
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`
|
instead. Finally, never change column semantics, this is especially dangerous because the `STRICT`
|
||||||
keyword doesn't help here.
|
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
|
## Errors
|
||||||
|
|
||||||
Delta Chat core mostly uses [`anyhow`](https://docs.rs/anyhow/) errors.
|
Delta Chat core mostly uses [`anyhow`](https://docs.rs/anyhow/) errors.
|
||||||
|
|||||||
@@ -2506,10 +2506,11 @@ async fn lookup_or_create_adhoc_group(
|
|||||||
id INTEGER PRIMARY KEY
|
id INTEGER PRIMARY KEY
|
||||||
) STRICT",
|
) STRICT",
|
||||||
(),
|
(),
|
||||||
)?;
|
)
|
||||||
|
.context("CREATE TEMP TABLE temp.contacts")?;
|
||||||
let mut stmt = t.prepare("INSERT INTO temp.contacts(id) VALUES (?)")?;
|
let mut stmt = t.prepare("INSERT INTO temp.contacts(id) VALUES (?)")?;
|
||||||
for &id in &contact_ids {
|
for &id in &contact_ids {
|
||||||
stmt.execute((id,))?;
|
stmt.execute((id,)).context("INSERT INTO temp.contacts")?;
|
||||||
}
|
}
|
||||||
let val = t
|
let val = t
|
||||||
.query_row(
|
.query_row(
|
||||||
@@ -2531,8 +2532,10 @@ async fn lookup_or_create_adhoc_group(
|
|||||||
Ok((id, blocked))
|
Ok((id, blocked))
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.optional()?;
|
.optional()
|
||||||
t.execute("DROP TABLE temp.contacts", ())?;
|
.context("Select chat with matching name and members")?;
|
||||||
|
t.execute("DROP TABLE temp.contacts", ())
|
||||||
|
.context("DROP TABLE temp.contacts")?;
|
||||||
Ok(val)
|
Ok(val)
|
||||||
};
|
};
|
||||||
let query_only = true;
|
let query_only = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user