From 2043b8d65192b8c4741d2a48579117c82fc2e31a Mon Sep 17 00:00:00 2001 From: Anthony Potappel Date: Fri, 2 Aug 2024 17:41:29 +0200 Subject: [PATCH] compat fix tui 0.27, fix modified int64 error on filelist, enforce error-check --- lumni/Cargo.toml | 2 +- lumni/src/apps/builtin/llm/prompt/Cargo.toml | 2 +- .../modals/conversations/render_on_frame.rs | 2 +- lumni/src/handlers/object_store.rs | 1 - lumni/src/localfs/bucket.rs | 2 +- lumni/src/localfs/list.rs | 9 +++---- lumni/src/table/columns.rs | 7 +++++- lumni/src/table/file_object.rs | 25 ++++++++++--------- lumni/src/table/mod.rs | 4 ++- lumni/src/table/object_store.rs | 9 ++++--- 10 files changed, 36 insertions(+), 27 deletions(-) diff --git a/lumni/Cargo.toml b/lumni/Cargo.toml index 3ab79fa6..fcd69e67 100644 --- a/lumni/Cargo.toml +++ b/lumni/Cargo.toml @@ -59,7 +59,7 @@ tokio = { version = "1.12", default-features = false, features = ["rt-multi-thre # tokio = { version = "1.12", default-features = false, features = ["full"], optional = true } clap = { version = "4.2" , default-features = false, features = ["std", "help"], optional = true } crossterm = { version = "0.27", optional = true } -ratatui = { version = ">=0.26.0, <1", default-features = false, features = ["crossterm"], optional = true } +ratatui = { version = ">=0.27.0, <1", default-features = false, features = ["crossterm"], optional = true } arboard = { version = "3.2", default-features = false, optional = true } # WEB diff --git a/lumni/src/apps/builtin/llm/prompt/Cargo.toml b/lumni/src/apps/builtin/llm/prompt/Cargo.toml index 3d15349d..6f08f48f 100644 --- a/lumni/src/apps/builtin/llm/prompt/Cargo.toml +++ b/lumni/src/apps/builtin/llm/prompt/Cargo.toml @@ -13,7 +13,7 @@ env_logger = { version = "0.9" } tokio = { version = "1.12", default-features = false, features = ["rt-multi-thread", "macros"] } clap = { version = "4.2" , default-features = false, features = ["std", "help"] } crossterm = { version = "0.27" } -ratatui = { version = ">=0.26.0, <1", default-features = false, features = ["crossterm"] } +ratatui = { version = ">=0.27.0, <1", default-features = false, features = ["crossterm"] } arboard = { version = "3.2", default-features = false } lumni = { git = "https://github.com/serverlessnext/lumni", branch = "main" } diff --git a/lumni/src/apps/builtin/llm/prompt/src/tui/modals/conversations/render_on_frame.rs b/lumni/src/apps/builtin/llm/prompt/src/tui/modals/conversations/render_on_frame.rs index 99533808..8e0ca6bd 100644 --- a/lumni/src/apps/builtin/llm/prompt/src/tui/modals/conversations/render_on_frame.rs +++ b/lumni/src/apps/builtin/llm/prompt/src/tui/modals/conversations/render_on_frame.rs @@ -167,7 +167,7 @@ impl<'a> ConversationListModal<'a> { .begin_symbol(None) .end_symbol(None); - let scrollbar_area = area.inner(&Margin { + let scrollbar_area = area.inner(Margin { vertical: 1, horizontal: 0, }); diff --git a/lumni/src/handlers/object_store.rs b/lumni/src/handlers/object_store.rs index 68122439..662b3de3 100644 --- a/lumni/src/handlers/object_store.rs +++ b/lumni/src/handlers/object_store.rs @@ -282,7 +282,6 @@ impl ObjectStoreHandler { parsed_uri.scheme.to_string(), parsed_uri.bucket.as_ref().unwrap() ); - let object_store = ObjectStore::new(&bucket_uri, config).unwrap(); object_store .list_files( diff --git a/lumni/src/localfs/bucket.rs b/lumni/src/localfs/bucket.rs index 0bc7b74e..1ee0ea4b 100644 --- a/lumni/src/localfs/bucket.rs +++ b/lumni/src/localfs/bucket.rs @@ -69,7 +69,7 @@ impl ObjectStoreTrait for LocalFsBucket { filter, table, ) - .await; + .await?; Ok(()) } diff --git a/lumni/src/localfs/list.rs b/lumni/src/localfs/list.rs index 15e3d6f4..2a3255e6 100644 --- a/lumni/src/localfs/list.rs +++ b/lumni/src/localfs/list.rs @@ -8,7 +8,7 @@ use crossbeam_channel::{bounded, Sender}; use rayon::prelude::*; use crate::table::{FileObjectTable, TableColumnValue}; -use crate::{FileObject, FileObjectFilter}; +use crate::{FileObject, FileObjectFilter, InternalError}; pub async fn list_files( path: &Path, @@ -18,13 +18,12 @@ pub async fn list_files( recursive: bool, filter: &Option, table: &mut FileObjectTable, -) { +) -> Result<(), InternalError> { if let Some(columns) = selected_columns { println!("Selected columns: {:?}", columns); } let max_count = max_keys.map(|m| m as usize).unwrap_or(usize::MAX); - //let count = AtomicUsize::new(0); let count = Arc::new(AtomicUsize::new(0)); let (sender, receiver) = bounded(500); @@ -60,8 +59,9 @@ pub async fn list_files( // Batch insert all rows at once if !rows.is_empty() { - let _ = table.add_rows(rows).await; + table.add_rows(rows).await?; } + Ok(()) } fn process_directory( @@ -129,7 +129,6 @@ fn process_entry( selected_columns: &Option>, ) -> Option> { let metadata = entry.metadata().ok()?; - if metadata.is_file() { handle_file(entry, filter, selected_columns) } else if metadata.is_dir() && filter.is_none() { diff --git a/lumni/src/table/columns.rs b/lumni/src/table/columns.rs index ef2cba69..e962253b 100644 --- a/lumni/src/table/columns.rs +++ b/lumni/src/table/columns.rs @@ -91,6 +91,7 @@ macro_rules! create_column_types { create_column_types!(Int32Column, OptionalInt32Column, i32); create_column_types!(Uint64Column, OptionalUint64Column, u64); +create_column_types!(Int64Column, OptionalInt64Column, i64); create_column_types!(FloatColumn, OptionalFloatColumn, f64); create_column_types!(StringColumn, OptionalStringColumn, String); @@ -108,10 +109,14 @@ impl TableColumnValue { TableColumnValue::OptionalUint64Column(Some(val)) => { val.to_string() } + TableColumnValue::OptionalInt64Column(Some(val)) => val.to_string(), TableColumnValue::OptionalFloatColumn(Some(val)) => val.to_string(), TableColumnValue::OptionalStringColumn(Some(val)) => val.clone(), // Match any None variant for Optional types - _ => "NULL".to_string(), + _ => { + log::error!("Unexpected TableColumnValue: {:?}", self); + "NULL".to_string() + } } } } diff --git a/lumni/src/table/file_object.rs b/lumni/src/table/file_object.rs index 881b19e7..66ba733a 100644 --- a/lumni/src/table/file_object.rs +++ b/lumni/src/table/file_object.rs @@ -3,10 +3,10 @@ use std::collections::HashMap; use std::sync::Arc; use crate::table::{ - OptionalUint64Column, StringColumn, TableRow, Uint64Column, + OptionalInt64Column, StringColumn, TableRow, Uint64Column, }; use crate::utils::formatters::{bytes_human_readable, time_human_readable}; -use crate::{FileObject, Table, TableCallback, TableColumn, TableColumnValue}; +use crate::{FileObject, InternalError, Table, TableCallback, TableColumn, TableColumnValue}; pub struct FileObjectTable { columns: Vec<(String, Box)>, // Store columns in order @@ -37,7 +37,7 @@ impl FileObjectTable { .add_column("size", Box::new(Uint64Column(Vec::new()))), "modified" => table.add_column( "modified", - Box::new(OptionalUint64Column(Vec::new())), + Box::new(OptionalInt64Column(Vec::new())), ), _ => panic!("Invalid column name: {}", column), } @@ -52,7 +52,7 @@ impl FileObjectTable { .add_column("size", Box::new(Uint64Column(Vec::new()))), "modified" => table.add_column( "modified", - Box::new(OptionalUint64Column(Vec::new())), + Box::new(OptionalInt64Column(Vec::new())), ), // should not be reachable because valid_columns is hardcoded _ => panic!("Invalid column name: {}", column), @@ -87,7 +87,7 @@ impl Table for FileObjectTable { fn add_row( &mut self, row_data: Vec<(String, TableColumnValue)>, - ) -> Result<(), String> { + ) -> Result<(), InternalError> { if let Some(callback) = &self.callback { let mut row = TableRow::new(row_data.clone(), Some(&print_row)); callback.on_row_add(&mut row); @@ -98,10 +98,12 @@ impl Table for FileObjectTable { let (_, column) = &mut self.columns[index]; column.append(value)?; } else { - return Err(format!("Column '{}' not found", column_name)); + return Err(InternalError::InternalError(format!( + "Column '{}' not found", + column_name + ))); } } - Ok(()) } @@ -182,10 +184,9 @@ impl FileObjectTable { pub async fn add_file_objects( &mut self, file_objects: Vec, - ) -> Result<(), String> { + ) -> Result<(), InternalError> { for file_object in file_objects { let mut row_data: Vec<(String, TableColumnValue)> = Vec::new(); - for (column_name, _) in &self.columns { if let Some(value) = file_object.get_value_by_column_name(column_name) @@ -205,10 +206,10 @@ impl FileObjectTable { pub async fn add_rows( &mut self, rows: Vec>, - ) -> Result<(), String> { - for row_data in rows { - let mut row_vec: Vec<(String, TableColumnValue)> = Vec::new(); + ) -> Result<(), InternalError> { + for row_data in rows.iter() { + let mut row_vec: Vec<(String, TableColumnValue)> = Vec::new(); // Iterate over self.columns to maintain the defined order for (column_name, _) in &self.columns { if let Some(value) = row_data.get(column_name) { diff --git a/lumni/src/table/mod.rs b/lumni/src/table/mod.rs index c844b22d..fff7e078 100644 --- a/lumni/src/table/mod.rs +++ b/lumni/src/table/mod.rs @@ -10,6 +10,8 @@ pub use columns::*; pub use file_object::FileObjectTable; pub use object_store::ObjectStoreTable; +use crate::InternalError; + pub struct TableRow<'a> { data: Vec<(String, TableColumnValue)>, print_fn: Option<&'a (dyn Fn(&TableRow) + 'a)>, @@ -86,6 +88,6 @@ pub trait Table: Debug { fn add_row( &mut self, row_data: Vec<(String, TableColumnValue)>, - ) -> Result<(), String>; + ) -> Result<(), InternalError>; fn fmt_debug(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result; } diff --git a/lumni/src/table/object_store.rs b/lumni/src/table/object_store.rs index 78e9ce4a..568ff9b8 100644 --- a/lumni/src/table/object_store.rs +++ b/lumni/src/table/object_store.rs @@ -70,7 +70,7 @@ impl Table for ObjectStoreTable { fn add_row( &mut self, row_data: Vec<(String, TableColumnValue)>, - ) -> Result<(), String> { + ) -> Result<(), InternalError> { if let Some(callback) = &self.callback { let mut row = TableRow::new(row_data.clone(), Some(&print_row)); callback.on_row_add(&mut row); @@ -83,7 +83,10 @@ impl Table for ObjectStoreTable { { column.append(value)?; } else { - return Err(format!("Column '{}' not found", column_name)); + return Err(InternalError::InternalError(format!( + "Column {} not found in table", + column_name + ))); } } @@ -109,7 +112,7 @@ impl ObjectStoreTable { pub async fn add_object_store( &mut self, object_store: ObjectStore, - ) -> Result<(), String> { + ) -> Result<(), InternalError> { let row_data = vec![( "uri".to_string(), TableColumnValue::StringColumn(object_store.uri()),