Skip to content

Commit

Permalink
Merge pull request #2577 from dathere/describegpt-model-validation-er…
Browse files Browse the repository at this point in the history
…r-handling

fix: `describegpt` add error handling when LLM API response format is not in expected format
  • Loading branch information
jqnatividad authored Mar 5, 2025
2 parents 32e6475 + 62043d6 commit 50b98d9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cmd/describegpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,14 @@ fn is_valid_model(
} else {
args.flag_model.clone().unwrap()
};
let models = response_json["data"].as_array().unwrap();
let models = match response_json["data"].as_array() {
Some(models) => models,
None => {
return fail_clierror!(
"Invalid response: 'data' field is not an array or is missing\n{response_json:?}"
)
},
};
for model in models {
if model["id"].as_str().unwrap() == given_model {
return Ok(true);
Expand Down

0 comments on commit 50b98d9

Please sign in to comment.