PineForge HPO 1.11.0
Native hyperparameter optimization for PineForge strategies
Loading...
Searching...
No Matches
error.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <map>
5#include <optional>
6#include <stdexcept>
7#include <string>
8#include <utility>
9#include <variant>
10
11namespace pineforge::hpo {
12
14enum class FailureOrigin : std::uint8_t { Hpo, Engine };
15
18public:
20 using Value =
21 std::variant<std::nullptr_t, bool, std::int64_t, std::uint64_t, double, std::string>;
23 ErrorArgument(std::nullptr_t value) : value_(value) {}
25 ErrorArgument(bool value) : value_(value) {}
27 ErrorArgument(std::int64_t value) : value_(value) {}
29 ErrorArgument(std::uint64_t value) : value_(value) {}
31 ErrorArgument(double value) : value_(value) {}
33 ErrorArgument(const char* value) : value_(std::string(value)) {}
35 ErrorArgument(std::string value) : value_(std::move(value)) {}
37 const Value& value() const noexcept { return value_; }
38
39private:
40 Value value_;
41};
42
44using ErrorArguments = std::map<std::string, ErrorArgument>;
45
48class HpoError {
49public:
52 : code_(std::move(code)), args_(std::move(args)), origin_(origin) {}
53 virtual ~HpoError() = default;
55 virtual const char* what() const noexcept = 0;
57 const std::string& code() const noexcept { return code_; }
59 const ErrorArguments& args() const noexcept { return args_; }
61 FailureOrigin origin() const noexcept { return origin_; }
62
63private:
64 std::string code_;
65 ErrorArguments args_;
66 FailureOrigin origin_;
67};
68
70template <typename Base = std::runtime_error>
71class TypedHpoError : public Base, public HpoError {
72public:
74 TypedHpoError(std::string code,
76 const std::string& message,
78 : Base(message), HpoError(std::move(code), std::move(args), origin) {}
80 const char* what() const noexcept override { return Base::what(); }
81};
82
84class EngineError : public TypedHpoError<> {
85public:
87 EngineError(std::optional<std::string> code,
88 std::optional<std::string> args,
89 const std::string& message)
90 : TypedHpoError<>(code.value_or(""), {}, message, FailureOrigin::Engine),
91 raw_args_(std::move(args)) {}
93 const std::optional<std::string>& raw_args() const noexcept { return raw_args_; }
94
95private:
96 std::optional<std::string> raw_args_;
97};
98
99} // namespace pineforge::hpo
An engine-owned failure whose optional metadata is forwarded without reclassification.
Definition error.hpp:84
const std::optional< std::string > & raw_args() const noexcept
Returns the untrusted engine JSON for transport validation, or unavailable metadata.
Definition error.hpp:93
EngineError(std::optional< std::string > code, std::optional< std::string > args, const std::string &message)
Preserves unavailable getters as null metadata and the original diagnostic text.
Definition error.hpp:87
A typed JSON scalar; strings in HPO-owned arguments use closed catalog vocabularies.
Definition error.hpp:17
ErrorArgument(std::string value)
Constructs a string argument.
Definition error.hpp:35
ErrorArgument(std::uint64_t value)
Constructs an unsigned integer argument.
Definition error.hpp:29
ErrorArgument(std::nullptr_t value)
Constructs a null argument.
Definition error.hpp:23
ErrorArgument(bool value)
Constructs a Boolean argument.
Definition error.hpp:25
const Value & value() const noexcept
Returns the scalar value.
Definition error.hpp:37
std::variant< std::nullptr_t, bool, std::int64_t, std::uint64_t, double, std::string > Value
Supported scalar types, including exact signed and unsigned persistence integers.
Definition error.hpp:21
ErrorArgument(const char *value)
Constructs a string argument without converting string literals to Boolean.
Definition error.hpp:33
ErrorArgument(std::int64_t value)
Constructs a signed integer argument.
Definition error.hpp:27
ErrorArgument(double value)
Constructs a numeric argument.
Definition error.hpp:31
Stable machine-readable failure metadata shared by the standard exception families.
Definition error.hpp:48
FailureOrigin origin() const noexcept
Returns the component which owns the code.
Definition error.hpp:61
const std::string & code() const noexcept
Returns the stable failure code, never inferred from diagnostic text.
Definition error.hpp:57
virtual ~HpoError()=default
HpoError(std::string code, ErrorArguments args={}, FailureOrigin origin=FailureOrigin::Hpo)
Constructs metadata; HPO codes and argument vocabularies are defined by the catalog.
Definition error.hpp:51
virtual const char * what() const noexcept=0
Returns the unchanged legacy English diagnostic.
const ErrorArguments & args() const noexcept
Returns typed, catalog-declared scalar arguments.
Definition error.hpp:59
Adds stable metadata while preserving a standard exception's catch compatibility.
Definition error.hpp:71
TypedHpoError(std::string code, ErrorArguments args, const std::string &message, FailureOrigin origin=FailureOrigin::Hpo)
Constructs a coded exception with unchanged English text and optional provenance.
Definition error.hpp:74
const char * what() const noexcept override
Returns the original standard exception diagnostic.
Definition error.hpp:80
FailureOrigin
Provenance of a failure, independent of its human-readable diagnostic.
Definition error.hpp:14
std::map< std::string, ErrorArgument > ErrorArguments
Deterministically ordered failure arguments. No strategy-computed value belongs here.
Definition error.hpp:44