Skip to content

Execution crashes if library import argument cannot be converted #5815

Closed

Description

@d-biehl

If a library is imported with an argument that cannot be converted to the type its __init__ expects, the whole execution crashes with Unexpected error. Other invalid library imports, for example with a wrong number of arguments, are reported as errors and execution continues.

Library ServerLib.py:

class ServerLib:

    def __init__(self, host: str = "localhost", port: int = 8270):
        self.host = host
        self.port = port

    def connect(self):
        pass

Test example.robot:

*** Settings ***
Library    ServerLib.py    port=80x

*** Test Cases ***
Example
    Connect

Running robot example.robot stops immediately:

[ ERROR ] Unexpected error: ValueError: Argument 'port' got value '80x' that cannot be converted to integer.

The exit code is 255 and log.html and report.html are not created. Execution stops at the failing import, so no other suites are run after it either. The same happens with --dryrun.

Full traceback
[ ERROR ] Unexpected error: ValueError: Argument 'port' got value '80x' that cannot be converted to integer.
Traceback (most recent call last):
  File ".../site-packages/robot/running/arguments/typeconverters.py", line 351, in _string_convert
    return int(value, base)
ValueError: invalid literal for int() with base 10: '80x'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../site-packages/robot/running/arguments/typeconverters.py", line 141, in convert
    return self._string_convert(value)
  File ".../site-packages/robot/running/arguments/typeconverters.py", line 362, in _string_convert
    raise ValueError
ValueError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File ".../site-packages/robot/utils/application.py", line 97, in _execute
    rc = self.main(arguments, **options)
  File ".../site-packages/robot/run.py", line 496, in main
    result = suite.run(settings)
  File ".../site-packages/robot/running/model.py", line 921, in run
    self.visit(runner)
  File ".../site-packages/robot/model/testsuite.py", line 470, in visit
    visitor.visit_suite(self)
  File ".../site-packages/robot/model/visitor.py", line 129, in visit_suite
    if self.start_suite(suite) is not False:
  File ".../site-packages/robot/running/suiterunner.py", line 92, in start_suite
    ns.handle_imports()
  File ".../site-packages/robot/running/namespace.py", line 61, in handle_imports
    self._handle_imports(self._imports)
  File ".../site-packages/robot/running/namespace.py", line 72, in _handle_imports
    self._import(item)
  File ".../site-packages/robot/running/namespace.py", line 82, in _import
    action(import_setting)
  File ".../site-packages/robot/running/namespace.py", line 144, in _import_library
    lib = IMPORTER.import_library(name, import_.args, import_.alias, self.variables)
  File ".../site-packages/robot/running/importer.py", line 53, in import_library
    lib = TestLibrary.from_name(
        name,
    ...<2 lines>...
        create_keywords=False,
    )
  File ".../site-packages/robot/running/testlibraries.py", line 169, in from_name
    return cls.from_code(
        code, name, real_name, source, args, variables, create_keywords, logger
    )
  File ".../site-packages/robot/running/testlibraries.py", line 194, in from_code
    return cls.from_class(
        code, name, real_name, source, args, variables, create_keywords, logger
    )
  File ".../site-packages/robot/running/testlibraries.py", line 230, in from_class
    return library.from_class(
        klass, name, real_name, source, args, variables, create_keywords, logger
    )
  File ".../site-packages/robot/running/testlibraries.py", line 384, in from_class
    positional, named = init.args.resolve(args, variables=variables)
  File ".../site-packages/robot/running/arguments/argumentspec.py", line 155, in resolve
    return self.convert(
        positional,
    ...<3 lines>...
        languages=languages,
    )
  File ".../site-packages/robot/running/arguments/argumentspec.py", line 173, in convert
    positional, named = converter.convert(positional, named)
  File ".../site-packages/robot/running/arguments/argumentconverter.py", line 45, in convert
    return self._convert_positional(positional), self._convert_named(named)
  File ".../site-packages/robot/running/arguments/argumentconverter.py", line 61, in _convert_named
    (name, self._convert(name if name in names else var_named, value))
  File ".../site-packages/robot/running/arguments/argumentconverter.py", line 120, in _convert
    raise conversion_error
  File ".../site-packages/robot/running/arguments/argumentconverter.py", line 93, in _convert
    return converter.convert(value, name)
  File ".../site-packages/robot/running/arguments/typeconverters.py", line 143, in convert
    return self._handle_error(value, name, kind, error)
  File ".../site-packages/robot/running/arguments/typeconverters.py", line 189, in _handle_error
    raise ValueError(
        f"{kind} '{name}' got value '{value}'{typ} that {cannot_be_converted}"
    )
ValueError: Argument 'port' got value '80x' that cannot be converted to integer.

With a wrong number of arguments, for example Library ServerLib.py a b c, the import fails as expected and the run continues:

[ ERROR ] Error in file '.../example.robot' on line 2: Library 'ServerLib' expected 0 to 2 arguments, got 3.

The test then fails with No keyword with name 'Connect' found. and the log and the report are created normally.

The cause is that ClassLibrary.from_class calls init.args.resolve() without handling errors, and Namespace handles only DataError when it processes imports. Argument conversion normally fails with ValueError, but built-in converters can raise other exceptions as well. For example, timeout=1e20 with a timedelta argument fails with OverflowError: Python int too large to convert to C int, and that crashes the execution in the same way.

Conversion errors are handled in other places. Invalid arguments to variable files are reported as Processing variable file '...' with arguments [...] failed: ValueError: .... utils.Importer, which is used for example with listeners, turns ValueError into DataError. The Import Library keyword and Libdoc report the error as well. utils.Importer handles only ValueError, though, so a listener argument that fails with OverflowError crashes the execution too. An example is --listener Listener.py:1e20 with a timedelta argument.

This is not a regression. It has been like this since Robot Framework 3.1, which added automatic argument conversion (#2890, #2932). With 3.0.4 the example runs, and port simply gets the string 80x. Every version from 3.1 on that I tested crashes in the same way: 3.1, 3.1.2, 3.2.2, 4.0 and 4.1.3 on Python 3.9, 5.0.1, 6.0.2, 6.1.1, 7.0.1, 7.1.1, 7.2.2, 7.3.2, 7.4.2 and 7.5 on Python 3.10 and 3.14, and the current master (fe64590) on Python 3.13. For example:

Robot Framework 7.5 (Python 3.14.8 on linux)

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. added this to the v7.5.1 milestone on Oct 22, 2026
  2. added theissue type on Oct 22, 2026
  3. pekkaklarck commented on Oct 22, 2026

    @pekkaklarck
    Member

    Wow, this is rather bad! Crashes are always severe, but at least the error doesn't go unnoticed. Thanks for the PR!

  4. pekkaklarck commented on Oct 22, 2026

    @pekkaklarck
    Member

    I tested the fix locally and noticed that the error when argument conversion fails doesn't mention the library name. What you get is something like this:

    [ ERROR ] Error in file '/path/5815.robot' on line 2: ValueError: Argument 'port' got value '80x' that cannot be converted to integer.

    This is different to errors you get when a library is called with wrong number of arguments:

    [ ERROR ] Error in file '/path/5815.robot' on line 2: Library 'Lib5815' expected 1 to 2 arguments, got 0.

    This can be easily fixed by adding a bit context information to the exception reraised in ClassLibrary.from_class and that's what I plan to do.

    It would probably be better to fix this in ArgumentSpec.convert, though. Then we could make sure that this method only raises DataError and changes to ClassLibrary.from_class could be reverted. That would have a problem that then also error messages when converting arguments passes keywords, listeners, etc. would change. More context would probably be good there as well, but such a change would require updating a lot of tests, we needed to check all places that call ArgumentSpec.convert directly and indirectly and such an error message change in a bug fix release could even cause backwards incompatibility issues. I thus believe this is too big change now, but I'll add some comments to the code so that we can take a look at this later.

  5. added a commit that references this issue on Oct 22, 2026
    c913c8d
  6. d-biehl commented on Oct 22, 2026

    @d-biehl
    ContributorAuthor

    Thanks for the follow-up! The same kind of crash still happens in other places that convert arguments or variables, such as --listener, --prerunmodifier and typed variables, when conversion fails with something else than ValueError. I created #5819 about that. The fix proposed there is in TypeConverter.convert, so it doesn't change any existing ValueError messages, and the TODOs you added stay valid.

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: critical

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions