Part 6 (Unhandled Errors)

When you exit your pipeline with CTRL+C, you may notice a stack trace thrown:

$ ./build/tutorial_pipeline
(2022-02-02 14:04:56.829) [info] (http_server_stage.cc:874) HTTP Server is listening on "0.0.0.0:8080".
^C***** INTERRUPT *****
(2022-02-02 14:04:57.633) [info] (realtime_executor.cc:327) Shutting down all stages...
terminate called after throwing an instance of 'std::runtime_error'
  what():  Received interrupt request, aborted execution early.
***** CAUGHT SIGABRT *****
PC@            226294c ark::core::(anonymous namespace)::failure_signal_handler(int, siginfo_t*, void*) at /home/desktop/ark/ark/core/backtrace.cc:375
PC@       7f5fc37913bf (unknown)
PC@       7f5fc348118b raise
PC@       7f5fc3460858 abort
PC@            2291e99 __gnu_cxx::__verbose_terminate_handler() [clone .cold]
PC@            2290925 __cxxabiv1::__terminate(void (*)())
PC@            2290960 std::terminate()
PC@            2290a83 __cxa_throw
PC@            22702a2 __wrap___cxa_throw at /home/desktop/ark/ark/core/throw.cc:46
PC@             834f9c void ark::main::(anonymous namespace)::execute_pipeline<ark::pipeline::RealTimeExecutor>(int, char const**, ark::pipeline::Pipeline, ark::main::MainOffboardConfiguration const&) at /home/desktop/ark/ark/main/main_offboard.cc:377
PC@             832955 ark::main::execute_realtime_pipeline(int, char const**, ark::pipeline::Pipeline, ark::main::MainOffboardConfiguration) at /home/desktop/ark/ark/main/main_offboard.cc:633
PC@             82547f main at /home/desktop/ark/tutorial/pipeline/tutorial_pipeline.cc:17
PC@       7f5fc34620b2 __libc_start_main
PC@             82502d _start
PC@   ffffffffffffffff (unknown)

This is normal. When your pipeline encounters an unhandled signal or exception, it will print a stack trace of the offending location.

We can avoid the stack trace by print error messages out more gracefully.

Let’s do so now by adjusting our ${APP_ROOT}/tutorial/pipeline/tutorial_pipeline.cc:

#include "tutorial/first_stage/first_stage.hh"
#include "tutorial/second_stage/second_stage.hh"

#include "ark/comms/stages/http_server_stage.hh"
#include "ark/debuglog/log.hh"
#include "ark/main/main_offboard.hh"

int main(int argc, const char **argv)
{
    ark::pipeline::Pipeline pipeline;

    pipeline.add_stage<FirstStage>();
    pipeline.add_stage<ark::comms::HttpServerStage>();
    pipeline.add_stage<SecondStage>("SecondStage");

    try
    {
        return ark::main::execute_realtime_pipeline(argc, argv, std::move(pipeline));
    }
    catch (const std::exception &exception)
    {
        LERROR("Exiting due to error: {}", exception.what());
        return 1;
    }
}

Update your pipeline’s CMakeLists.txt file to include the debug logger:

add_executable(tutorial_pipeline tutorial_pipeline.cc)

target_link_libraries(
    tutorial_pipeline
    PRIVATE first_stage second_stage ark::main_offboard ark::http_server_stage ark::debuglog)

We’ll next discuss creating multiple instances of the same stage in Part 7.