17a7e6055SDimitry Andric #include "llvm/DebugInfo/PDB/Native/RawError.h"
27a7e6055SDimitry Andric #include "llvm/Support/ErrorHandling.h"
37a7e6055SDimitry Andric #include "llvm/Support/ManagedStatic.h"
47a7e6055SDimitry Andric 
57a7e6055SDimitry Andric using namespace llvm;
67a7e6055SDimitry Andric using namespace llvm::pdb;
77a7e6055SDimitry Andric 
87a7e6055SDimitry Andric // FIXME: This class is only here to support the transition to llvm::Error. It
97a7e6055SDimitry Andric // will be removed once this transition is complete. Clients should prefer to
107a7e6055SDimitry Andric // deal with the Error value directly, rather than converting to error_code.
117a7e6055SDimitry Andric class RawErrorCategory : public std::error_category {
127a7e6055SDimitry Andric public:
name() const137a7e6055SDimitry Andric   const char *name() const noexcept override { return "llvm.pdb.raw"; }
message(int Condition) const147a7e6055SDimitry Andric   std::string message(int Condition) const override {
157a7e6055SDimitry Andric     switch (static_cast<raw_error_code>(Condition)) {
167a7e6055SDimitry Andric     case raw_error_code::unspecified:
177a7e6055SDimitry Andric       return "An unknown error has occurred.";
187a7e6055SDimitry Andric     case raw_error_code::feature_unsupported:
197a7e6055SDimitry Andric       return "The feature is unsupported by the implementation.";
207a7e6055SDimitry Andric     case raw_error_code::invalid_format:
217a7e6055SDimitry Andric       return "The record is in an unexpected format.";
227a7e6055SDimitry Andric     case raw_error_code::corrupt_file:
237a7e6055SDimitry Andric       return "The PDB file is corrupt.";
247a7e6055SDimitry Andric     case raw_error_code::insufficient_buffer:
257a7e6055SDimitry Andric       return "The buffer is not large enough to read the requested number of "
267a7e6055SDimitry Andric              "bytes.";
277a7e6055SDimitry Andric     case raw_error_code::no_stream:
287a7e6055SDimitry Andric       return "The specified stream could not be loaded.";
297a7e6055SDimitry Andric     case raw_error_code::index_out_of_bounds:
307a7e6055SDimitry Andric       return "The specified item does not exist in the array.";
317a7e6055SDimitry Andric     case raw_error_code::invalid_block_address:
327a7e6055SDimitry Andric       return "The specified block address is not valid.";
337a7e6055SDimitry Andric     case raw_error_code::duplicate_entry:
347a7e6055SDimitry Andric       return "The entry already exists.";
357a7e6055SDimitry Andric     case raw_error_code::no_entry:
367a7e6055SDimitry Andric       return "The entry does not exist.";
377a7e6055SDimitry Andric     case raw_error_code::not_writable:
387a7e6055SDimitry Andric       return "The PDB does not support writing.";
397a7e6055SDimitry Andric     case raw_error_code::stream_too_long:
407a7e6055SDimitry Andric       return "The stream was longer than expected.";
417a7e6055SDimitry Andric     case raw_error_code::invalid_tpi_hash:
427a7e6055SDimitry Andric       return "The Type record has an invalid hash value.";
437a7e6055SDimitry Andric     }
447a7e6055SDimitry Andric     llvm_unreachable("Unrecognized raw_error_code");
457a7e6055SDimitry Andric   }
467a7e6055SDimitry Andric };
477a7e6055SDimitry Andric 
48*b5893f02SDimitry Andric static llvm::ManagedStatic<RawErrorCategory> RawCategory;
RawErrCategory()49*b5893f02SDimitry Andric const std::error_category &llvm::pdb::RawErrCategory() { return *RawCategory; }
507a7e6055SDimitry Andric 
51*b5893f02SDimitry Andric char RawError::ID;
52