vscode-cmake-tools: Parsing of cmake-kits.json fails regularly

Brief Issue Summary

Quite often I get the error message [kit] Failed to parse cmake-kits.json: {1} when changing the cmake-kits.json file. After saving the file a few times (without modifications) parsing will succeed. Sometimes this also seems to happen on start of VSCode.

Expected:

Consistent behavior if cmake-kits.json does not change. In the example below I’d expect the parsing of the file to succeed all the time.

CMake Tools Log

Log from saving a few times, cmake.loggingLevel is at trace.

[kit] Reading kits file c:\work\git\poquid\.vscode\cmake-kits.json
[kit] Failed to parse cmake-kits.json: {1}
[kit] Reading kits file c:\work\git\poquid\.vscode\cmake-kits.json
[kit] Failed to parse cmake-kits.json: {1}
[kit] Reading kits file c:\work\git\poquid\.vscode\cmake-kits.json
[kit] Successfully loaded 2 kits from c:\work\git\poquid\.vscode\cmake-kits.json
[kit] Reading kits file c:\work\git\poquid\.vscode\cmake-kits.json
[kit] Successfully loaded 2 kits from c:\work\git\poquid\.vscode\cmake-kits.json

Platform and Versions

  • Operating System: Windows 10
  • CMake Version: 3.15.1
  • VSCode Version: 1.45.0-insider
  • CMake Tools Extension Version: 1.3.1
  • Compiler/Toolchain: Keil ARMClang & Keil ARMCC with custom toolchain file

Other Notes/Information

cmake-kits.json being used (with minor modifications to my productive one, but the same issue can be observed here):

[
  {
    "name": "Keil armclang Chip1",
    "toolchainFile": "C:/work/git/cmake-keil/toolchain-keil-armclang.cmake",
    "cmakeSettings": {
      "TOOLCHAIN_PATH": "C:/ToolsRep",
      "DERIVATIVE": "Chip1",
      "LIB_PATH": "../lib"
    }
  },
  {
    "name": "Keil armcc Chip1",
    "toolchainFile": "C:/work/git/cmake-keil/toolchain-keil-armcc.cmake",
    "cmakeSettings": {
      "TOOLCHAIN_PATH": "C:/ToolsRep",
      "DERIVATIVE": "Chip1",
      "LIB_PATH": "../lib"
    }
  }
]

I know that the provided log is most likely quite insufficient to debug the issue. If there is any way I can provide additional information I’d be happy to do so.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 16 (6 by maintainers)

Most upvoted comments

I did some additional checking, and as could be guesses from the exception it seems that the issue occurs during reading of the file, not the parsing. I added an additional output in the error case to dump the read file content:

...
} catch (e) {
  log.error(localize('failed.to.parse', 'Failed to parse {0}: {1} : {2}', "cmake-kits.json", e.message, e.stack));
  log.error(content_str)
  return [];
}
...

Testing with a cmake-kits.json just containing [] I can see that the content_str is empty.

[kit] Failed to parse cmake-kits.json: Unexpected EOF at line 1 column 2 of the JSON5 data. Still to read: "" : SyntaxError: Unexpected EOF at line 1 column 2 of the JSON5 data. Still to read: ""
  at error (c:\work\git\vscode-cmake-tools\dist\main.js:38451:25)
  at word (c:\work\git\vscode-cmake-tools\dist\main.js:38788:13)
  at value (c:\work\git\vscode-cmake-tools\dist\main.js:38888:56)
  at Object.parse (c:\work\git\vscode-cmake-tools\dist\main.js:38903:18)
  at Object.readKitsFile (c:\work\git\vscode-cmake-tools\dist\main.js:61774:26)
  at async KitsController.readKits (c:\work\git\vscode-cmake-tools\dist\main.js:61948:31)
[kit] 

I’ve not seen a case where only part of the file was read, always either all or nothing (also with bigger files). Just a wild guess: could it be that it’s reading the file in a state where the new content was not yet written? (assuming the write is not atomic)

cmake-kits.json vs user level cmake-tools-kits.json: The issue occurs for the user-level file as well, it seems to be more infrequent though.

Repro I’d be happy to provide a repository, but after the check of the user-level file I’m not sure that would help… I can reproduce the issue by opening a new workspace and placing a .vscode/cmake-kits.json file containing [] into it. Then I just repeatedly save the file. If you think it help I’d not have a problem generating that. Or just save the user-level kits file repeatedly.