[PATCH] D104483: Improve error handling in llvm-dwarfdump

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 09:45:45 PDT 2021


JDevlieghere added inline comments.


================
Comment at: llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp:274
 
+static void error(StringRef Prefix, Error Err) {
+  std::error_code EC;
----------------
jhenderson wrote:
> I think the code would be a lot simpler if you switched which is the "base" error reporting function. If I'm not mistaken, you can use toString to convert an `Error` into an error message. You could convert an error code to an `Error` and report things that way. Approximate code:
> ```
> static void error(StringRef Prefix, Error Err) {
>   if (!Err)
>     return;
>   WithColor::error() << Prefix << ": " << toString(std::move(Err)) << "\n";
>   exit(1);  
> }
> 
> static void error(StringRef Prefix, std::error_code EC) {
>   error(errorCodeToError(EC));
> }
> ```
I was going to suggest the same thing, so +1 from me


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104483/new/

https://reviews.llvm.org/D104483



More information about the llvm-commits mailing list