IndexError masks failures from JavaScript extension keywords with *args

Aperta Adatta ai principianti
#5,306 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
testing

Direzione di ricerca

Inizia da _get_selector_value_from_keyword_call() in Browser/browser.py e segui come associa i valori passati alla firma della keyword. Riproduci il problema con l’estensione JavaScript e il test Robot forniti. Il lavoro è terminato quando l’errore segnala l’errore originale boom: ["a","b"] invece di sollevare IndexError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
662
Fork
149
Merge medio
6h 13m
PR unite (30g)
121

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MarketSquare/robotframework-browser

Tutte le issue di MarketSquare/robotframework-browser

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.