file: Add more context to errors from file(DOWNLOAD)

This commit is contained in:
Martin Duffy
2025-04-17 10:28:27 -04:00
parent 980b79ad1f
commit cc2cbfc61e
9 changed files with 45 additions and 15 deletions

View File

@@ -2131,7 +2131,8 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
if (!file.empty()) {
fout.open(file.c_str(), std::ios::binary);
if (!fout) {
status.SetError("DOWNLOAD cannot open file for write.");
status.SetError(cmStrCat("DOWNLOAD cannot open file for write\n",
" file: \"", file, '"'));
return false;
}
}
@@ -2320,16 +2321,18 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
//
if (hash) {
if (res != CURLE_OK) {
status.SetError(cmStrCat(
"DOWNLOAD cannot compute hash on failed download\n"
" status: [",
static_cast<int>(res), ";\"", ::curl_easy_strerror(res), "\"]"));
status.SetError(
cmStrCat("DOWNLOAD cannot compute hash on failed download\n"
" from url: \"",
url, "\"\n status: [", static_cast<int>(res), ";\"",
::curl_easy_strerror(res), "\"]"));
return false;
}
std::string actualHash = hash->HashFile(file);
if (actualHash.empty()) {
status.SetError("DOWNLOAD cannot compute hash on downloaded file");
status.SetError(cmStrCat("DOWNLOAD cannot compute hash on download\n",
" for file: \"", file, '"'));
return false;
}
@@ -2343,14 +2346,14 @@ bool HandleDownloadCommand(std::vector<std::string> const& args,
}
status.SetError(cmStrCat("DOWNLOAD HASH mismatch\n"
" for file: [",
" for file: \"",
file,
"]\n"
" expected hash: [",
"\"\n"
" expected hash: \"",
expectedHash,
"]\n"
" actual hash: [",
actualHash, "]\n"));
"\"\n"
" actual hash: \"",
actualHash, "\"\n"));
return false;
}
}

View File

@@ -15,6 +15,8 @@ run_cmake(TLS_VERSION-invalid)
run_cmake(TLS_VERSION-missing)
run_cmake(pass-not-set)
run_cmake(no-save-hash)
run_cmake(failed-download)
run_cmake(bad-file)
run_cmake(basic)
run_cmake(EXPECTED_HASH)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,6 @@
CMake Error at bad-file.cmake:[0-9]+ \(file\):
file DOWNLOAD cannot open file for write
file: "."
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)

View File

@@ -0,0 +1,3 @@
include(common.cmake)
file(DOWNLOAD ${url} .)

View File

@@ -0,0 +1 @@
1

View File

@@ -0,0 +1,8 @@
CMake Error at failed-download.cmake:[0-9]+ \(file\):
file DOWNLOAD cannot compute hash on failed download
from url: "[^
]*input.png_invalid"
status: \[37;"(Could not|Couldn't) read a file:// file"\]
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)

View File

@@ -0,0 +1,6 @@
include(common.cmake)
file(DOWNLOAD ${url}_invalid ${file}
EXPECTED_HASH SHA1=0123456789abcdef0123456789abcdef01234567
STATUS status
)

View File

@@ -1,9 +1,9 @@
^CMake Error at hash-mismatch.cmake:[0-9]+ \(file\):
file DOWNLOAD HASH mismatch
for file: \[.*/Tests/RunCMake/file-DOWNLOAD/hash-mismatch-build/output.png\]
expected hash: \[0123456789abcdef0123456789abcdef01234567\]
actual hash: \[67eee17f79d9ac557284fc0b8ad19f25723fb578\]
for file: ".*/Tests/RunCMake/file-DOWNLOAD/hash-mismatch-build/output.png"
expected hash: "0123456789abcdef0123456789abcdef01234567"
actual hash: "67eee17f79d9ac557284fc0b8ad19f25723fb578"
Call Stack \(most recent call first\):
CMakeLists.txt:[0-9]+ \(include\)