Skip to content

Support warnings, not only errors, in parsing model #5210

Description

@pekkaklarck

The parsing model supports setting errors for individual tokens, but there are two problems with the current approach:

  1. Errors (typically syntax errors) aren't separated from warnings (typically deprecations). This caused a problem when deprecating singular section headers (Loudly deprecate singular section headers #4432) and the code reporting the warning as part of execution needed to know what errors can occur in different contexts to handle the problem. With the planned deprecation of the pipe-separated format (Deprecate pipe-separated format #5203) this is likely even a bigger problem, because there's no single context where pipes can be used.
  2. It isn't easy to recognize if the same error/warning occurs multiple times in same file. This requires comparing messages, but because they typically contain some variables parts, they cannot be compared directly. Searching for a certain sub-string is also problematic, because error messages can change.

My proposal for solving both of the above problems is adding new errno attribute to to the Token objects with the following semantics:

  1. errno is an integer representing an error code.
  2. Each error and warning has a different code.
  3. Codes have constant names like ERR_SINGULAR_HEADER_DEPRECATED stored as attributes of the Token class.
  4. Errors and warnings have different ranges so that it is easy to separate them. We could, for example, use negative values with warnings and positive with errors. Zero would mean no error/warning.

Activity

  1. added this to the v7.2 milestone on Sep 17, 2024
  2. mikeleppane commented on Oct 1, 2024

    @mikeleppane

    Hey! If it is okay, I would be interested in looking at this.

  3. mikeleppane commented on Oct 1, 2024

    @mikeleppane

    After looking into this, I wanted to know if it makes sense to introduce a data model for errors/warnings.

    @dataclass(frozen=True)
    class InvalidTokenError:
        level: ErrorKind
        code: ErrorCode
        message: str | None = None
        is_fatal: bool = False   # I added this to control when the robot should throw a hard error. I'm not fully aware of all the use cases, but it seems that in some cases, `DataError` is thrown immediately. 

    This way, we don't need specific ranges for errors/warnings.

  4. mikeleppane commented on Oct 2, 2024

    @mikeleppane

    This is just playing around with the code. Trying to find the best solution. Here's a one proposal:

    visit_SectionHeader(self, node):
            token: 'Token|None' = node.get_token(*Token.HEADER_TOKENS)
            if token is None or token.error is None:
                return
            token.dump_error_or_raise(source=self.source)    # option 1
            self.report_invalid_token_or_raise()  # option 2

    It allows the Token type to handle its reporting. I think this raise_on_invalid_header does not belong to the ErrorReporter type.

  5. mikeleppane commented on Oct 16, 2024

    @mikeleppane

    I've had a working implementation ready locally for some time now. Should I create a pull request, or should we discuss the implementation approach?

  6. pekkaklarck commented on Oct 16, 2024

    @pekkaklarck
    MemberAuthor

    It's probably easiest if you create a PR, you can make it draft, so that it's easier to see the code.

  7. mikeleppane commented on Oct 19, 2024

    @mikeleppane

    I came across this issue related to the exit-on-error thingy (see, issue).
    I'm unsure if it's applicable, but I thought we could leverage this new functionality to tackle at least some part of the exit-on-error problem space (meaning parsing). If a user sets the exit-on-error option, could we pass the info to the parser and raise a hard error in case a parsing error occurs? I understand there are subtleties when it comes to exit-on-error, and how to tackle that in different scenarios might not be trivial.

    I could investigate this if that's okay.

  8. pekkaklarck commented on Dec 30, 2024

    @pekkaklarck
    MemberAuthor

    The deprecation of the pipe-separated format (#5203) that would need this enhancement has been moved to RF 7.3. Because this enhancement doesn't have any other usages right now, it's best to move this as well.

  9. modified the milestones: v7.2, v7.3 on Dec 30, 2024
  10. removed this from the v7.3 milestone on Apr 4, 2025
  11. 2 remaining items

  12. added this to the v7.5 milestone on Jun 24, 2025
  13. added a commit that references this issue on May 7, 2026
  14. pekkaklarck commented on May 7, 2026

    @pekkaklarck
    MemberAuthor

    There's a new usage for reporting parsing time warnings: reporting deprecated translations (#5668). We could handle deprecated section headers using same kludge we used when deprecating singular section headers (#4432), but handling deprecated settings would require much more kludges. This issue was originally created because deprecating singular headers turned out to be somewhat complicated, and I believe it's now best to implement this.

    Although this issue is totally valid, I think the design I proposed in the description is overly complicated. There could be some benefits with adding errno that identifies errors and warnings, but maintaining and documenting these error codes would add extra work. At least with the current use case just separating warnings and errors is enough, and I believe that covers also future usages. If we in the future need something more complicated, we can enhance error/warning reporting further when we know what we actually need. Designing and implementing something complicated now is most likely YAGNI. In the worst the complicated design wouldn't anyway solve the future needs and we needed anyway make changes.

    What I wrote above about the design I proposed matches equally well to the draft PR #5241. It has even more complicated design where error messages are turned into objects that have the error code, error kind (i.e. severity) and the actual error message as attributes. I don't see concrete needs for such functionality, and that change would also break IDE plugins, linters, formatters and other tools that use the parsing API.

  15. pekkaklarck commented on May 7, 2026

    @pekkaklarck
    MemberAuthor

    After thinking this a bit more and looking at the related code, I believe the best way to implement this is adding new Token.warning and Statement.warnings attributes that work exactly the same way as the current Token.error and Statement.errors. When transforming the parsing model to an executable model, we could then report warnings and errors separately. External tools working with the model could do the same, and older external tools that don't know about these new attributes would just ignore them.

    My next steps related to this are:

    • Start a discussion about this on the #devel channel on our Slack. I want to get opinions from others, especially from those developing tools that work with the parsing model. Comments are obviously appreciated here as well.
    • Create a prototype implementation.
  16. changed the title [-]Enhance reporting errors and warnings in parsing model tokens[/-] [+]Support warnings, not only errors, in parsing model[/+] on May 7, 2026
  17. self-assigned this
    on May 7, 2026
  18. pekkaklarck commented on Jul 16, 2026

    @pekkaklarck
    MemberAuthor

    I created a prototype earlier, but it didn't work as well as I hoped. We now want to get RF 7.5 out and I decided to move this issue to RF 7.6 instead of trying to implement it. This means that we can add translation deprecation system (#5668) so that old and new terms work, but there will never be actual deprecation warnings. That doesn't matter in practice, because the plan was to start emitting deprecation warnings earliest in RF 7.6. To make that happen, we then really need to get this issue done. I raised the priority and effort estimation accordingly.

  19. modified the milestones: v7.5, v7.6 on Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions