Skip to content

SmartSortKeywords failed because of Comments missing a body attribute #1718

@MobyNL

Description

@MobyNL

Hey, i currently have robocop v 8.2.4 installed. I noticed this error using the SmartSortKeywords rule.
I am not directly able to replicate it. After removing the rule, and putting it back I no longer have the issue. Maybe the error message gives you an idea on where to quickly locate it.

╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ /path-to-project-XGn5vme4-py3.12/lib/python3.12/site-packages/robocop/run.py:746 in format_files                                                                                                                              │
│                                                                                                                                                                                                                                                                              │
│   743 │   if clear_cache:                                                                                                                                                                                                                                                    │
│   744 │   │   config_manager.cache.invalidate_all()                                                                                                                                                                                                                          │
│   745 │   runner = RobocopFormatter(config_manager)                                                                                                                                                                                                                          │
│ ❱ 746 │   return runner.run()                                                                                                                                                                                                                                                │
│   747                                                                                                                                                                                                                                                                        │
│   748                                                                                                                                                                                                                                                                        │
│   749 @list_app.command(name="rules")                                                                                                                                                                                                                                        │
│                                                                                                                                                                                                                                                                              │
│ /path-to-project-XGn5vme4-py3.12/lib/python3.12/site-packages/robocop/formatter/runner.py:71 in run                                                                                                                           │
│                                                                                                                                                                                                                                                                              │
│    68 │   │   │   │   │   │   cached_files += 1                                                                                                                                                                                                                              │
│    69 │   │   │   │   │   │   continue                                                                                                                                                                                                                                       │
│    70 │   │   │   │   previous_changed_files = changed_files                                                                                                                                                                                                                 │
│ ❱  71 │   │   │   │   diff, old_model, new_model, model = self.format_until_stable(source_file                                                                                                                                                                               │
│    72 │   │   │   │   # if stdin:                                                                                                                                                                                                                                            │
│    73 │   │   │   │   #     self.print_to_stdout(new_model)                                                                                                                                                                                                                  │
│    74 │   │   │   │   if diff and old_model and new_model:                                                                                                                                                                                                                   │
│                                                                                                                                                                                                                                                                              │
│ /path-to-project-XGn5vme4-py3.12/lib/python3.12/site-packages/robocop/formatter/runner.py:129 in format_until_stable                                                                                                          │
│                                                                                                                                                                                                                                                                              │
│   126 │   │   disabler_finder.visit(model)                                                                                                                                                                                                                                   │
│   127 │   │   if disabler_finder.is_disabled_in_file(disablers.ALL_FORMATTERS):                                                                                                                                                                                              │
│   128 │   │   │   return False, None, None, model                                                                                                                                                                                                                            │
│ ❱ 129 │   │   diff, old_model, new_model = self.format(model, disabler_finder.disablers, resol                                                                                                                                                                               │
│   130 │   │   reruns = self.config.formatter.reruns                                                                                                                                                                                                                          │
│   131 │   │   while diff and reruns:                                                                                                                                                                                                                                         │
│   132 │   │   │   model = get_model(new_model.text)                                                                                                                                                                                                                          │
│                                                                                                                                                                                                                                                                              │
│ /path-to-project-XGn5vme4-py3.12/lib/python3.12/site-packages/robocop/formatter/runner.py:148 in format                                                                                                                       │
│                                                                                                                                                                                                                                                                              │
│   145 │   │   │   formatter.disablers = disablers  # set dynamically to allow using external f                                                                                                                                                                               │
│   146 │   │   │   if disablers.is_disabled_in_file(name):                                                                                                                                                                                                                    │
│   147 │   │   │   │   continue                                                                                                                                                                                                                                               │
│ ❱ 148 │   │   │   formatter.visit(model)                                                                                                                                                                                                                                     │
│   149 │   │   new_model = StatementLinesCollector(model)                                                                                                                                                                                                                     │
│   150 │   │   return new_model != old_model, old_model, new_model                                                                                                                                                                                                            │
│   151                                                                                                                                                                                                                                                                        │
│                                                                                                                                                                                                                                                                              │
│ /path-to-project-XGn5vme4-py3.12/lib/python3.12/site-packages/robot/parsing/model/visitor.py:101 in visit                                                                                                                     │
│                                                                                                                                                                                                                                                                              │
│    98 │                                                                                                                                                                                                                                                                      │
│    99 │   def visit(self, node: Node) -> "None|Node|list[Node]":                                                                                                                                                                                                             │
│   100 │   │   visitor_method = self._find_visitor(type(node))                                                                                                                                                                                                                │
│ ❱ 101 │   │   return visitor_method(self, node)                                                                                                                                                                                                                              │
│   102                                                                                                                                                                                                                                                                        │
│                                                                                                                                                                                                                                                                              │
│ /usr/lib/python3.12/ast.py:483 in generic_visit                                                                                                                                                                                                                              │
│                                                                                                                                                                                                                                                                              │
│    480 │   │   │   │   new_values = []                                                                                                                                                                                                                                       │
│    481 │   │   │   │   for value in old_value:                                                                                                                                                                                                                               │
│    482 │   │   │   │   │   if isinstance(value, AST):                                                                                                                                                                                                                        │
│ ❱  483 │   │   │   │   │   │   value = self.visit(value)                                                                                                                                                                                                                     │
│    484 │   │   │   │   │   │   if value is None:                                                                                                                                                                                                                             │
│    485 │   │   │   │   │   │   │   continue                                                                                                                                                                                                                                  │
│    486 │   │   │   │   │   │   elif not isinstance(value, AST):                                                                                                                                                                                                              │
│                                                                                                                                                                                                                                                                              │
│ /path-to-project-XGn5vme4-py3.12/lib/python3.12/site-packages/robot/parsing/model/visitor.py:101 in visit                                                                                                                     │
│                                                                                                                                                                                                                                                                              │
│    98 │                                                                                                                                                                                                                                                                      │
│    99 │   def visit(self, node: Node) -> "None|Node|list[Node]":                                                                                                                                                                                                             │
│   100 │   │   visitor_method = self._find_visitor(type(node))                                                                                                                                                                                                                │
│ ❱ 101 │   │   return visitor_method(self, node)                                                                                                                                                                                                                              │
│   102                                                                                                                                                                                                                                                                        │
│                                                                                                                                                                                                                                                                              │
│ /path-to-project-XGn5vme4-py3.12/lib/python3.12/site-packages/robocop/formatter/disablers.py:70 in wrapper                                                                                                                    │
│                                                                                                                                                                                                                                                                              │
│    67 │   │   │   section_name = get_section_name_from_header_type(node)                                                                                                                                                                                                     │
│    68 │   │   │   if self.skip.section(section_name):                                                                                                                                                                                                                        │
│    69 │   │   │   │   return node                                                                                                                                                                                                                                            │
│ ❱  70 │   │   result: _SectionT = func(self, node, *args, **kwargs)                                                                                                                                                                                                          │
│    71 │   │   return result                                                                                                                                                                                                                                                  │
│    72 │                                                                                                                                                                                                                                                                      │
│    73 │   return wrapper                                                                                                                                                                                                                                                     │
│                                                                                                                                                                                                                                                                              │
│ /path-to-project-XGn5vme4-py3.12/lib/python3.12/site-packages/robocop/formatter/formatters/SmartSortKeywords.py:75 in visit_KeywordSection                                                                                    │
│                                                                                                                                                                                                                                                                              │
│    72 │   @skip_section_if_disabled                                                                                                                                                                                                                                          │
│    73 │   def visit_KeywordSection(self, node: KeywordSection) -> KeywordSection:  # noqa: N80                                                                                                                                                                               │
│    74 │   │   before, after = self.leave_only_keywords(node)                                                                                                                                                                                                                 │
│ ❱  75 │   │   empty_lines = self.pop_empty_lines(node)                                                                                                                                                                                                                       │
│    76 │   │   node.body.sort(key=self.sort_function)                                                                                                                                                                                                                         │
│    77 │   │   self.append_empty_lines(node, empty_lines)                                                                                                                                                                                                                     │
│    78 │   │   node.body = before + node.body + after                                                                                                                                                                                                                         │
│                                                                                                                                                                                                                                                                              │
│ /path-to-project-XGn5vme4-py3.12/lib/python3.12/site-packages/robocop/formatter/formatters/SmartSortKeywords.py:86 in pop_empty_lines                                                                                         │
│                                                                                                                                                                                                                                                                              │
│    83 │   │   all_empty: list[list[EmptyLine]] = []                                                                                                                                                                                                                          │
│    84 │   │   for kw in node.body:                                                                                                                                                                                                                                           │
│    85 │   │   │   kw_empty: list[EmptyLine] = []                                                                                                                                                                                                                             │
│ ❱  86 │   │   │   while kw.body and isinstance(kw.body[-1], EmptyLine):                                                                                                                                                                                                      │
│    87 │   │   │   │   kw_empty.insert(0, kw.body.pop())                                                                                                                                                                                                                      │
│    88 │   │   │   all_empty.append(kw_empty)                                                                                                                                                                                                                                 │
│    89 │   │   return all_empty                                                                                                                                                                                                                                               │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
AttributeError: 'Comment' object has no attribute 'body'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions