cheshirekow / cmake_format

Source code formatter for cmake listfiles.
GNU General Public License v3.0
941 stars 103 forks source link

When `.cmake-format` file does not include the `.yaml` extension errors are not reported correctly #299

Open CraigHutchinson opened 1 year ago

CraigHutchinson commented 1 year ago

Situation

When using the .cmake-format without an extension the script doesn't know which parser to utilise so tries each in-turn. However in doing so ALL exceptions are passed and you get a very unhelpful error: "RuntimeError: Failed to parse C:\development\CPM.cmake\.cmake-format as any of yaml, json, or python"

Investigation

Adding the .yaml extension I determined the source of my issue is: ModuleNotFoundError: No module named 'yaml'

Solutions

  1. The cmake-format package should explicitly depend on Yaml to circumvent this current issue.
  2. Where all three parsers fail a 'best guess' could be made based on some simple Regex i.e. contains "format:\n" at start of file as to display the exception e.g. Failed to parse C:\development\CPM.cmake\.cmake-format, best-guess is 'yaml' format. Parser returned: "ModuleNotFoundError: No module named 'yaml'"
  3. Just display the error output from all 3 parsers, a bit verbose but would solve all cases!