Skip to content

Commit 2b8525d

Browse files
authored
Handle missing model in CLI parameters for llama-run (#11399)
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 a4417dd commit 2b8525d

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

examples/run/run.cpp

+11-7
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

@@ -350,7 +354,11 @@ class HttpClient {
350354
data.file_size = set_resume_point(output_file_partial);
351355
set_progress_options(progress, data);
352356
set_headers(headers);
353-
perform(url);
357+
CURLcode res = perform(url);
358+
if (res != CURLE_OK){
359+
printe("Fetching resource '%s' failed: %s\n", url.c_str(), curl_easy_strerror(res));
360+
return 1;
361+
}
354362
if (!output_file.empty()) {
355363
std::filesystem::rename(output_file_partial, output_file);
356364
}
@@ -415,16 +423,12 @@ class HttpClient {
415423
}
416424
}
417425

418-
void perform(const std::string & url) {
419-
CURLcode res;
426+
CURLcode perform(const std::string & url) {
420427
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
421428
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
422429
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
423430
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
424-
res = curl_easy_perform(curl);
425-
if (res != CURLE_OK) {
426-
printe("curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
427-
}
431+
return curl_easy_perform(curl);
428432
}
429433

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

0 commit comments

Comments
 (0)