126#include <type_traits>
130#define PINEFORGE_HAS_RUN_FAILURE_CODES_V1 1
134inline namespace engine_script_run_v19 {
178 template <
typename Integer,
179 typename std::enable_if<std::is_integral<Integer>::value
180 && !std::is_same<Integer, bool>::value,
int>
::type = 0>
183 template <
typename Floating,
184 typename std::enable_if<std::is_floating_point<Floating>::value,
int>
::type = 0>
195 std::shared_ptr<const std::string>
args;
257 const std::exception& error);
273 std::int32_t line,
const char* english) {
276 {{
"function", function}, {
"call", call}, {
"line", line}}, english ? english :
"");
280 const char* symbol_literal_or_null,
281 const char* call, std::int32_t line,
282 const char* english) {
283 RunFailureArgs args{{
"function", function}, {
"call", call}, {
"line", line}};
284 if (symbol_literal_or_null) args.emplace_back(
"symbol", symbol_literal_or_null);
286 english ? english :
"");
289[[noreturn]]
inline void pine_array_stop(
const char* reason,
const char* method_or_null,
290 const char* english) {
292 if (method_or_null) args.emplace_back(
"method", method_or_null);
294 english ? english :
"");
298 const char* english) {
299 const char* text = english ? english :
"";
302 const bool listed = collection && (std::strcmp(collection,
"array") == 0
303 || std::strcmp(collection,
"matrix") == 0);
304 if (listed && reason && std::strcmp(reason,
"na_reference") == 0) {
306 {{
"object", collection}}, text);
308 if (listed && reason && std::strcmp(reason,
"historical_modified") == 0) {
311 {{
"reason",
"historical_modified"}, {
"collection", collection}}, text);
316[[noreturn]]
inline void pine_na_stop(
const char*
object,
const char* english) {
318 english ? english :
"");
322 const char* english) {
324 if (max >= 0) args.emplace_back(
"max", max);
326 english ? english :
"");
330 const char* english) {
332 if (line >= 0) args.emplace_back(
"line", line);
334 english ? english :
"");
339 english ? english :
"");
344 english ? english :
"");
virtual ~RunFailureInfo()
RunFailureCode run_failure_code() const noexcept
RunFailureInfo(const RunFailureInfo &) noexcept=default
RunFailureInfo(RunFailureValue value) noexcept
const RunFailureValue & run_failure() const noexcept
RunFailureInfo(RunFailureCode code, const RunFailureArgs &args) noexcept
RunFailureInfo & operator=(const RunFailureInfo &) noexcept=default
Base with a code: throw coded<std::invalid_argument>(code, {args}, text).
coded(RunFailureValue value, const char *what)
coded(RunFailureCode code, const RunFailureArgs &args, const char *what)
coded(RunFailureCode code, const RunFailureArgs &args, const std::string &what)
coded(RunFailureValue value, const std::string &what)
bool run_failure_code_retryable(RunFailureCode code) noexcept
const char * run_failure_args_of(const BacktestEngine &engine) noexcept
void pine_unsupported_stop(const char *reason, std::int32_t line, const char *english)
void pine_string_stop(const char *reason, const char *english)
void note_run_failure(BacktestEngine &engine, std::string text, RunFailureCode code, const RunFailureArgs &args={})
void clear_run_failure(BacktestEngine &engine) noexcept
RunFailureValue make_run_failure(RunFailureCode code, const RunFailureArgs &args) noexcept
Validate args against code's registry entry and canonicalize them.
void pine_limit_stop(const char *limit, std::int64_t max, const char *english)
RunFailureClass run_failure_code_class(RunFailureCode code) noexcept
The code's catalog class and retryable flag.
RunFailureValue run_failure_value_of(const BacktestEngine &engine) noexcept
The recorded value under the same rule (none when there is no failure).
RunFailureValue classify_run_failure(const std::exception &error) noexcept
The code an exception carries: a coded exception's own; else the safety net by type (std::bad_alloc -...
RunFailureClass
The class a code belongs to (the catalog's class).
const char * run_failure_code_of(const BacktestEngine &engine) noexcept
The getters' answers (strategy_get_last_error_code / _args): the stored code while its text is the en...
void pine_array_stop(const char *reason, const char *method_or_null, const char *english)
RunFailureArgKind
An argument's kind (the catalog's kind).
void pine_other_symbol_stop(const char *function, const char *symbol_literal_or_null, const char *call, std::int32_t line, const char *english)
std::vector< RunFailureArg > RunFailureArgs
const char * run_failure_code_name(RunFailureCode code) noexcept
The code's catalog name ("" for none or an unknown value).
void pine_na_stop(const char *object, const char *english)
void pine_engine_invariant(const char *english)
void note_run_failure_unknown(BacktestEngine &engine, const char *entrypoint)
void pine_collection_stop(const char *collection, const char *reason, const char *english)
void pine_no_data_stop(const char *function, const char *call, std::int32_t line, const char *english)
RunFailureArg(const char *arg_name, const char *value)
RunFailureArg(const char *arg_name, std::string value)
RunFailureArg(const char *arg_name, Integer value)
RunFailureArg(const char *arg_name, Floating value)
A validated code and its canonical arguments: the JSON object with its keys sorted and no whitespace,...
std::shared_ptr< const std::string > args