Skip to content

Commit

Permalink
fix model skip on not ready
Browse files Browse the repository at this point in the history
  • Loading branch information
aprxi committed Aug 14, 2024
1 parent 22b8d0e commit e5510c0
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,15 @@ async fn select_model(
}
Err(ApplicationError::NotReady(msg)) => {
println!("Error: {}", msg);
if let Err(e) = handle_not_ready() {
return Err(e);
match handle_not_ready()? {
ModelSelection::Reload => continue,
ModelSelection::Quit => {
return Err(ApplicationError::UserCancelled(
"Model selection cancelled by user".to_string(),
))
}
ModelSelection::Skip => return Ok(None),
_ => unreachable!(),
}
}
Err(e) => return Err(e), // propagate other errors
Expand Down Expand Up @@ -164,24 +171,19 @@ fn select_model_from_list(
}
}

fn handle_not_ready() -> Result<(), ApplicationError> {
fn handle_not_ready() -> Result<ModelSelection, ApplicationError> {
loop {
print!(
"Press Enter to retry, 'q' to quit, or 's' to skip model \
selection: "
"Press Enter to retry, 'q' to quit, or 's' to skip model selection: "
);
io::stdout().flush()?;
let mut input = String::new();
io::stdin().read_line(&mut input)?;

match input.trim().to_lowercase().as_str() {
"" => return Ok(()),
"q" => {
return Err(ApplicationError::UserCancelled(
"Model selection cancelled by user".to_string(),
))
}
"s" => return Ok(()),
"" => return Ok(ModelSelection::Reload),
"q" => return Ok(ModelSelection::Quit),
"s" => return Ok(ModelSelection::Skip),
_ => println!("Invalid input. Please try again."),
}
}
Expand Down

0 comments on commit e5510c0

Please sign in to comment.