diff --git a/STYLE.md b/STYLE.md index c67f77102..719a6d9dc 100644 --- a/STYLE.md +++ b/STYLE.md @@ -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. diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 6f89b66a3..35dfbcbc9 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -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;