diff --git a/include/mgp.hpp b/include/mgp.hpp index ba5002c3f..5f36c5e58 100644 --- a/include/mgp.hpp +++ b/include/mgp.hpp @@ -4401,11 +4401,12 @@ inline ExecutionResult::ExecutionResult(mgp_execution_result *result, mgp_graph inline ExecutionHeaders ExecutionResult::Headers() const { return mgp::fetch_execution_headers(result_); }; inline std::optional ExecutionResult::PullOne() const { - try { - return ExecutionRow(mgp::MemHandlerCallback(pull_one, result_, graph_)); - } catch (const std::exception &e) { + auto value = mgp::MemHandlerCallback(pull_one, result_, graph_); + if (!value) { return std::nullopt; } + + return ExecutionRow(value); } inline bool ExecutionHeaders::Iterator::operator==(const Iterator &other) const { diff --git a/src/query/procedure/mg_procedure_impl.cpp b/src/query/procedure/mg_procedure_impl.cpp index 9778ad1b0..824a8cad5 100644 --- a/src/query/procedure/mg_procedure_impl.cpp +++ b/src/query/procedure/mg_procedure_impl.cpp @@ -4128,12 +4128,17 @@ mgp_error mgp_fetch_execution_headers(mgp_execution_result *exec_result, mgp_exe mgp_error mgp_pull_one(mgp_execution_result *exec_result, mgp_graph *graph, mgp_memory *memory, mgp_map **result) { return WrapExceptions( - [exec_result, graph, memory]() { + [exec_result, graph, memory]() -> mgp_map * { MgProcedureResultStream stream(memory); - exec_result->pImpl->interpreter->Pull(&stream, 1, {}); + + try { + exec_result->pImpl->interpreter->Pull(&stream, 1, {}); + } catch (const std::exception &e) { + return nullptr; + } if (stream.rows.empty()) { - throw std::out_of_range("Out of range pull since query does not remove anything!"); + return nullptr; } const size_t headers_size = exec_result->pImpl->headers->headers.size();