Skip to content

Commit 9b0c889

Browse files
committed
Handle missing model in CLI parameters for llama-run
The HTTP client in llama-run only prints an error in case the download of a resource failed. If the model name in the CLI parameter list is missing, this causes the application to crash. In order to prevent this, a check for the required model parameter has been added and errors for resource downloads get propagated to the caller. Signed-off-by: Michael Engel <[email protected]>
1 parent a07c2c8 commit 9b0c889

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

examples/run/run.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ class Opt {
181181
}
182182
}
183183

184+
if (model_.empty()){
185+
return 1;
186+
}
187+
184188
return 0;
185189
}
186190

@@ -346,7 +350,11 @@ class HttpClient {
346350
data.file_size = set_resume_point(output_file_partial);
347351
set_progress_options(progress, data);
348352
set_headers(headers);
349-
perform(url);
353+
CURLcode res = perform(url);
354+
if (res != CURLE_OK){
355+
printe("Fetching resource '%s' failed: %s\n", url.c_str(), curl_easy_strerror(res));
356+
return 1;
357+
}
350358
if (!output_file.empty()) {
351359
std::filesystem::rename(output_file_partial, output_file);
352360
}
@@ -411,16 +419,12 @@ class HttpClient {
411419
}
412420
}
413421

414-
void perform(const std::string & url) {
415-
CURLcode res;
422+
CURLcode perform(const std::string & url) {
416423
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
417424
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
418425
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
419426
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
420-
res = curl_easy_perform(curl);
421-
if (res != CURLE_OK) {
422-
printe("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
423-
}
427+
return curl_easy_perform(curl);
424428
}
425429

426430
static std::string human_readable_time(double seconds) {

0 commit comments

Comments
 (0)