Skip to content

Parsing differences in try/except statements with get_model and data_only parameter #4208

Closed

Description

@d-biehl

Hi there,

In the new version 5.0 alpha1 there is a difference in parsing code with robot.api.get_model for try/except statements.

Given this piece of code:

import ast
from robot.api.parsing import get_model


test = r"""
*** Test Cases ***
first
    Log    hi   

    TRY
        Fail    huch
    EXCEPT    huch    AS  ${a}
        Log    except ${a}  
    FINALLY
        Log    finally
    END
"""

for node in ast.walk(get_model(test, data_only=False)):
    if node.errors:
        print(node.errors)

If I set the data_only parameter to False (which is the default value) i will get:

("EXCEPT's AS marker must be second to last.", "EXCEPT's AS variable '\n' is invalid.")

which is not correct, because it is valid code. If I set the data_only parameter to True, then everything is ok.

I think the implementation is wrong in this case:

see here

if as_token is not self.tokens[-2]:

The test for the AS token and the variable should not be done by index, because the tokens differs if we are parsing with data_only= False mode.

Also I think the message EXCEPT's AS marker must be second to last. is not really necessary, it should be enough to say that there is no variable or a wrong variable.

Activity

  1. pekkaklarck commented on Jan 29, 2022

    @pekkaklarck
    Member

    Great catch!

  2. pekkaklarck commented on Jan 30, 2022

    @pekkaklarck
    Member

    I'll assign this issue to RF 5.0 scope as a task with high priority. Being a task means it won't be included in to release notes unnecessarily.

    There's PR #4209 to fix this.

  3. modified the milestone: v5.0 on Jan 30, 2022
  4. pekkaklarck commented on Jan 30, 2022

    @pekkaklarck
    Member

    Instead of assigning this issue to RF 5.0 scope I decided to reopen the original TRY/EXCEPT issue. This one can be closed now.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions