From dca16f5936d264662b0c856c4431d8d107a64c61 Mon Sep 17 00:00:00 2001 From: Elias Renman Date: Sun, 7 May 2023 15:50:39 +0200 Subject: [PATCH] fix: improved table insert_row method --- src/database/table.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/database/table.rs b/src/database/table.rs index 4eff558..b42fd01 100644 --- a/src/database/table.rs +++ b/src/database/table.rs @@ -28,17 +28,17 @@ impl Table { self.indexes.insert(key, index); } - pub fn insert_row(&mut self, row: Row) -> Result<(), &str> { + pub fn insert_row(&mut self, row: Row) -> Result<(), String> { let key_option = row.get(&self.pk); if key_option.is_none() { - panic!("Primary key not found on row to insert!"); + return Err("Primary key not found on row to insert!".to_string()); } let row_primary_key = key_option.unwrap().as_u64(); if row_primary_key.is_none() { - panic!("Primary key is not of type u64"); + return Err("Primary key is not of type u64".to_string()); } // Insert row into database @@ -52,10 +52,10 @@ impl Table { Entry::Occupied(mut e) => { let result = e.get_mut().insert_row(self.pk.clone(), row.clone()); if result.is_err() { - panic!( + return Err(format!( "Failed writing to index with erro: {}", result.err().unwrap() - ); + )); } } Entry::Vacant(_e) => {}