From 6015ef807de198466ebb281a24bb550076abcdab Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 15 Jan 2026 13:39:13 -0500 Subject: [PATCH] cmake -E tar: Improve error message formatting Do not print file paths with our prose line wrapping, which breaks on spaces. --- Source/cmArchiveWrite.cxx | 5 +++-- Source/cmFileCommand.cxx | 2 +- Source/cmSystemTools.cxx | 4 ++-- Source/cmcmd.cxx | 5 +++-- .../CommandLineTar/7zip-zstd-unsupported-stderr.txt | 3 ++- Tests/RunCMake/CommandLineTar/bad-file-stderr.txt | 9 +++++++-- Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt | 9 +++++++-- Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt | 9 +++++++-- Tests/RunCMake/CommandLineTar/bad-mtime1-stderr.txt | 3 ++- Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt | 9 +++++++-- .../CommandLineTar/zip-bz2-unsupported-stderr.txt | 3 ++- .../CommandLineTar/zip-lzma-unsupported-stderr.txt | 3 ++- .../CommandLineTar/zip-xz-unsupported-stderr.txt | 3 ++- .../CommandLineTar/zip-zstd-unsupported-stderr.txt | 3 ++- 14 files changed, 49 insertions(+), 21 deletions(-) diff --git a/Source/cmArchiveWrite.cxx b/Source/cmArchiveWrite.cxx index d54c5c0728..0cd88eb8b1 100644 --- a/Source/cmArchiveWrite.cxx +++ b/Source/cmArchiveWrite.cxx @@ -448,8 +448,9 @@ bool cmArchiveWrite::AddFile(char const* file, size_t skip, char const* prefix) cm_archive_entry_copy_pathname(e, dest); if (archive_read_disk_entry_from_file(this->Disk, e, -1, nullptr) != ARCHIVE_OK) { - this->Error = cmStrCat("Unable to read from file '", file, - "': ", cm_archive_error_string(this->Disk)); + this->Error = + cmStrCat("Unable to read from file:\n ", file, "\nbecause:\n ", + cm_archive_error_string(this->Disk)); return false; } if (!this->MTime.empty()) { diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 8791385d93..f964367a3b 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -3901,7 +3901,7 @@ bool HandleArchiveExtractCommand(std::vector const& args, parsedArgs.Touch ? cmSystemTools::cmTarExtractTimestamps::No : cmSystemTools::cmTarExtractTimestamps::Yes, parsedArgs.Verbose)) { - status.SetError(cmStrCat("failed to extract: ", inFile)); + status.SetError(cmStrCat("failed to extract:\n ", inFile)); cmSystemTools::SetFatalErrorOccurred(); return false; } diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 58ea714e5a..5d2a99e31e 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -2715,8 +2715,8 @@ bool extract_tar(std::string const& outFileName, # endif else { ArchiveError("Problem with archive_write_header(): ", ext); - cmSystemTools::Error("Current file: " + - cm_archive_entry_pathname(entry)); + cmSystemTools::Error( + cmStrCat("Current file:\n ", cm_archive_entry_pathname(entry))); break; } } diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 58e0998af5..4715ef211a 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -1790,13 +1790,14 @@ int cmcmd::ExecuteCMakeCommand(std::vector const& args, if (!cmSystemTools::CreateTar(outFile, files, {}, compress, verbose, mtime, format, compressionLevel, numThreads)) { - cmSystemTools::Error("Problem creating tar: " + outFile); + cmSystemTools::Error(cmStrCat("Problem creating tar:\n ", outFile)); return 1; } } else if (action == cmSystemTools::TarActionExtract) { if (!cmSystemTools::ExtractTar(outFile, files, extractTimestamps, verbose)) { - cmSystemTools::Error("Problem extracting tar: " + outFile); + cmSystemTools::Error( + cmStrCat("Problem extracting tar:\n ", outFile)); return 1; } #ifdef _WIN32 diff --git a/Tests/RunCMake/CommandLineTar/7zip-zstd-unsupported-stderr.txt b/Tests/RunCMake/CommandLineTar/7zip-zstd-unsupported-stderr.txt index 6ea20fa158..692474c575 100644 --- a/Tests/RunCMake/CommandLineTar/7zip-zstd-unsupported-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/7zip-zstd-unsupported-stderr.txt @@ -1,2 +1,3 @@ ^CMake Error: Zstd is not supported for 7zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it. -CMake Error: Problem creating tar: bad.7z$ +CMake Error: Problem creating tar: + bad\.7z$ diff --git a/Tests/RunCMake/CommandLineTar/bad-file-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-file-stderr.txt index 3064c66e0c..ea8ab2ed8d 100644 --- a/Tests/RunCMake/CommandLineTar/bad-file-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/bad-file-stderr.txt @@ -1,2 +1,7 @@ -^CMake Error: Unable to read from file 'badfile\.txt': .* -CMake Error: Problem creating tar: bad\.tar$ +^CMake Error: Unable to read from file: + badfile\.txt +because: + [^ +]* +CMake Error: Problem creating tar: + bad\.tar$ diff --git a/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt index 0aa8a3680d..887dd88fa4 100644 --- a/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/bad-from4-stderr.txt @@ -1,2 +1,7 @@ -^CMake Error: Unable to read from file 'does-not-exist':.* -CMake Error: Problem creating tar: bad\.tar$ +^CMake Error: Unable to read from file: + does-not-exist +because: + [^ +]* +CMake Error: Problem creating tar: + bad\.tar$ diff --git a/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt index 0aa8a3680d..887dd88fa4 100644 --- a/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/bad-from5-stderr.txt @@ -1,2 +1,7 @@ -^CMake Error: Unable to read from file 'does-not-exist':.* -CMake Error: Problem creating tar: bad\.tar$ +^CMake Error: Unable to read from file: + does-not-exist +because: + [^ +]* +CMake Error: Problem creating tar: + bad\.tar$ diff --git a/Tests/RunCMake/CommandLineTar/bad-mtime1-stderr.txt b/Tests/RunCMake/CommandLineTar/bad-mtime1-stderr.txt index 835d18cf2f..1e57989e95 100644 --- a/Tests/RunCMake/CommandLineTar/bad-mtime1-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/bad-mtime1-stderr.txt @@ -1,2 +1,3 @@ ^CMake Error: unable to parse mtime 'bad' -CMake Error: Problem creating tar: bad\.tar$ +CMake Error: Problem creating tar: + bad\.tar$ diff --git a/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt b/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt index 0ab02d14ba..6f3a2a9a69 100644 --- a/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/end-opt1-stderr.txt @@ -1,2 +1,7 @@ -^CMake Error: Unable to read from file '--bad':.* -CMake Error: Problem creating tar: bad\.tar$ +^CMake Error: Unable to read from file: + --bad +because: + [^ +]* +CMake Error: Problem creating tar: + bad\.tar$ diff --git a/Tests/RunCMake/CommandLineTar/zip-bz2-unsupported-stderr.txt b/Tests/RunCMake/CommandLineTar/zip-bz2-unsupported-stderr.txt index e3c92fd496..88e0868bd2 100644 --- a/Tests/RunCMake/CommandLineTar/zip-bz2-unsupported-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/zip-bz2-unsupported-stderr.txt @@ -1,2 +1,3 @@ ^CMake Error: BZip2 is not supported for zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it. -CMake Error: Problem creating tar: bad.zip$ +CMake Error: Problem creating tar: + bad\.zip$ diff --git a/Tests/RunCMake/CommandLineTar/zip-lzma-unsupported-stderr.txt b/Tests/RunCMake/CommandLineTar/zip-lzma-unsupported-stderr.txt index 4048db7b51..81ccfacf52 100644 --- a/Tests/RunCMake/CommandLineTar/zip-lzma-unsupported-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/zip-lzma-unsupported-stderr.txt @@ -1,2 +1,3 @@ ^CMake Error: LZMA is not supported for zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it. -CMake Error: Problem creating tar: bad.zip$ +CMake Error: Problem creating tar: + bad\.zip$ diff --git a/Tests/RunCMake/CommandLineTar/zip-xz-unsupported-stderr.txt b/Tests/RunCMake/CommandLineTar/zip-xz-unsupported-stderr.txt index 66cb461a26..b86e3afeef 100644 --- a/Tests/RunCMake/CommandLineTar/zip-xz-unsupported-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/zip-xz-unsupported-stderr.txt @@ -1,2 +1,3 @@ ^CMake Error: LZMA2 \(XZ\) is not supported for zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it. -CMake Error: Problem creating tar: bad.zip$ +CMake Error: Problem creating tar: + bad\.zip$ diff --git a/Tests/RunCMake/CommandLineTar/zip-zstd-unsupported-stderr.txt b/Tests/RunCMake/CommandLineTar/zip-zstd-unsupported-stderr.txt index 26d93ad562..21805559b8 100644 --- a/Tests/RunCMake/CommandLineTar/zip-zstd-unsupported-stderr.txt +++ b/Tests/RunCMake/CommandLineTar/zip-zstd-unsupported-stderr.txt @@ -1,2 +1,3 @@ ^CMake Error: Zstd is not supported for zip. Please, build CMake with libarchive 3.8.0 or newer if you want to use it. -CMake Error: Problem creating tar: bad.zip$ +CMake Error: Problem creating tar: + bad\.zip$