From: Michael Engel Date: Tue, 28 Jan 2025 08:32:40 +0000 (+0100) Subject: Handle missing model in CLI parameters for llama-run (#11399) X-Git-Tag: upstream/0.0.4631~62 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=2b8525d5c89b124c4578a2621cbeb64354ff3d9c;p=pkg%2Fggml%2Fsources%2Fllama.cpp 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 --- diff --git a/examples/run/run.cpp b/examples/run/run.cpp index 8a0db74b..5980a786 100644 --- a/examples/run/run.cpp +++ b/examples/run/run.cpp @@ -181,6 +181,10 @@ class Opt { } } + if (model_.empty()){ + return 1; + } + return 0; } @@ -350,7 +354,11 @@ class HttpClient { data.file_size = set_resume_point(output_file_partial); set_progress_options(progress, data); set_headers(headers); - perform(url); + CURLcode res = perform(url); + if (res != CURLE_OK){ + printe("Fetching resource '%s' failed: %s\n", url.c_str(), curl_easy_strerror(res)); + return 1; + } if (!output_file.empty()) { std::filesystem::rename(output_file_partial, output_file); } @@ -415,16 +423,12 @@ class HttpClient { } } - void perform(const std::string & url) { - CURLcode res; + CURLcode perform(const std::string & url) { curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https"); curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L); - res = curl_easy_perform(curl); - if (res != CURLE_OK) { - printe("curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); - } + return curl_easy_perform(curl); } static std::string human_readable_time(double seconds) {