From 91a719e53438dbf1859a1ad31163ff960da4f47a Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:50:49 -0600 Subject: [PATCH] Use internal_error over std:: errors --- src/symbols/symbols_with_dbghelp.cpp | 12 ++++++------ src/symbols/symbols_with_libbacktrace.cpp | 2 +- src/unwind/unwind_with_dbghelp.cpp | 4 ++-- src/utils/dbghelp_syminit_manager.hpp | 2 +- src/utils/dwarf.hpp | 2 +- src/utils/error.hpp | 13 +++++++++---- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/symbols/symbols_with_dbghelp.cpp b/src/symbols/symbols_with_dbghelp.cpp index 71e9203..ee4881b 100644 --- a/src/symbols/symbols_with_dbghelp.cpp +++ b/src/symbols/symbols_with_dbghelp.cpp @@ -70,7 +70,7 @@ namespace dbghelp { if(FAILABLE) { return (T)-1; } else { - throw std::logic_error( + throw internal_error( std::string("SymGetTypeInfo failed: ") + std::system_error(GetLastError(), std::system_category()).what() ); @@ -85,7 +85,7 @@ namespace dbghelp { if( !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::system_error(GetLastError(), std::system_category()).what() ); @@ -247,7 +247,7 @@ namespace dbghelp { children ) ) { - throw std::logic_error( + throw internal_error( std::string("SymGetTypeInfo failed: ") + std::system_error(GetLastError(), std::system_category()).what() ); @@ -255,7 +255,7 @@ namespace dbghelp { // get children type std::string extent = "("; 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++) { extent += (i == 0 ? "" : ", ") + resolve_type(children->ChildId[i], proc, modbase); @@ -413,7 +413,7 @@ namespace dbghelp { get_syminit_manager().init(proc); } else { if(!SymInitialize(proc, NULL, TRUE)) { - throw std::logic_error("Cpptrace SymInitialize failed"); + throw internal_error("Cpptrace SymInitialize failed"); } } for(const auto frame : frames) { @@ -430,7 +430,7 @@ namespace dbghelp { } if(get_cache_mode() != cache_mode::prioritize_speed) { if(!SymCleanup(proc)) { - throw std::logic_error("Cpptrace SymCleanup failed"); + throw internal_error("Cpptrace SymCleanup failed"); } } return trace; diff --git a/src/symbols/symbols_with_libbacktrace.cpp b/src/symbols/symbols_with_libbacktrace.cpp index 2d7937b..02f6ded 100644 --- a/src/symbols/symbols_with_libbacktrace.cpp +++ b/src/symbols/symbols_with_libbacktrace.cpp @@ -38,7 +38,7 @@ namespace libbacktrace { } 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() { diff --git a/src/unwind/unwind_with_dbghelp.cpp b/src/unwind/unwind_with_dbghelp.cpp index 5e49fe5..6e9d744 100644 --- a/src/unwind/unwind_with_dbghelp.cpp +++ b/src/unwind/unwind_with_dbghelp.cpp @@ -110,7 +110,7 @@ namespace detail { get_syminit_manager().init(proc); } else { if(!SymInitialize(proc, NULL, TRUE)) { - throw std::logic_error("Cpptrace SymInitialize failed"); + throw internal_error("Cpptrace SymInitialize failed"); } } while(trace.size() < max_depth) { @@ -147,7 +147,7 @@ namespace detail { } if(get_cache_mode() != cache_mode::prioritize_speed) { if(!SymCleanup(proc)) { - throw std::logic_error("Cpptrace SymCleanup failed"); + throw internal_error("Cpptrace SymCleanup failed"); } } return trace; diff --git a/src/utils/dbghelp_syminit_manager.hpp b/src/utils/dbghelp_syminit_manager.hpp index 6f7ffd7..b7053fb 100644 --- a/src/utils/dbghelp_syminit_manager.hpp +++ b/src/utils/dbghelp_syminit_manager.hpp @@ -25,7 +25,7 @@ namespace detail { void init(HANDLE proc) { if(set.count(proc) == 0) { 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); } diff --git a/src/utils/dwarf.hpp b/src/utils/dwarf.hpp index 39feb34..8a82cbe 100644 --- a/src/utils/dwarf.hpp +++ b/src/utils/dwarf.hpp @@ -28,7 +28,7 @@ namespace libdwarf { char* msg = dwarf_errmsg(error); (void)dbg; // 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 { diff --git a/src/utils/error.hpp b/src/utils/error.hpp index 5c52e8c..a8fd46b 100644 --- a/src/utils/error.hpp +++ b/src/utils/error.hpp @@ -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. struct source_location { const char* const file; @@ -56,7 +61,7 @@ namespace detail { const char* action = assert_actions[static_cast::type>(type)]; const char* name = assert_names[static_cast::type>(type)]; if(message == "") { - throw std::logic_error( + throw internal_error( stringf( "Cpptrace %s failed at %s:%d: %s\n" " %s(%s);\n", @@ -65,7 +70,7 @@ namespace detail { ) ); } else { - throw std::logic_error( + throw internal_error( stringf( "Cpptrace %s failed at %s:%d: %s: %s\n" " %s(%s);\n", @@ -82,14 +87,14 @@ namespace detail { const std::string& message = "" ) { if(message == "") { - throw std::logic_error( + throw internal_error( stringf( "Cpptrace panic %s:%d: %s\n", location.file, location.line, signature ) ); } else { - throw std::logic_error( + throw internal_error( stringf( "Cpptrace panic %s:%d: %s: %s\n", location.file, location.line, signature, message.c_str()