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 all 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
8 changes: 4 additions & 4 deletions src/cli/repl/meta_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 12 additions & 8 deletions src/cli/repl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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::<parser::Error>() {
// It's ok, it just means we've hit the EOF
return Ok(());
} else {
return Err(e);
}
return Err(e);
}
}
}
Expand Down
Loading