Skip to content

Commit b4ced5e

Browse files
author
KostinPavel
committed
add avro error as throw
correct1
1 parent d645285 commit b4ced5e

3 files changed

Lines changed: 4 additions & 24 deletions

File tree

include/rfl/avro/Writer.hpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,9 @@ class Writer {
191191
private:
192192
template <class T>
193193
void set_value(const T& _var, avro_value_t* _val) const {
194-
std::cout << "[DEBUG] set_value called with type: " << typeid(T).name() << std::endl;
195-
196194
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
197-
std::cout << "[DEBUG] Processing std::string: " << _var << std::endl;
198195
int result = avro_value_set_string_len(_val, _var.c_str(), _var.size() + 1);
199196
if (result != 0) {
200-
std::cout << "[DEBUG] avro_value_set_string_len failed with result: " << result << std::endl;
201197
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
202198
}
203199
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
@@ -206,61 +202,43 @@ class Writer {
206202
rfl::Vectorstring>()) {
207203
auto var = _var;
208204
if (!var.data()) {
209-
std::cout << "[DEBUG] Bytestring/Vectorstring has no data" << std::endl;
210205
return;
211206
}
212-
std::cout << "[DEBUG] Processing Bytestring/Vectorstring of size: " << var.size() << std::endl;
213207
int result = avro_value_set_bytes(_val, var.data(), var.size());
214208
if (result != 0) {
215-
std::cout << "[DEBUG] avro_value_set_bytes failed with result: " << result << std::endl;
216209
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
217210
}
218211
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
219-
std::cout << "[DEBUG] Processing bool: " << _var << std::endl;
220212
int result = avro_value_set_boolean(_val, _var);
221213
if (result != 0) {
222-
std::cout << "[DEBUG] avro_value_set_boolean failed with result: " << result << std::endl;
223214
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
224215
}
225216
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
226-
std::cout << "[DEBUG] Processing floating point: " << _var << std::endl;
227217
int result = avro_value_set_double(_val, static_cast<double>(_var));
228218
if (result != 0) {
229-
std::cout << "[DEBUG] avro_value_set_double failed with result: " << result << std::endl;
230219
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
231220
}
232221
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
233-
std::cout << "[DEBUG] Processing integral: " << _var << std::endl;
234222
int result = avro_value_set_long(_val, static_cast<std::int64_t>(_var));
235223
if (result != 0) {
236-
std::cout << "[DEBUG] avro_value_set_long failed with result: " << result << std::endl;
237224
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
238225
}
239226
} else if constexpr (internal::is_literal_v<T>) {
240-
std::cout << "[DEBUG] Processing literal enum: " << static_cast<int>(_var.value()) << std::endl;
241227
int result = avro_value_set_enum(_val, static_cast<int>(_var.value()));
242228
if (result != 0) {
243-
std::cout << "[DEBUG] avro_value_set_enum failed with result: " << result << std::endl;
244229
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
245230
}
246231
} else if constexpr (internal::is_validator_v<T>) {
247-
std::cout << "[DEBUG] Processing validator type" << std::endl;
248-
// Для валидаторов используем внутреннее значение
249232
using ValueType = std::remove_cvref_t<typename T::ReflectionType>;
250233
const auto val = _var.value();
251234
set_value<ValueType>(val, _val);
252235
} else if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Timestamp<"%Y-%m-%d">>()) {
253-
std::cout << "[DEBUG] Processing Timestamp" << std::endl;
254-
// Конвертируем Timestamp в строку
255236
const auto str = _var.to_string();
256237
set_value<std::string>(str, _val);
257238
} else if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Email>()) {
258-
std::cout << "[DEBUG] Processing Email" << std::endl;
259-
// Email является паттерном на базе std::string, используем внутреннее значение
260239
const auto& str = static_cast<const std::string&>(_var);
261240
set_value<std::string>(str, _val);
262241
} else {
263-
std::cout << "[DEBUG] Unsupported type reached: " << typeid(T).name() << std::endl;
264242
static_assert(rfl::always_false_v<T>, "Unsupported type.");
265243
}
266244
}

include/rfl/avro/read.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,18 @@ Result<internal::wrap_in_rfl_array_t<T>> read(
3939
int res = avro_generic_value_new(_schema.iface(), &root);
4040
if (res != 0) {
4141
avro_value_decref(&root);
42+
avro_reader_free(avro_reader);
4243
return error(std::string("Could not read root value: ") + avro_strerror());
4344
}
4445
res = avro_value_read(avro_reader, &root);
4546
if (res) {
46-
avro_reader_free(avro_reader);
4747
avro_value_decref(&root);
48+
avro_reader_free(avro_reader);
4849
return error(std::string("Could not read root value: ") + avro_strerror());
4950
}
5051
auto result = read<T, Ps...>(InputVarType{&root});
51-
avro_reader_free(avro_reader);
5252
avro_value_decref(&root);
53+
avro_reader_free(avro_reader);
5354
return result;
5455
}
5556

include/rfl/avro/write.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ std::vector<char> write(const auto& _obj, const auto& _schema) {
2525
avro_value_t root;
2626
int result = avro_generic_value_new(_schema.iface(), &root);
2727
if (result != 0) {
28+
avro_value_decref(&root);
2829
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
2930
}
3031
const auto writer = Writer(&root);

0 commit comments

Comments
 (0)