IndexError masks failures from JavaScript extension keywords with *args

未关闭 适合新手
#5,306 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
75/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
testing

调研方向

从 Browser/browser.py 中的 _get_selector_value_from_keyword_call() 开始,追踪它如何将传入的值与 keyword 签名匹配。使用提供的 JavaScript 扩展和 Robot 测试复现该问题。完成标准是失败报告原始错误 boom: ["a","b"],而不是引发 IndexError。

由索引模型根据 Issue 内容生成。

描述

priority: high

Describe the bug
When a JavaScript extension keyword declares a parameter named args and is called with multiple positional arguments, a keyword failure can be replaced by an IndexError during Browser’s failure handling. This hides the original exception and makes the failure difficult to diagnose.

To Reproduce
Steps to reproduce the behavior:
JavaScript extension:

async function boom(args) {
  throw new Error(`boom: ${JSON.stringify(args)}`);
}

exports.Boom = boom;

Robot test:

*** Test Cases ***
Failure Should Preserve Original Error
    Boom    a    b

Expected behavior
The JavaScript keyword receives both values, but the failure handling path raises IndexError: list index out of range while inspecting the keyword arguments, instead of reporting the original boom: ["a","b"] error.

cause
The generated Python signature turns a JavaScript parameter called args into *args. When _get_selector_value_from_keyword_call() tries to match the values passed to the keyword with the keyword signature, it checks the actual values instead of the signature itself. With multiple values, it can end up looking past the end of the signature and throw an IndexError.

suggested fix
Change _get_selector_value_from_keyword_call() method to:

    def _get_selector_value_from_keyword_call(self, name, args, kwargs):
        selector = kwargs.get("selector")
        if not selector and args:
            arguments = self.get_keyword_arguments(name)
            for i, arg in enumerate(args):
                if i >= len(arguments):
                    break
                spec = arguments[i][0] if isinstance(arguments[i], tuple) else arguments[i]
                if spec.startswith("*"):
                    break
                if spec.startswith("selector"):
                    selector = arg
                    break
        return selector

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: chromium
  • Version: 151.0.7922.34
主要语言
Python
星标
662
派生
149
平均合并
6 小时 13 分钟
30 天内合并 PR
121

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

MarketSquare/robotframework-browser 的其他 Issue

查看 MarketSquare/robotframework-browser 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。