Skip to content

Fix crash when library import argument cannot be converted - #5816

Merged
pekkaklarck merged 1 commit into
robotframework:masterfrom
d-biehl:library-import-conversion-error
Oct 22, 2026
Merged

pekkaklarck merged 1 commit into
robotframework:masterfrom
d-biehl:library-import-conversion-error

Conversation

@d-biehl

@d-biehl d-biehl commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #5815.

ClassLibrary.from_class now turns errors from resolving and converting library arguments into a DataError. DataErrors, for example about a wrong number of arguments, are re-raised as they are. The failing import is then reported like other failing library imports, and execution continues:

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

The fix handles Exception, not only ValueError, because built-in converters can raise other exceptions as well. For example, timeout=1e20 with a timedelta argument raises OverflowError, and with a ValueError-only handler that still crashes the execution.

The message keeps the exception name, like conversion errors in keyword calls and in variable file arguments. Because of that, the failure message of the Import Library keyword does not change. Libdoc now prints the message without the Building library '...' failed: prefix. It already does the same with other DataErrors, for example a wrong number of arguments.

Tests:

  • Acceptance test in test_libraries/library_import_failing.robot. Without the fix the run of the test data crashes, so the existing Importing library with same name as Python built-in module test fails as well.
  • Unit test TestLibraryInit.test_argument_conversion. It covers a successful conversion, a ValueError and an OverflowError.

I ran the full unit and acceptance test suites with Python 3.13 on Linux. All 2442 unit tests pass. Of the 7143 acceptance tests, 7134 pass. The 9 failing ones are Screenshot library tests, and they fail the same way on unmodified master, because taking screenshots is not supported in my environment. utest/running/test_testlibrary.py also passes on Python 3.9 through 3.15. The changed files pass ruff, black and isort with the project configuration.


AI/tooling disclosure: This contribution was prepared with assistance from Claude Code. I reviewed the result manually, understand the changes, verified them locally, and confirm that I have the right to submit this contribution under the project license.

Copilot AI balanced review requested due to automatic review settings October 15, 2026 13:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The localized fix preserves existing error handling and includes regression coverage for conversion failures and continued execution.

0 open findings

What changed in this PR

Fixes #5815 by reporting library argument conversion failures as import errors instead of stopping execution.

Changes:

  • Wraps argument-resolution exceptions in DataError, preserving existing DataErrors.
  • Adds unit coverage for successful conversion, ValueError, and OverflowError.
  • Adds acceptance coverage for conversion failure and continued execution.
File Description
utest/​running/​test_testlibrary.py Tests argument conversion and error handling.
src/​robot/​running/​testlibraries.py Converts resolution failures into import errors.
atest/​testresources/​testlibs/​libswithargs.py Adds a typed library fixture.
atest/​testdata/​test_libraries/​library_import_failing.robot Adds an invalid typed import.
atest/​robot/​test_libraries/​library_import_failing.robot Checks the conversion error message.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@pekkaklarck
pekkaklarck merged commit c913c8d into robotframework:master Oct 22, 2026
8 checks passed
@d-biehl
d-biehl deleted the library-import-conversion-error branch October 22, 2026 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Execution crashes if library import argument cannot be converted

3 participants