Skip to content

Argument conversion failing unexpectedly causes bad error messages with keywords and crashes elsewhere (e.g. with listeners) #5819

Closed

Description

@d-biehl

#5815 fixed crashes when a library import argument cannot be converted. Argument and variable conversion is used in many other places too, and most of them handle only ValueError. Argument conversion normally fails with ValueError, but built-in converters can also raise other exceptions. The whole execution then crashes with Unexpected error, exit code 255, and no log or report. #5815 already mentioned this for listeners.

Listener Listener.py:

from datetime import timedelta


class Listener:
    ROBOT_LISTENER_API_VERSION = 3

    def __init__(self, timeout: timedelta = timedelta()):
        self.timeout = timeout

Running robot --listener Listener.py:1e20 example.robot stops immediately:

[ ERROR ] Unexpected error: OverflowError: Python int too large to convert to C int

With --listener Listener.py:invalid the error is reported, and execution continues:

[ ERROR ] Taking listener 'Listener.py:invalid' into use failed: Importing listener '.../Listener.py' failed: Argument 'timeout' got value 'invalid' that cannot be converted to timedelta: Invalid time string 'invalid'.

Exceptions that I have seen escaping:

  • OverflowError from timedelta, for example with 1e20 or inf.
  • TypeError from set and frozenset with unhashable items, for example [[1]].

Affected places, all verified on current master (4a757d7) with Python 3.13:

  • Everything imported with robot.utils.Importer, because Importer._instantiate_class handles only ValueError:
    • --listener
    • library listeners given as strings with arguments
    • custom --console loggers
    • --prerunmodifier
    • --prerebotmodifier, with both robot and rebot. With robot, output.xml is written, but log.html and report.html are not.
    • --parser
  • Typed command line variables, such as --variable "X: timedelta:1e20". VariableScopes._convert_cli_variable handles only ValueError.
  • Typed variables in the Variables section, such as ${X: timedelta} 1e20, in suite and resource files. VariableResolver._convert handles only ValueError and TypeError.
  • With keyword calls the execution does not crash, but the failure is the raw OverflowError: Python int too large to convert to C int instead of the normal conversion error message.

TypeInfo.convert is public API and documents that it raises ValueError if conversion fails. With these inputs it raises OverflowError or TypeError instead.

This is not a regression. utils.Importer has supported argument conversion since RF 4.0, and typed variables have existed since RF 7.3.

Proposed fix: make TypeConverter.convert turn other exceptions into ValueError. CustomConverter has done the same with custom converters since RF 5.0 (#4088). Then TypeInfo.convert follows its documented contract, and all callers that already handle ValueError work without changes. RecursionError should still be re-raised. Otherwise deeply nested values of recursive type aliases would fall through to the next union member, such as str, and keywords would get silently converted data. TimeoutExceeded, KeyboardInterrupt and SystemExit are not Exceptions, so they are not affected.

Messages and behavior change only for these previously crashing or odd failures:

  • The normal conversion error format is used, for example ValueError: Argument 'arg' got value '1e20' that cannot be converted to timedelta: OverflowError: Python int too large to convert to C int instead of OverflowError: Python int too large to convert to C int.
  • In unions the next member type is tried, as with ValueError. For example, timedelta | float with 1e20 now gives the float 1e20.
  • Conversion based on the default value type works as with ValueError: the original value is used if conversion fails.

No existing ValueError message changes, and the existing unit and acceptance tests pass unchanged. This also does not replace the TODOs added in #5815 about ArgumentSpec.convert raising only DataErrors. It makes that change a bit easier, because only ValueErrors would need to be handled there.

Not covered, separate and much less likely: extremely deeply nested literals given to list, dict, and other converters that use ast.literal_eval can raise RecursionError or MemoryError ("Parser stack overflowed"). RF deliberately re-raises MemoryError, so these can still crash at the places listed above.

I'll submit a pull request with a fix.


AI/tooling disclosure: This issue was prepared with assistance from Claude Code. I reviewed the result manually, understand the reported problem, and verified it locally.

Activity

  1. pekkaklarck commented on Oct 22, 2026

    @pekkaklarck
    Member

    Good catch. This is a severe issue, but I don't think this is as severe as #5815 was. I agree converting all conversion errors to ValueErrors makes sense.

  2. added this to the v7.5.1 milestone on Oct 22, 2026
  3. added
    acknowledge
    on Oct 22, 2026
  4. added theissue type on Oct 22, 2026
  5. changed the title [-]Execution crashes if argument conversion fails with other exception than `ValueError`[/-] [+]Argument conversion failing unexpectedly causes bad error messages with keywords and crashes elsewhere (e.g. with listeners)[/+] on Oct 27, 2026
  6. added 2 commits that reference this issue on Oct 28, 2026
    ff8ce2c
    a0cb344
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledgeeffort: mediumpriority: high

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions