INNER CODE UNIT · Python
declare_error_code
pineforge-4pass/pineforge-engine · tutorial/run.py:141
def declare_error_code(lib: ctypes.CDLL) -> None:
for name in ("strategy_get_last_error_code", "strategy_get_last_error_args"):
if hasattr(lib, name):
getattr(lib, name).argtypes = [ctypes.c_void_p]
getattr(lib, name).restype = ctypes.c_char_p
if hasattr(lib, "strategy_last_run_status"):
lib.strategy_last_run_status.argtypes = [ctypes.c_void_p]
lib.strategy_last_run_status.restype = ctypes.c_int
def error_code(lib: ctypes.CDLL, state) -> str:
"""'<code> <args JSON>' of the last failure on state, or '' without one."""
if not hasattr(lib, "strategy_get_last_error_code"):
return ""
code = lib.strategy_get_last_error_code(state)
if not code:
return ""
args = (lib.strategy_get_last_error_args(state)