Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
radicle: Fix panic when reading from SQLite database fails
Merged lorenz opened 8 months ago

I was greeted by rad patch redact with

called `Result::unwrap()` on an `Err` value:

  Error { code: None, message: Some("failed to convert") }

stack backtrace:

[…]
   3: core::result::Result<T,E>::unwrap
         at …/rust-1.88.0/lib/rustlib/src/rust/library/core/src/result.rs:1137:23
   4: sqlite::cursor::Row::read
         at …/index.crates.io-1949cf8c6b5b557f/sqlite-0.32.0/src/cursor.rs:136:9
   5: radicle::cob::patch::cache::query::find_by_revision
         at ./crates/radicle/src/cob/patch/cache.rs:624:65
   6: <… as radicle::cob::patch::cache::Patches>::find_by_revision
         at ./crates/radicle/src/cob/patch/cache.rs:553:9
   7: radicle_cli::commands::rad_patch::redact::run
         at ./crates/radicle-cli/src/commands/patch/redact.rs:23:9
   8: radicle_cli::commands::rad_patch::run
         at ./crates/radicle-cli/src/commands/patch.rs:1026:13
[…]

It turns out that sqlite::cursor::Row::read is the panicky version of sqlite::cursor::Row::try_read (which returns a Result).

While it is somewhat rare that SQLite reads fail, it is not unheard of. In radicle-cli it might not be critical, but also radicle-protocol and radicle-fetch are affected, and they could potentially panic a radicle-node process.

Use try_read instead, and propagate down the error handling.

lorenz opened with revision 1b5103d1 on base 19a262d3 +230 -141 8 months ago

I was greeted by rad patch redact with

called `Result::unwrap()` on an `Err` value:

  Error { code: None, message: Some("failed to convert") }

stack backtrace:

[…]
   3: core::result::Result<T,E>::unwrap
         at …/rust-1.88.0/lib/rustlib/src/rust/library/core/src/result.rs:1137:23
   4: sqlite::cursor::Row::read
         at …/index.crates.io-1949cf8c6b5b557f/sqlite-0.32.0/src/cursor.rs:136:9
   5: radicle::cob::patch::cache::query::find_by_revision
         at ./crates/radicle/src/cob/patch/cache.rs:624:65
   6: <… as radicle::cob::patch::cache::Patches>::find_by_revision
         at ./crates/radicle/src/cob/patch/cache.rs:553:9
   7: radicle_cli::commands::rad_patch::redact::run
         at ./crates/radicle-cli/src/commands/patch/redact.rs:23:9
   8: radicle_cli::commands::rad_patch::run
         at ./crates/radicle-cli/src/commands/patch.rs:1026:13
[…]

It turns out that sqlite::cursor::Row::read is the panicky version of sqlite::cursor::Row::try_read (which returns a Result).

While it is somewhat rare that SQLite reads fail, it is not unheard of. In radicle-cli it might not be critical, but also radicle-protocol and radicle-fetch are affected, and they could potentially panic a radicle-node process.

Use try_read instead, and propagate down the error handling.

lorenz pushed revision 2 30b728c3 on base a4d83ec8 +242 -144 8 months ago

Also handle that one case where I was lazy and .ok()’d

fintohaps pushed revision 3 5970fcd8 on base a568e7f4 +242 -144 8 months ago

Rebased

fintohaps merged revision 5970fcd8 at 192cc993 8 months ago