154#include <string_view>
155#include <type_traits>
159#define PINEFORGE_HAS_RUN_FAILURE_CODES_V1 1
160#define PINEFORGE_HAS_RUN_FAILURE_VALIDATION_V1 1
161#define PINEFORGE_HAS_TIMEZONE_STOP_V1 1
165inline namespace engine_script_run_v20 {
228 template <
typename Boolean,
229 typename std::enable_if<std::is_same<Boolean, bool>::value,
int>
::type = 0>
232 template <
typename Integer,
233 typename std::enable_if<std::is_integral<Integer>::value
234 && !std::is_same<Integer, bool>::value,
int>
::type = 0>
237 template <
typename Floating,
238 typename std::enable_if<std::is_floating_point<Floating>::value,
int>
::type = 0>
249 std::shared_ptr<const std::string>
args;
271 std::optional<RunFailureValue>
value;
346 const std::exception& error);
362 std::int32_t
line,
const char* english) {
365 {{
"function", function}, {
"call", call}, {
"line",
line}}, english ? english :
"");
369 const char* symbol_literal_or_null,
370 const char* call, std::int32_t
line,
371 const char* english) {
373 if (symbol_literal_or_null) args.emplace_back(
"symbol", symbol_literal_or_null);
375 english ? english :
"");
378[[noreturn]]
inline void pine_array_stop(
const char* reason,
const char* method_or_null,
379 const char* english) {
381 if (method_or_null) args.emplace_back(
"method", method_or_null);
383 english ? english :
"");
387 const char* english) {
388 const char* text = english ? english :
"";
391 const bool listed = collection && (std::strcmp(collection,
"array") == 0
392 || std::strcmp(collection,
"matrix") == 0);
393 if (listed && reason && std::strcmp(reason,
"na_reference") == 0) {
395 {{
"object", collection}}, text);
397 if (listed && reason && std::strcmp(reason,
"historical_modified") == 0) {
400 {{
"reason",
"historical_modified"}, {
"collection", collection}}, text);
405[[noreturn]]
inline void pine_na_stop(
const char*
object,
const char* english) {
407 english ? english :
"");
411 const char* english) {
413 if (max >= 0) args.emplace_back(
"max", max);
415 english ? english :
"");
419 const char* english) {
421 if (
line >= 0) args.emplace_back(
"line",
line);
423 english ? english :
"");
428 english ? english :
"");
432 const char* english) {
441 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)
coded(RunFailureCode code, const RunFailureArgs &args, const Base &error)
RunFailureValidation validate_run_failure_name(std::string_view name, const RunFailureArgs &args) noexcept
Resolve an exact catalog name (excluding none) and validate/canonicalize through the same path as mak...
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
void pine_timezone_stop(const char *function, const char *zone, const char *english)
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 -...
std::string run_error_bar_prefix()
Stops using TradingView's text prepend "Error on bar N: " when a bar context is installed,...
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...
RunFailureValidationStatus
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::int64_t run_error_bar_index() noexcept
The same context's current bar index, or -1 when no context is installed.
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, std::nullptr_t)
RunFailureArg(const char *arg_name, Floating value)
RunFailureArg(const char *arg_name, Boolean value)
std::optional< RunFailureValue > value
RunFailureValidationStatus status
A validated code and its canonical arguments: the JSON object with its keys sorted and no whitespace,...
void observe_owned_storage(OwnedStorage &out) const noexcept
std::shared_ptr< const std::string > args