remove internal_error

master
Daniel Kolesa 2021-05-03 00:39:00 +02:00
parent 5b54c74f2a
commit 7febb8f5b1
5 changed files with 16 additions and 17 deletions

View File

@ -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;
}

View File

@ -1,5 +1,6 @@
#include <cubescript/cubescript.hh>
#include <cstdlib>
#include <algorithm>
#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;

View File

@ -1,3 +1,4 @@
#include <cassert>
#include <cubescript/cubescript.hh>
#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 */

View File

@ -5,6 +5,7 @@
#include "cs_strman.hh"
#include <cmath>
#include <cstdlib>
#include <iterator>
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)};
}

View File

@ -1,3 +1,4 @@
#include <cstdlib>
#include <functional>
#include <iterator>
@ -148,8 +149,8 @@ LIBCUBESCRIPT_EXPORT void std_init_string(state &cs) {
res.set_string(static_cast<char const *>(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) {