cmake_format icon indicating copy to clipboard operation
cmake_format copied to clipboard

[cmake-lint] crash with empty file

Open WenbinHou opened this issue 3 years ago • 2 comments

Thank you for these great tools! We have encountered a little problem with it, and it's quite easy to reproduce: cmake-lint crashes with empty file (default config)

$ touch empty.cmake
$ cmake-lint empty.cmake 
ERROR An internal error occured. Please consider filing a bug report at github.com/cheshirekow/cmakelang/issues
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/cmakelang/lint/__main__.py", line 185, in main
    return inner_main()
  File "/usr/local/lib/python3.9/site-packages/cmakelang/lint/__main__.py", line 168, in inner_main
    process_file(cfg, local_ctx, intext)
  File "/usr/local/lib/python3.9/site-packages/cmakelang/lint/__main__.py", line 47, in process_file
    checker.check_parse_tree(parse_tree)
  File "/usr/local/lib/python3.9/site-packages/cmakelang/lint/basic_checker.py", line 825, in check_parse_tree
    self.check_tree(node)
  File "/usr/local/lib/python3.9/site-packages/cmakelang/lint/basic_checker.py", line 806, in check_tree
    self.check_body(node)
  File "/usr/local/lib/python3.9/site-packages/cmakelang/lint/basic_checker.py", line 546, in check_body
    lineno = node.get_tokens()[-1].get_location().line
IndexError: list index out of range

cmake-lint version: 0.6.13 (installed from pip)

WenbinHou avatar Apr 26 '22 05:04 WenbinHou

If the file contains a newline (echo >empty.cmake), cmake-lint won't crash.

WenbinHou avatar Apr 26 '22 05:04 WenbinHou

worked for us, thanks @WenbinHou. Adding a more descriptive error message or even tolerating that would be very helpful 💡.

patzm avatar Dec 12 '22 15:12 patzm