Browse Source

remove internal_error

master
Daniel Kolesa 3 months ago
parent
commit
7febb8f5b1
  1. 11
      include/cubescript/cubescript/error.hh
  2. 3
      src/cs_error.cc
  3. 9
      src/cs_strman.cc
  4. 5
      src/cs_val.cc
  5. 5
      src/lib_str.cc

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

3
src/cs_error.cc

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

9
src/cs_strman.cc

@ -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 */

5
src/cs_val.cc

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

5
src/lib_str.cc

@ -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) {

Loading…
Cancel
Save