Skip to content

errors

Exceptions and return codes used internally.

External libraries should not used exceptions defined here.

BreakLoop

Bases: ExecutionPassed

Used by BREAK statement.

Source code in src/robot/errors.py
class BreakLoop(ExecutionPassed):
    """Used by BREAK statement."""

    def __init__(self):
        super().__init__("Invalid 'BREAK' usage.")

ContinueLoop

Bases: ExecutionPassed

Used by CONTINUE statement.

Source code in src/robot/errors.py
class ContinueLoop(ExecutionPassed):
    """Used by CONTINUE statement."""

    def __init__(self):
        super().__init__("Invalid 'CONTINUE' usage.")

DataError

Bases: RobotError

Used when the provided test data is invalid.

DataErrors are not caught by keywords that run other keywords (e.g. Run Keyword And Expect Error).

Source code in src/robot/errors.py
class DataError(RobotError):
    """Used when the provided test data is invalid.

    DataErrors are not caught by keywords that run other keywords
    (e.g. `Run Keyword And Expect Error`).
    """
    def __init__(self, message='', details='', syntax=False):
        super().__init__(message, details)
        self.syntax = syntax

ExecutionFailed

Bases: ExecutionStatus

Used for communicating failures in test execution.

Source code in src/robot/errors.py
class ExecutionFailed(ExecutionStatus):
    """Used for communicating failures in test execution."""

ExecutionPassed

Bases: ExecutionStatus

Base class for all exceptions communicating that execution passed.

Should not be raised directly, but more detailed exceptions used instead.

Source code in src/robot/errors.py
class ExecutionPassed(ExecutionStatus):
    """Base class for all exceptions communicating that execution passed.

    Should not be raised directly, but more detailed exceptions used instead.
    """

    def __init__(self, message=None, **kwargs):
        super().__init__(message, **kwargs)
        self._earlier_failures = []

    def set_earlier_failures(self, failures):
        if failures:
            self._earlier_failures = list(failures) + self._earlier_failures

    @property
    def earlier_failures(self):
        if not self._earlier_failures:
            return None
        return ExecutionFailures(self._earlier_failures)

    @property
    def status(self):
        return 'PASS' if not self._earlier_failures else 'FAIL'

ExecutionStatus

Bases: RobotError

Base class for exceptions communicating status in test execution.

Source code in src/robot/errors.py
class ExecutionStatus(RobotError):
    """Base class for exceptions communicating status in test execution."""

    def __init__(self, message, test_timeout=False, keyword_timeout=False,
                 syntax=False, exit=False, continue_on_failure=False,
                 skip=False, return_value=None):
        if '\r\n' in message:
            message = message.replace('\r\n', '\n')
        from robot.utils import cut_long_message
        super().__init__(cut_long_message(message))
        self.test_timeout = test_timeout
        self.keyword_timeout = keyword_timeout
        self.syntax = syntax
        self.exit = exit
        self._continue_on_failure = continue_on_failure
        self.skip = skip
        self.return_value = return_value

    @property
    def timeout(self):
        return self.test_timeout or self.keyword_timeout

    @property
    def dont_continue(self):
        return self.timeout or self.syntax or self.exit

    @property
    def continue_on_failure(self):
        return self._continue_on_failure

    @continue_on_failure.setter
    def continue_on_failure(self, continue_on_failure):
        self._continue_on_failure = continue_on_failure
        for child in getattr(self, '_errors', []):
            if child is not self:
                child.continue_on_failure = continue_on_failure

    def can_continue(self, context, templated=False):
        if context.dry_run:
            return True
        if self.syntax or self.exit or self.skip or self.test_timeout:
            return False
        if templated:
            return context.continue_on_failure(default=True)
        if self.keyword_timeout:
            if context.in_teardown:
                self.keyword_timeout = False
            return False
        return self.continue_on_failure or context.continue_on_failure()

    def get_errors(self):
        return [self]

    @property
    def status(self):
        return 'FAIL' if not self.skip else 'SKIP'

