From 4119e541dd9e0c287cd35a5739dc346874a40b30 Mon Sep 17 00:00:00 2001 From: Martin Valgur Date: Sun, 30 Jun 2024 21:08:31 +0300 Subject: [PATCH] Improve error handling in get_latest_conan_version() --- conan_provider.cmake | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/conan_provider.cmake b/conan_provider.cmake index d0065561..79f16e16 100644 --- a/conan_provider.cmake +++ b/conan_provider.cmake @@ -556,9 +556,20 @@ endfunction() function(get_latest_conan_version VERSION_VARIABLE) set(json_file "${CMAKE_BINARY_DIR}/conan_latest_release.json") - file(DOWNLOAD "https://api.github.com/repos/conan-io/conan/releases/latest" "${json_file}") - file(READ "${json_file}" json) + file(DOWNLOAD "https://api.github.com/repos/conan-io/conan/releases/latest" + "${json_file}" + INACTIVITY_TIMEOUT 5 + STATUS status) + list(GET status 0 status_code) + if(NOT status_code EQUAL 0) + list(GET status 1 message) + message(FATAL_ERROR "CMake-Conan: Failed to get the latest Conan version info: ${message} (${status_code})") + endif() + file(READ "${json_file}" json ENCODING UTF-8) string(REGEX MATCH "\"tag_name\": \"([^\"]+)\"" _ "${json}") + if(NOT _) + message(FATAL_ERROR "CMake-Conan: Failed to parse the latest Conan version info from: '${json_file}'") + endif() set(${VERSION_VARIABLE} "${CMAKE_MATCH_1}" PARENT_SCOPE) endfunction()