godot-gdscript-toolkit
godot-gdscript-toolkit copied to clipboard
Unhandled exception `TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'` when running `gdformat`
find ./ | grep "\.gd$" | xargs gdformat --line-length 200
on
extends ORMMaterial3D
func _ready() -> void:
pass
match (
cause
Traceback (most recent call last):
File "/home/rafal/.local/lib/python3.9/site-packages/gdtoolkit/formatter/__main__.py", line 184, in _format_code
code_parse_tree = parser.parse(code, gather_metadata=True)
File "/home/rafal/.local/lib/python3.9/site-packages/gdtoolkit/parser/parser.py", line 61, in parse
self._parser_with_metadata.parse(code)
File "/home/rafal/.local/lib/python3.9/site-packages/lark/lark.py", line 293, in parse
return self.parser.parse(text, start=start)
File "/home/rafal/.local/lib/python3.9/site-packages/lark/parser_frontends.py", line 124, in parse
return self._parse(token_stream, start, set_parser_state)
File "/home/rafal/.local/lib/python3.9/site-packages/lark/parser_frontends.py", line 54, in _parse
return self.parser.parse(input, start, *args)
File "/home/rafal/.local/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 35, in parse
return self.parser.parse(*args)
File "/home/rafal/.local/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 85, in parse
action, arg = get_action(token)
File "/home/rafal/.local/lib/python3.9/site-packages/lark/parsers/lalr_parser.py", line 64, in get_action
raise UnexpectedToken(token, expected, state=state)
lark.exceptions.UnexpectedToken: Unexpected token Token(_DEDENT, '') at line None, column None.
Expected one of:
* LBRACE
* LSQB
* LONG_STRING
* HEX
* DOLLAR
* NAME
* DOT
* NUMBER
* AT
* TILDE
* MINUS
* NOT
* LPAR
* BIN
* REGULAR_STRING
* BANG
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/rafal/.local/bin/gdformat", line 8, in <module>
sys.exit(main())
File "/home/rafal/.local/lib/python3.9/site-packages/gdtoolkit/formatter/__main__.py", line 71, in main
_format_files(files, line_length, safety_checks)
File "/home/rafal/.local/lib/python3.9/site-packages/gdtoolkit/formatter/__main__.py", line 146, in _format_files
success, actually_formatted, formatted_code = _format_code(
File "/home/rafal/.local/lib/python3.9/site-packages/gdtoolkit/formatter/__main__.py", line 206, in _format_code
lark_unexpected_token_to_str(e, code),
File "/home/rafal/.local/lib/python3.9/site-packages/gdtoolkit/common/exceptions.py", line 12, in lark_unexpected_token_to_str
return f"{exception.get_context(code)}\n{exception}".strip()
File "/home/rafal/.local/lib/python3.9/site-packages/lark/exceptions.py", line 29, in get_context
start = max(pos - span, 0)
TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'
This is clearly not a problem of gdtoolkit. The GDScript code in the example is missing a closing parenthesis and that is what the exception complains about.
Expected one of:
* LBRACE
That's true, yet the problem is more about handling the exception properly.