From fd8d8d4bfa6e3a01fd0f3e8b552155da47f34367 Mon Sep 17 00:00:00 2001 From: Ryan Olson Date: Tue, 14 Jun 2022 04:50:03 +0000 Subject: [PATCH] take action earlier with respect to exception throw while updating --- src/internal/pipeline/controller.cpp | 11 ++++++++++- src/tests/test_pipeline.cpp | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/internal/pipeline/controller.cpp b/src/internal/pipeline/controller.cpp index df8b65a74..015708d3d 100644 --- a/src/internal/pipeline/controller.cpp +++ b/src/internal/pipeline/controller.cpp @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -57,7 +58,15 @@ void Controller::on_data(ControlMessage&& message) switch (message.type) { case ControlMessageType::Update: - update(std::move(message.addresses)); + try + { + update(std::move(message.addresses)); + } catch (...) + { + LOG(ERROR) << "exception caught while performing update - this is fatal - issuing kill"; + kill(); + std::rethrow_exception(std::current_exception()); + } break; case ControlMessageType::Stop: stop(); diff --git a/src/tests/test_pipeline.cpp b/src/tests/test_pipeline.cpp index d1ee7d419..aa1cdd0d1 100644 --- a/src/tests/test_pipeline.cpp +++ b/src/tests/test_pipeline.cpp @@ -63,6 +63,7 @@ #include #include #include +#include #include #include #include @@ -194,6 +195,13 @@ TEST_F(TestPipeline, LifeCycleStop) run_manager(std::move(pipeline), true); } +TEST_F(TestPipeline, InitializerThrows) +{ + auto pipeline = srf::make_pipeline(); + auto segment = pipeline->make_segment("seg_1", [](segment::Builder& s) { throw std::runtime_error("no bueno"); }); + EXPECT_ANY_THROW(run_manager(std::move(pipeline))); +} + TEST_F(TestPipeline, DuplicateNameInSegment) { auto pipeline = srf::make_pipeline();