From ffb4071b7aa5bd5955b59afb1835635a8a59b65c Mon Sep 17 00:00:00 2001 From: vuvoth Date: Wed, 14 Feb 2024 19:04:24 +0700 Subject: [PATCH] Feat:recovereable error functions in scope src/cli (#1106) * fix clippy unwrap in src/cli * apply suggestion --- src/cli/mod.rs | 2 +- src/cli/repl/meta_cmd.rs | 8 ++++---- src/cli/repl/mod.rs | 20 ++++++++++++-------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index f88adfb7ed..b7aace4e0a 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -347,7 +347,7 @@ impl ReplCli { // Initializes CLI config with CLI arguments as overrides let config = cli_config(self.config.as_ref(), Some(&cli_settings)); - create_lurk_dirs().unwrap(); + create_lurk_dirs()?; let rc = config.rc; let limit = config.limit; diff --git a/src/cli/repl/meta_cmd.rs b/src/cli/repl/meta_cmd.rs index 03d3864570..01109ba812 100644 --- a/src/cli/repl/meta_cmd.rs +++ b/src/cli/repl/meta_cmd.rs @@ -531,10 +531,10 @@ where } let open = repl.store.intern_lurk_symbol("open"); let open_expr = repl.store.list(vec![open, repl.store.num(hash)]); - let (args_vec, _) = repl - .store - .fetch_list(&args) - .expect("data must have been interned"); + let Some((args_vec, _)) = repl.store.fetch_list(&args) else { + bail!("Data must have been interned"); + }; + let mut expr_vec = Vec::with_capacity(args_vec.len() + 1); expr_vec.push(open_expr); expr_vec.extend(args_vec); diff --git a/src/cli/repl/mod.rs b/src/cli/repl/mod.rs index bb55493174..27a5d9b1b7 100644 --- a/src/cli/repl/mod.rs +++ b/src/cli/repl/mod.rs @@ -469,11 +469,13 @@ where self.limit, )?; let iterations = frames.len(); - let output = frames - .last() - .expect("evaluation should return at least one frame") - .output - .clone(); + + let Some(last_frames) = frames.last() else { + // TODO: better error decs + bail!("Frames is empty"); + }; + + let output = last_frames.output.clone(); self.evaluation = Some(Evaluation { frames, iterations }); Ok((output, iterations)) } @@ -584,16 +586,18 @@ where let mut input = parser::Span::new(&input); loop { - let file_dir = file_path.parent().unwrap(); + let Some(file_dir) = file_path.parent() else { + bail!("Can't load parent of {}", file_path); + }; + match self.handle_form(input, file_dir, demo) { Ok(new_input) => input = new_input, Err(e) => { if let Some(parser::Error::NoInput) = e.downcast_ref::() { // It's ok, it just means we've hit the EOF return Ok(()); - } else { - return Err(e); } + return Err(e); } } }