[PATCH] error_code for dynamically generated error messages

Rafael Espíndola rafael.espindola at gmail.com
Thu May 22 22:38:59 PDT 2014


Will this work with the std::error_code once we switch?

As far as style goes I probably like the clang model best: pass an
DiagnosticsEngine down instead of passing the error back up. That way
we separate two concepts

* an error we want to report to the user: foo.o in bar.a is corrupted.
* an error condition we want to handle: open failed with no_such_file
in /usr/lib/libfoo.so. The caller will check the error_code and try
the next directory.

But I agree that this is isolated enough that it is fine if it also
works with std::error_code.




On 22 May 2014 18:40, kledzik at apple.com <kledzik at apple.com> wrote:
> Hi Bigcheese, ruiu, shankarke, atanasyan, silvas,
>
> This proposed patch adds a new kind of error_code, one which allows arbitrary
> message strings.
>
> error_code is based on the model that errors are enumerable and you may want
> to programmatically handle when some function called fails with some specific
> error_code.
>
> lld uses ErrorOr<> extensively which is based on error_code.  But the errors
> that arise when parsing .o files or linking them are not usefully enumerable.
> That is, there is nothing that can be programmatic done and you really want
> an error message richer than “bad object format”.  For instance, a richer
> message might be “relocation 14 contains invalid relocation type (23)”.
>
> This patch creates a subclass of error_category which dynamically associcates
> a value and string.  I hope this is not bending the error_code model too much.
> If the idea is good, should this be pushed down from lld into llvm/Support?
>
> As an example usage, I updated lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
> to use make_dynamic_error_code().
>
> http://reviews.llvm.org/D3881
>
> Files:
>   include/lld/Core/Error.h
>   lib/Core/Error.cpp
>   lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>




More information about the llvm-commits mailing list