Use internal_error over std:: errors

This commit is contained in:
Jeremy 2024-03-09 21:50:49 -06:00
parent e80a11d730
commit 91a719e534
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4
6 changed files with 20 additions and 15 deletions

View File

@ -70,7 +70,7 @@ namespace dbghelp {
if(FAILABLE) { if(FAILABLE) {
return (T)-1; return (T)-1;
} else { } else {
throw std::logic_error( throw internal_error(
std::string("SymGetTypeInfo failed: ") std::string("SymGetTypeInfo failed: ")
+ std::system_error(GetLastError(), std::system_category()).what() + std::system_error(GetLastError(), std::system_category()).what()
); );
@ -85,7 +85,7 @@ namespace dbghelp {
if( if(
!SymGetTypeInfo(proc, modbase, type_index, static_cast<::IMAGEHLP_SYMBOL_TYPE_INFO>(SymType), &info) !SymGetTypeInfo(proc, modbase, type_index, static_cast<::IMAGEHLP_SYMBOL_TYPE_INFO>(SymType), &info)
) { ) {
throw std::logic_error( throw internal_error(
std::string("SymGetTypeInfo failed: ") std::string("SymGetTypeInfo failed: ")
+ std::system_error(GetLastError(), std::system_category()).what() + std::system_error(GetLastError(), std::system_category()).what()
); );
@ -247,7 +247,7 @@ namespace dbghelp {
children children
) )
) { ) {
throw std::logic_error( throw internal_error(
std::string("SymGetTypeInfo failed: ") std::string("SymGetTypeInfo failed: ")
+ std::system_error(GetLastError(), std::system_category()).what() + std::system_error(GetLastError(), std::system_category()).what()
); );
@ -255,7 +255,7 @@ namespace dbghelp {
// get children type // get children type
std::string extent = "("; std::string extent = "(";
if(children->Start != 0) { if(children->Start != 0) {
throw std::logic_error("Error: children->Start == 0"); throw internal_error("Error: children->Start == 0");
} }
for(std::size_t i = 0; i < n_children; i++) { for(std::size_t i = 0; i < n_children; i++) {
extent += (i == 0 ? "" : ", ") + resolve_type(children->ChildId[i], proc, modbase); extent += (i == 0 ? "" : ", ") + resolve_type(children->ChildId[i], proc, modbase);
@ -413,7 +413,7 @@ namespace dbghelp {
get_syminit_manager().init(proc); get_syminit_manager().init(proc);
} else { } else {
if(!SymInitialize(proc, NULL, TRUE)) { if(!SymInitialize(proc, NULL, TRUE)) {
throw std::logic_error("Cpptrace SymInitialize failed"); throw internal_error("Cpptrace SymInitialize failed");
} }
} }
for(const auto frame : frames) { for(const auto frame : frames) {
@ -430,7 +430,7 @@ namespace dbghelp {
} }
if(get_cache_mode() != cache_mode::prioritize_speed) { if(get_cache_mode() != cache_mode::prioritize_speed) {
if(!SymCleanup(proc)) { if(!SymCleanup(proc)) {
throw std::logic_error("Cpptrace SymCleanup failed"); throw internal_error("Cpptrace SymCleanup failed");
} }
} }
return trace; return trace;

View File

@ -38,7 +38,7 @@ namespace libbacktrace {
} }
void error_callback(void*, const char* msg, int errnum) { void error_callback(void*, const char* msg, int errnum) {
throw std::runtime_error(stringf("Libbacktrace error: %s, code %d\n", msg, errnum)); throw internal_error(stringf("Libbacktrace error: %s, code %d\n", msg, errnum));
} }
backtrace_state* get_backtrace_state() { backtrace_state* get_backtrace_state() {

View File

@ -110,7 +110,7 @@ namespace detail {
get_syminit_manager().init(proc); get_syminit_manager().init(proc);
} else { } else {
if(!SymInitialize(proc, NULL, TRUE)) { if(!SymInitialize(proc, NULL, TRUE)) {
throw std::logic_error("Cpptrace SymInitialize failed"); throw internal_error("Cpptrace SymInitialize failed");
} }
} }
while(trace.size() < max_depth) { while(trace.size() < max_depth) {
@ -147,7 +147,7 @@ namespace detail {
} }
if(get_cache_mode() != cache_mode::prioritize_speed) { if(get_cache_mode() != cache_mode::prioritize_speed) {
if(!SymCleanup(proc)) { if(!SymCleanup(proc)) {
throw std::logic_error("Cpptrace SymCleanup failed"); throw internal_error("Cpptrace SymCleanup failed");
} }
} }
return trace; return trace;

View File

@ -25,7 +25,7 @@ namespace detail {
void init(HANDLE proc) { void init(HANDLE proc) {
if(set.count(proc) == 0) { if(set.count(proc) == 0) {
if(!SymInitialize(proc, NULL, TRUE)) { if(!SymInitialize(proc, NULL, TRUE)) {
throw std::logic_error(stringf("SymInitialize failed %llu", to_ull(GetLastError()))); throw internal_error(stringf("SymInitialize failed %llu", to_ull(GetLastError())));
} }
set.insert(proc); set.insert(proc);
} }

View File

@ -28,7 +28,7 @@ namespace libdwarf {
char* msg = dwarf_errmsg(error); char* msg = dwarf_errmsg(error);
(void)dbg; (void)dbg;
// dwarf_dealloc_error(dbg, error); // dwarf_dealloc_error(dbg, error);
throw std::runtime_error(stringf("Cpptrace dwarf error %u %s\n", ev, msg)); throw internal_error(stringf("Cpptrace dwarf error %u %s\n", ev, msg));
} }
struct die_object { struct die_object {

View File

@ -25,6 +25,11 @@ namespace detail {
} }
}; };
class file_error : public internal_error {
public:
file_error(std::string path) : internal_error("Unable to read file " + std::move(path)) {}
};
// Lightweight std::source_location. // Lightweight std::source_location.
struct source_location { struct source_location {
const char* const file; const char* const file;
@ -56,7 +61,7 @@ namespace detail {
const char* action = assert_actions[static_cast<std::underlying_type<assert_type>::type>(type)]; const char* action = assert_actions[static_cast<std::underlying_type<assert_type>::type>(type)];
const char* name = assert_names[static_cast<std::underlying_type<assert_type>::type>(type)]; const char* name = assert_names[static_cast<std::underlying_type<assert_type>::type>(type)];
if(message == "") { if(message == "") {
throw std::logic_error( throw internal_error(
stringf( stringf(
"Cpptrace %s failed at %s:%d: %s\n" "Cpptrace %s failed at %s:%d: %s\n"
" %s(%s);\n", " %s(%s);\n",
@ -65,7 +70,7 @@ namespace detail {
) )
); );
} else { } else {
throw std::logic_error( throw internal_error(
stringf( stringf(
"Cpptrace %s failed at %s:%d: %s: %s\n" "Cpptrace %s failed at %s:%d: %s: %s\n"
" %s(%s);\n", " %s(%s);\n",
@ -82,14 +87,14 @@ namespace detail {
const std::string& message = "" const std::string& message = ""
) { ) {
if(message == "") { if(message == "") {
throw std::logic_error( throw internal_error(
stringf( stringf(
"Cpptrace panic %s:%d: %s\n", "Cpptrace panic %s:%d: %s\n",
location.file, location.line, signature location.file, location.line, signature
) )
); );
} else { } else {
throw std::logic_error( throw internal_error(
stringf( stringf(
"Cpptrace panic %s:%d: %s: %s\n", "Cpptrace panic %s:%d: %s: %s\n",
location.file, location.line, signature, message.c_str() location.file, location.line, signature, message.c_str()