Bartleby 0.1.0
A symbol renaming toolkit
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
saq::bartleby::Error Class Reference

Custom error info for Bartleby. More...

#include <Error.h>

Inheritance diagram for saq::bartleby::Error:

Classes

struct  MachOUniversalBinaryReason
 Fat Mach-O related error. More...
 
struct  ObjectFormatTypeMismatchReason
 Mismatch between object format type. More...
 
struct  UnsupportedBinaryReason
 Error from std::error_code. More...
 

Public Types

using ReasonT = std::variant< UnsupportedBinaryReason, ObjectFormatTypeMismatchReason, MachOUniversalBinaryReason >
 Reason for error.
 

Public Member Functions

template<typename T >
 Error (T Reason) noexcept
 Constructs an error using a reason.
 
void log (llvm::raw_ostream &OS) const noexcept override
 
std::string message () const noexcept override
 
std::error_code convertToErrorCode () const noexcept override
 

Static Public Attributes

static char ID = 'b'
 Error ID.
 

Detailed Description

Custom error info for Bartleby.

Constructor & Destructor Documentation

◆ Error()

template<typename T >
saq::bartleby::Error::Error ( Reason)
inlinenoexcept

Constructs an error using a reason.

Parameters
ReasonThe reason of the error.
71: Reason(std::move(Reason)) {}

Member Function Documentation

◆ convertToErrorCode()

std::error_code Error::convertToErrorCode ( ) const
overridenoexcept
68 {
69 return std::visit(
70 [](auto &&Err) {
71 using ErrT = std::decay_t<decltype(Err)>;
72 if constexpr (std::is_same_v<UnsupportedBinaryReason, ErrT>) {
73 return std::error_code(1, std::system_category());
74 } else if constexpr (std::is_same_v<ObjectFormatTypeMismatchReason,
75 ErrT>) {
76 return std::error_code(2, std::system_category());
77 } else if constexpr (std::is_same_v<MachOUniversalBinaryReason, ErrT>) {
78 return std::error_code(3, std::system_category());
79 } else {
80 __builtin_unreachable();
81 }
82 },
83 Reason);
84}

◆ log()

void Error::log ( llvm::raw_ostream &  OS) const
overridenoexcept
27 {
28 OS << message();
29 std::visit(
30 [&OS](auto &&Err) {
31 using ErrT = std::decay_t<decltype(Err)>;
32 if constexpr (std::is_same_v<UnsupportedBinaryReason, ErrT>) {
33 OS << Err.Msg;
34 } else if constexpr (std::is_same_v<ObjectFormatTypeMismatchReason,
35 ErrT>) {
36 OS << "expected " << Err.Constraint << ", got " << Err.Found;
37 } else if constexpr (std::is_same_v<MachOUniversalBinaryReason, ErrT>) {
38 OS << Err.Msg;
39 } else {
40 __builtin_unreachable();
41 }
42 },
43 Reason);
44}

◆ message()

std::string Error::message ( ) const
overridenoexcept
46 {
47 std::string Msg;
48 llvm::raw_string_ostream OS(Msg);
49 std::visit(
50 [&OS](auto &&Err) {
51 using ErrT = std::decay_t<decltype(Err)>;
52 if constexpr (std::is_same_v<UnsupportedBinaryReason, ErrT>) {
53 OS << "error while reading binary: " << Err.Msg;
54 } else if constexpr (std::is_same_v<ObjectFormatTypeMismatchReason,
55 ErrT>) {
56 OS << "invalid object format type: expected " << Err.Constraint
57 << ", got " << Err.Found;
58 } else if constexpr (std::is_same_v<MachOUniversalBinaryReason, ErrT>) {
59 OS << "fat Mach-O error: " << Err.Msg;
60 } else {
61 __builtin_unreachable();
62 }
63 },
64 Reason);
65 return Msg;
66}

The documentation for this class was generated from the following files: