[llvm] 2569f79 - [llvm-dis] Improve missing file error message
Keith Smiley via llvm-commits
llvm-commits at lists.llvm.org
Thu May 19 11:09:36 PDT 2022
Author: Keith Smiley
Date: 2022-05-19T11:07:49-07:00
New Revision: 2569f79a4fe404da9d905188333484d5d66caf7e
URL: https://github.com/llvm/llvm-project/commit/2569f79a4fe404da9d905188333484d5d66caf7e
DIFF: https://github.com/llvm/llvm-project/commit/2569f79a4fe404da9d905188333484d5d66caf7e.diff
LOG: [llvm-dis] Improve missing file error message
Previously the error message didn't include the failing path, which made
it hard to tell what went wrong.
Differential Revision: https://reviews.llvm.org/D121665
Added:
llvm/test/tools/llvm-dis/errors.test
Modified:
llvm/tools/llvm-dis/llvm-dis.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-dis/errors.test b/llvm/test/tools/llvm-dis/errors.test
new file mode 100644
index 000000000000..47bd655263e0
--- /dev/null
+++ b/llvm/test/tools/llvm-dis/errors.test
@@ -0,0 +1,3 @@
+# RUN: not llvm-dis missing-file-path 2>&1 | FileCheck %s --check-prefix=MISSING
+
+# MISSING: error: missing-file-path: No such file or directory
diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp
index 3d40da21f472..f0e1655b19be 100644
--- a/llvm/tools/llvm-dis/llvm-dis.cpp
+++ b/llvm/tools/llvm-dis/llvm-dis.cpp
@@ -180,8 +180,13 @@ int main(int argc, char **argv) {
}
for (std::string InputFilename : InputFilenames) {
- std::unique_ptr<MemoryBuffer> MB = ExitOnErr(
- errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename)));
+ ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
+ MemoryBuffer::getFileOrSTDIN(InputFilename);
+ if (std::error_code EC = BufferOrErr.getError()) {
+ WithColor::error() << InputFilename << ": " << EC.message() << '\n';
+ return 1;
+ }
+ std::unique_ptr<MemoryBuffer> MB = std::move(BufferOrErr.get());
BitcodeFileContents IF = ExitOnErr(llvm::getBitcodeFileContents(*MB));
More information about the llvm-commits
mailing list