From 5e9a660fa2901eaecd124a9203a34d1f86f3b626 Mon Sep 17 00:00:00 2001 From: Patrick Urbanke Date: Thu, 4 Jan 2024 22:19:52 +0100 Subject: [PATCH] Fixed return type --- include/rfl/json/read.hpp | 6 +++++- include/rfl/xml/read.hpp | 2 +- include/rfl/yaml/read.hpp | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/rfl/json/read.hpp b/include/rfl/json/read.hpp index c8b7d926..89877bbd 100644 --- a/include/rfl/json/read.hpp +++ b/include/rfl/json/read.hpp @@ -6,6 +6,7 @@ #include #include +#include "../internal/wrap_in_rfl_array_t.hpp" #include "Parser.hpp" #include "Reader.hpp" @@ -24,9 +25,12 @@ auto read(const InputVarType& _obj) { /// Parses an object from JSON using reflection. template -auto read(const std::string& _json_str) { +Result> read(const std::string& _json_str) { using PtrType = std::unique_ptr; yyjson_doc* doc = yyjson_read(_json_str.c_str(), _json_str.size(), 0); + if (!doc) { + return Error("Could not parse document!"); + } const auto ptr = PtrType(doc, yyjson_doc_free); return read(InputVarType(yyjson_doc_get_root(doc))); } diff --git a/include/rfl/xml/read.hpp b/include/rfl/xml/read.hpp index e5a26968..a13d45c2 100644 --- a/include/rfl/xml/read.hpp +++ b/include/rfl/xml/read.hpp @@ -24,7 +24,7 @@ auto read(const InputVarType& _var) { /// Parses an object from XML using reflection. template -auto read(const std::string& _xml_str) { +Result read(const std::string& _xml_str) { pugi::xml_document doc; const auto result = doc.load_string(_xml_str.c_str()); if (!result) { diff --git a/include/rfl/yaml/read.hpp b/include/rfl/yaml/read.hpp index ba10de70..e3b38ec8 100644 --- a/include/rfl/yaml/read.hpp +++ b/include/rfl/yaml/read.hpp @@ -6,6 +6,7 @@ #include #include +#include "../internal/wrap_in_rfl_array_t.hpp" #include "Parser.hpp" #include "Reader.hpp" @@ -23,7 +24,7 @@ auto read(const InputVarType& _var) { /// Parses an object from YAML using reflection. template -auto read(const std::string& _yaml_str) { +Result> read(const std::string& _yaml_str) { try { const auto var = InputVarType(YAML::Load(_yaml_str)); return read(var);