# Troubleshooting

Site [llms.txt](/llms.txt)

---

This page provides some common issues that can occur, particulary when working with ROS, and more specifically, writing tests with ROS.

## ROS

### Failing Tests Due to Non-allowable Exit Codes (ROS2 launch_testing)

It is relatively common to test that all nodes, processes etc. have shutdown gracefully. The example below shows how this can be done using `launch_testing` against a particular process (in this case the controller). 

```python
launch_testing.asserts.assertExitCodes(
    proc_info, [launch_testing.asserts.EXIT_OK], controller_process
)
```

If the process does not exit cleanly, you may get an error code of `-6` and the line `terminate called without an active exception`. This error code typically indicates that the process was terminated due to an unhandled exception or signal.

You may be able to resolve this by making sure that not only `rclpy` is made to shutdown gracefully (if using Python), but also any threads that have been started. The below example demonstrates this:

```python
import rclpy
from threading import Thread

...

def main(args=None):
    rclpy.init(args=args)
    my_node = MyNode()
    executor = rclpy.executors.MultiThreadedExecutor(4)
    executor.add_node(my_node)

    # Start the executor in a separate thread
    executor_thread = Thread(target=executor.spin, daemon=True)
    executor_thread.start()

    try:
        my_node.my_initiating_function()
    except KeyboardInterrupt:
        pass
    finally:
        # Shutdown the executor and wait for the thread to terminate
        executor.shutdown()
        executor_thread.join()
        rclpy.shutdown()

if __name__ == '__main__':
    main()
```

> [!NOTE] Summary
> In this example:
>
> * We initialize rclpy and add our node.
> * We create a MultiThreadedExecutor and add the node to it.
> * We start the executor in a separate thread.
> * In the finally block, we ensure that the executor is shut down and the executor thread waits until it is terminated.