FrameworkError

Bases: RobotError

Can be used when the core framework goes to unexpected state.

It is good to explicitly raise a FrameworkError if some framework component is used incorrectly. This is pretty much same as 'Internal Error' and should of course never happen.

Source code in src/robot/errors.py
class FrameworkError(RobotError):
    """Can be used when the core framework goes to unexpected state.

    It is good to explicitly raise a FrameworkError if some framework
    component is used incorrectly. This is pretty much same as
    'Internal Error' and should of course never happen.
    """

Information

Bases: RobotError

Used by argument parser with --help or --version.

Source code in src/robot/errors.py
class Information(RobotError):
    """Used by argument parser with --help or --version."""

KeywordError

Bases: DataError

Used when no keyword is found or there is more than one match.

KeywordErrors are caught by keywords that run other keywords (e.g. Run Keyword And Expect Error).

Source code in src/robot/errors.py
class KeywordError(DataError):
    """Used when no keyword is found or there is more than one match.

    KeywordErrors are caught by keywords that run other keywords
    (e.g. `Run Keyword And Expect Error`).
    """
    def __init__(self, message='', details=''):
        super().__init__(message, details)

PassExecution

Bases: ExecutionPassed

Used by 'Pass Execution' keyword.

Source code in src/robot/errors.py
class PassExecution(ExecutionPassed):
    """Used by 'Pass Execution' keyword."""

    def __init__(self, message):
        super().__init__(message)

RemoteError

Bases: RobotError

Used by Remote library to report remote errors.

Source code in src/robot/errors.py
class RemoteError(RobotError):
    """Used by Remote library to report remote errors."""

    def __init__(self, message='', details='', fatal=False, continuable=False):
        super().__init__(message, details)
        self.ROBOT_EXIT_ON_FAILURE = fatal
        self.ROBOT_CONTINUE_ON_FAILURE = continuable

ReturnFromKeyword

Bases: ExecutionPassed

Used by 'RETURN' statement.

Source code in src/robot/errors.py
class ReturnFromKeyword(ExecutionPassed):
    """Used by 'RETURN' statement."""

    def __init__(self, return_value=None, failures=None):
        super().__init__("Invalid 'RETURN' usage.", return_value=return_value)
        if failures:
            self.set_earlier_failures(failures)

RobotError

Bases: Exception

Base class for Robot Framework errors.

Do not raise this method but use more specific errors instead.

Source code in src/robot/errors.py
class RobotError(Exception):
    """Base class for Robot Framework errors.

    Do not raise this method but use more specific errors instead.
    """

    def __init__(self, message='', details=''):
        super().__init__(message)
        self.details = details

    @property
    def message(self):
        return str(self)

TimeoutError

Bases: RobotError

Used when a test or keyword timeout occurs.

This exception is handled specially so that execution of the current test is always stopped immediately and it is not caught by keywords executing other keywords (e.g. Run Keyword And Expect Error).

Source code in src/robot/errors.py
class TimeoutError(RobotError):
    """Used when a test or keyword timeout occurs.

    This exception is handled specially so that execution of the
    current test is always stopped immediately and it is not caught by
    keywords executing other keywords (e.g. `Run Keyword And Expect Error`).
    """

    def __init__(self, message='', test_timeout=True):
        super().__init__(message)
        self.test_timeout = test_timeout

    @property
    def keyword_timeout(self):
        return not self.test_timeout

VariableError

Bases: DataError

Used when variable does not exist.

VariableErrors are caught by keywords that run other keywords (e.g. Run Keyword And Expect Error).

Source code in src/robot/errors.py
class VariableError(DataError):
    """Used when variable does not exist.

    VariableErrors are caught by keywords that run other keywords
    (e.g. `Run Keyword And Expect Error`).
    """
    def __init__(self, message='', details=''):
        super().__init__(message, details)