Skip to content

Commit

Permalink
Improve error handling in get_latest_conan_version()
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 16, 2024
1 parent 12ca608 commit 4119e54
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions conan_provider.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 4119e54

Please sign in to comment.