robokudo.utils.error_handling

Error handling utilities for RoboKudo.

This module provides error handling utilities for behavior trees.

module:

error_handling

synopsis:

Error handling utilities for behavior trees

moduleauthor:

RoboKudo Team

Dependencies:
  • py_trees

  • robokudo.identifier

  • functools.wraps

  • traceback

Functions

raise_to_blackboard(exception)

Store exception in blackboard.

has_blackboard_exception()

Check if blackboard contains an exception.

get_blackboard_exception()

Retrieve exception from blackboard.

clear_blackboard_exception()

Clear any stored exception from blackboard.

catch_and_raise_to_blackboard(...)

Catch and store exceptions in blackboard.

Module Contents

robokudo.utils.error_handling.raise_to_blackboard(exception)

Store exception in blackboard.

Parameters:

exception (Exception or None) – Exception to store or None to clear

Example:

try:
    # Some code that might raise
    pass
except Exception as e:
    raise_to_blackboard(e)
robokudo.utils.error_handling.has_blackboard_exception()

Check if blackboard contains an exception.

Returns:

True if exception exists and is not None

Return type:

bool

Example:

if has_blackboard_exception():
    # Handle exception
    pass
robokudo.utils.error_handling.get_blackboard_exception()

Retrieve exception from blackboard.

Returns:

Stored exception or None if not found

Return type:

Exception or None

Example:

exc = get_blackboard_exception()
if exc is not None:
    # Handle exception
    pass
robokudo.utils.error_handling.clear_blackboard_exception()

Clear any stored exception from blackboard.

Example:

clear_blackboard_exception()
assert not has_blackboard_exception()
robokudo.utils.error_handling.catch_and_raise_to_blackboard(function: Callable) py_trees.common.Status | Callable

Catch and store exceptions in blackboard.

This decorator is used to catch exceptions in Annotators to place them into the blackboard. Mostly useful in analysis-engines that have a query-interface which should return a failure back to the action-server caller if one of the Annotators yields an exception.

Returns:

Parameters:

function (callable) – The update or compute method of the desired Annotator

Returns:

Exception that has been catched or found in the Blackboard or wrapped function that handles exceptions

Return type:

Union[py_trees.Status.FAILURE, Callable]

Example:

@catch_and_raise_to_blackboard
def update(self) -> py_trees.common.Status:
    # Method code here
    pass

Warning

Should not be used on ThreadedAnnotators