PineForge HPO 1.11.0
Native hyperparameter optimization for PineForge strategies
Loading...
Searching...
No Matches
error.py
Go to the documentation of this file.
1"""Stable failure metadata, independent of human-readable exception text."""
2
3from __future__ import annotations
4
5from typing import Any
6
7
8class HpoError(Exception):
9 """Exception base preserving legacy types and exposing typed failure args.
10
11 ``str(error)`` and ``error.args`` retain the legacy message contract.
12 ``error.failure_args`` is the scalar JSON object used by the failure protocol.
13 """
14
15 code: str | None = "hpo_unclassified_error"
16 origin = "hpo"
17
18 @property
19 def failure_args(self) -> dict[str, Any] | None:
20 arguments = getattr(self, "_failure_args", {})
21 return dict(arguments) if arguments is not None else None
22
24 self, code: str | None, args: dict[str, Any] | None, origin: str = "hpo"
25 ):
26 self.codecode = code
27 self._failure_args = dict(args) if args is not None else None
28 self.originorigin = origin
29 return self
30
31
32def failure_document(error: BaseException, exit_code: int) -> dict[str, Any]:
33 return {
34 "schema_version": 1,
35 "ok": False,
36 "failure": {
37 "origin": getattr(error, "origin", "hpo"),
38 "code": getattr(error, "code", "hpo_unclassified_error"),
39 "args": error.failure_args if isinstance(error, HpoError) else {},
40 "exit_code": exit_code,
41 },
42 }
with_failure(self, str|None code, dict[str, Any]|None args, str origin="hpo")
Definition error.py:25
dict[str, Any]|None failure_args(self)
Definition error.py:19
dict[str, Any] failure_document(BaseException error, int exit_code)
Definition error.py:32