From 1fe1f0ebba0fcd794b6400c8e7c3df35c6036037 Mon Sep 17 00:00:00 2001 From: Jussi Saurio Date: Tue, 15 Apr 2025 13:16:28 +0300 Subject: [PATCH] ProgramBuilder: add resolve_cursor_id_safe() which doesn't unwrap --- core/vdbe/builder.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/core/vdbe/builder.rs b/core/vdbe/builder.rs index 03c634d07..648044d1d 100644 --- a/core/vdbe/builder.rs +++ b/core/vdbe/builder.rs @@ -441,15 +441,17 @@ impl ProgramBuilder { } // translate table to cursor id + pub fn resolve_cursor_id_safe(&self, table_identifier: &str) -> Option { + self.cursor_ref.iter().position(|(t_ident, _)| { + t_ident + .as_ref() + .is_some_and(|ident| ident == table_identifier) + }) + } + pub fn resolve_cursor_id(&self, table_identifier: &str) -> CursorID { - self.cursor_ref - .iter() - .position(|(t_ident, _)| { - t_ident - .as_ref() - .is_some_and(|ident| ident == table_identifier) - }) - .unwrap() + self.resolve_cursor_id_safe(table_identifier) + .unwrap_or_else(|| panic!("Cursor not found: {}", table_identifier)) } pub fn build(