From a4c879eb85e4299edd7d980d02ed3b9b1c657fc3 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Wed, 25 Nov 2020 14:49:18 +0100 Subject: [PATCH] fix segfault --- consumer/api/cpp/src/data_broker.cpp | 4 ++-- consumer/api/python/asapo_consumer.pyx.in | 6 +++--- .../consumer/consumer_api_python/consumer_api.py | 9 +++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/consumer/api/cpp/src/data_broker.cpp b/consumer/api/cpp/src/data_broker.cpp index 7ab6f2c04..755713044 100644 --- a/consumer/api/cpp/src/data_broker.cpp +++ b/consumer/api/cpp/src/data_broker.cpp @@ -1,7 +1,7 @@ #include <common/networking.h> #include "consumer/data_broker.h" #include "server_data_broker.h" - +#include "consumer//consumer_error.h" namespace asapo { @@ -10,7 +10,7 @@ std::unique_ptr<DataBroker> Create(const std::string& source_name, Error* error, Args&& ... args) noexcept { if (source_name.empty()) { - error->reset(new SimpleError("Empty Data Source")); + *error = ConsumerErrorTemplates::kWrongInput.Generate("Empty Data Source"); return nullptr; } diff --git a/consumer/api/python/asapo_consumer.pyx.in b/consumer/api/python/asapo_consumer.pyx.in index 67de7608c..bb37ba89c 100644 --- a/consumer/api/python/asapo_consumer.pyx.in +++ b/consumer/api/python/asapo_consumer.pyx.in @@ -335,11 +335,11 @@ cdef class __PyDataBrokerFactory: cdef unique_ptr[DataBroker] c_broker with nogil: c_broker = self.c_factory.CreateServerBroker(b_server_name,b_source_path,b_has_filesystem,source,&err) + if err: + throw_exception(err) broker = PyDataBroker() broker.c_broker = c_broker.release() broker.c_broker.SetTimeout(timeout) - if err: - throw_exception(err) return broker def create_server_broker(server_name,source_path,has_filesystem,beamtime_id,stream,token,timeout_ms): @@ -354,7 +354,7 @@ def create_server_broker(server_name,source_path,has_filesystem,beamtime_id,stre :rtype: Tuple with broker object and error. """ factory = __PyDataBrokerFactory() - return factory.create_server_broker(_bytes(server_name),_bytes(source_path),has_filesystem, _bytes(beamtime_id),_bytes(stream),_bytes(token),timeout_ms) + return factory.create_server_broker(server_name,source_path,has_filesystem, beamtime_id,stream,token,timeout_ms) __version__ = "@PYTHON_ASAPO_VERSION@@ASAPO_VERSION_COMMIT@" diff --git a/tests/automatic/consumer/consumer_api_python/consumer_api.py b/tests/automatic/consumer/consumer_api_python/consumer_api.py index f830ac031..98f1d29f9 100644 --- a/tests/automatic/consumer/consumer_api_python/consumer_api.py +++ b/tests/automatic/consumer/consumer_api_python/consumer_api.py @@ -202,6 +202,15 @@ def check_single(broker, group_id): else: exit_on_noerr("AsapoBrokerServersNotFound") + try: + asapo_consumer.create_server_broker("", "", True, "", "", "", 1000) + except asapo_consumer.AsapoWrongInputError as err: + print(err) + pass + else: + exit_on_noerr("should be AsapoWrongInputError") + + def check_dataset(broker, group_id): res = broker.get_next_dataset(group_id) -- GitLab