diff --git a/include/cubescript/cubescript/error.hh b/include/cubescript/cubescript/error.hh index fc369d4..7fdfcd8 100644 --- a/include/cubescript/cubescript/error.hh +++ b/include/cubescript/cubescript/error.hh @@ -20,15 +20,6 @@ namespace cubescript { struct state; -/** @brief An internal Cubescript error. - * - * This is an error that is never expected; it is thrown - * when some API call fails due to most likely a bug. - */ -struct internal_error: std::runtime_error { - using std::runtime_error::runtime_error; -}; - /** @brief Represents the simplified call stack at a point in time. * * This is a simplified call stack; it is generally carried by errors @@ -156,7 +147,7 @@ struct LIBCUBESCRIPT_EXPORT error { buf = request_buf(cs, sz, sp); int written = std::snprintf(buf, sz, msg.data(), args...); if (written <= 0) { - throw internal_error{"format error"}; + throw error{cs, "malformed format string"}; } else if (std::size_t(written) <= sz) { break; } diff --git a/src/cs_error.cc b/src/cs_error.cc index 87994ed..acba612 100644 --- a/src/cs_error.cc +++ b/src/cs_error.cc @@ -1,5 +1,6 @@ #include +#include #include #include "cs_thread.hh" @@ -69,7 +70,7 @@ LIBCUBESCRIPT_EXPORT char *error::request_buf( nsz = std::snprintf(cb.data(), sz, "%zu: ", *ts.current_line); } if (nsz <= 0) { - throw internal_error{"format error"}; + abort(); /* should be unreachable */ } else if (std::size_t(nsz) < sz) { sz = std::size_t(nsz); break; diff --git a/src/cs_strman.cc b/src/cs_strman.cc index 7273c22..4dc0621 100644 --- a/src/cs_strman.cc +++ b/src/cs_strman.cc @@ -1,3 +1,4 @@ +#include #include #include "cs_strman.hh" @@ -70,10 +71,14 @@ void string_pool::unref(char const *ptr) { */ auto sr = std::string_view{ptr, ss->length}; auto it = counts.find(sr); + /* this should *never* happen unless we have a bug */ +#ifndef NDEBUG + assert(it != counts.end()); +#else if (it == counts.end()) { - /* internal error: this should *never* happen */ - throw internal_error{"no refcount"}; + abort(); } +#endif /* we're freeing the key */ counts.erase(it); /* dealloc */ diff --git a/src/cs_val.cc b/src/cs_val.cc index 22d16d9..77ebbeb 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -5,6 +5,7 @@ #include "cs_strman.hh" #include +#include #include namespace cubescript { @@ -22,7 +23,7 @@ static std::string_view intstr(integer_type v, charbuf &buf) { } } if (n <= 0) { - throw internal_error{"format error"}; + abort(); /* unreachable, provided a well-formed format string */ } return std::string_view{buf.data(), std::size_t(n)}; } @@ -50,7 +51,7 @@ static std::string_view floatstr(float_type v, charbuf &buf) { } } if (n <= 0) { - throw internal_error{"format error"}; + abort(); /* unreachable, provided a well-formed format string */ } return std::string_view{buf.data(), std::size_t(n)}; } diff --git a/src/lib_str.cc b/src/lib_str.cc index ec438bb..9031f33 100644 --- a/src/lib_str.cc +++ b/src/lib_str.cc @@ -1,3 +1,4 @@ +#include #include #include @@ -148,8 +149,8 @@ LIBCUBESCRIPT_EXPORT void std_init_string(state &cs) { res.set_string(static_cast(buf), ccs); return; } - /* should pretty much be unreachable */ - throw internal_error{"format error"}; + /* should be unreachable */ + abort(); }); new_cmd_quiet(cs, "substr", "sii#", [](auto &ccs, auto args, auto &res) {