Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat:recovereable error functions in scope src/cli #1106

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/cli/repl/meta_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,14 @@ 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 mut expr_vec = Vec::with_capacity(args_vec.len() + 1);
expr_vec.push(open_expr);
expr_vec.extend(args_vec);
repl.handle_non_meta(repl.store.list(expr_vec))
if let Some((args_vec, _)) = repl.store.fetch_list(&args) {
let mut expr_vec = Vec::with_capacity(args_vec.len() + 1);
expr_vec.push(open_expr);
expr_vec.extend(args_vec);
repl.handle_non_meta(repl.store.list(expr_vec))
} else {
Err(anyhow!("Data must have been interned"))
}
vuvoth marked this conversation as resolved.
Show resolved Hide resolved
}

const CALL: MetaCmd<F, C> = MetaCmd {
Expand Down
34 changes: 19 additions & 15 deletions src/cli/repl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,15 @@ where
self.limit,
)?;
let iterations = frames.len();
let output = frames
.last()
.expect("evaluation should return at least one frame")
.output
.clone();
self.evaluation = Some(Evaluation { frames, iterations });
Ok((output, iterations))

if let Some(last_frames) = frames.last() {
let output = last_frames.output.clone();
self.evaluation = Some(Evaluation { frames, iterations });
Ok((output, iterations))
} else {
// TODO: better error decs
Err(anyhow!("Frames is empty"))
}
}

fn get_comm_hash(&mut self, args: &Ptr) -> Result<&F> {
Expand Down Expand Up @@ -584,17 +586,19 @@ where

let mut input = parser::Span::new(&input);
loop {
let file_dir = file_path.parent().unwrap();
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::<parser::Error>() {
// It's ok, it just means we've hit the EOF
return Ok(());
} else {
if let Some(file_dir) = file_path.parent() {
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::<parser::Error>() {
// It's ok, it just means we've hit the EOF
return Ok(());
}
return Err(e);
}
}
} else {
return Err(anyhow!("Can't load parent of {}", file_path));
}
}
}
Expand Down