MCPcopy Create free account
hub / github.com/apache/fory / Error

Class Error

cpp/fory/util/error.h:100–305  ·  view source on GitHub ↗

Error class for Fory serialization and deserialization operations. This class supports two usage patterns: 1. Static factory functions for creating new errors (recommended for general use) 2. Mutable error pattern for performance-critical read paths ## Pattern 1: Static Factory Functions (General Use) ```cpp // CORRECT: Use static factory functions auto err = Error::type_error("Expected string

Source from the content-addressed store, hash-verified

98/// - Error::invalid() - For general invalid state
99/// - Error::unknown() - For generic errors
100class Error {
101public:
102 /// Default constructor - creates an "OK" (no error) state.
103 /// Used for stack-allocated error variables in read paths.
104 Error() : ok_(true), state_(nullptr) {}
105 // Static factory functions - Use these instead of constructors!
106
107 /// Creates a type mismatch error with the given type IDs.
108 static Error type_mismatch(uint32_t type_a, uint32_t type_b) {
109 return Error(ErrorCode::TypeMismatch,
110 "Type mismatch: type_a = " + std::to_string(type_a) +
111 ", type_b = " + std::to_string(type_b));
112 }
113
114 /// Creates a buffer out of bound error.
115 static Error buffer_out_of_bound(size_t offset, size_t length,
116 size_t capacity) {
117 return Error(ErrorCode::BufferOutOfBound,
118 "Buffer out of bound: " + std::to_string(offset) + " + " +
119 std::to_string(length) + " > " + std::to_string(capacity));
120 }
121
122 /// Creates an encoding error.
123 static Error encode_error(const std::string &msg) {
124 return Error(ErrorCode::EncodeError, msg);
125 }
126
127 /// Creates an invalid data error.
128 static Error invalid_data(const std::string &msg) {
129 return Error(ErrorCode::InvalidData, msg);
130 }
131
132 /// Creates an invalid reference error.
133 static Error invalid_ref(const std::string &msg) {
134 return Error(ErrorCode::InvalidRef, msg);
135 }
136
137 /// Creates an unknown enum error.
138 static Error unknown_enum(const std::string &msg) {
139 return Error(ErrorCode::UnknownEnum, msg);
140 }
141
142 /// Creates a type error.
143 static Error type_error(const std::string &msg) {
144 return Error(ErrorCode::TypeError, msg);
145 }
146
147 /// Creates an encoding format error.
148 static Error encoding_error(const std::string &msg) {
149 return Error(ErrorCode::EncodingError, msg);
150 }
151
152 /// Creates a depth exceeded error.
153 static Error depth_exceed(const std::string &msg) {
154 return Error(ErrorCode::DepthExceed, msg);
155 }
156
157 /// Creates an unsupported operation error.

Callers 15

type_mismatchMethod · 0.70
buffer_out_of_boundMethod · 0.70
encode_errorMethod · 0.70
invalid_dataMethod · 0.70
invalid_refMethod · 0.70
unknown_enumMethod · 0.70
type_errorMethod · 0.70
encoding_errorMethod · 0.70
depth_exceedMethod · 0.70
unsupportedMethod · 0.70
not_allowedMethod · 0.70

Calls 1

resetMethod · 0.65

Tested by

no test coverage detected