Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse CMakePresets.json file generated by VS #2396

Closed
xisui-MSFT opened this issue Feb 22, 2022 · 2 comments · Fixed by #2411
Closed

Unable to parse CMakePresets.json file generated by VS #2396

xisui-MSFT opened this issue Feb 22, 2022 · 2 comments · Fixed by #2411
Assignees
Labels
bug a bug in the product Feature: presets
Milestone

Comments

@xisui-MSFT
Copy link
Collaborator

Brief Issue Summary

I tried to open a CMake project generated by VS (32119.88.main) in VS Code (1.64.2, with CMake Tools 1.9.2 installed), and got the following error:

[presetController] Failed to parse CMakePresets.json:
SyntaxError: Unexpected token  in JSON at position 0
at JSON.parse ()
at PresetsController.parsePresetsFile (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:60445:36)
at PresetsController.resetPresetsFile (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:59782:38)
at PresetsController.reapplyPresets (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:59797:9)
at watchPresetsChange (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:59699:13)
at Function.init (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:59727:9)
at Function.init (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:55479:35)
at CMakeToolsFolderController._addFolder (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:55727:22)
at CMakeToolsFolderController.loadAllCurrent (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:55679:17)
at ExtensionManager._init (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:54050:13)
at Function.create (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:54102:9)
at setup (c:\Users\xisui.vscode\extensions\ms-vscode.cmake-tools-1.9.2\dist\main.js:55194:32)

Repro steps:

  1. In latest VS 2022, create a new CMake project using the template.
    image
  2. Close VS, and open this folder in VS Code. Check

This might be an encoding issue. The file encoding of CMakePresets.json generated by VS is UTF-8 with BOM. Also, saving the file as UTF-8 in VS Code seems to work.

UTF-8 with bom DOES work using CMake (like cmake --preset presetName). So I think it makes sense to fix this issue in CMake tools.

@bobbrow
Copy link
Member

bobbrow commented Feb 24, 2022

Thanks for reporting this. We should be able to use bomstrip in our implementation of readFile as suggested here: https://stackoverflow.com/questions/24356713/node-js-readfile-error-with-utf8-encoded-file-on-windows

@bobbrow bobbrow added this to the On Deck milestone Feb 24, 2022
@bobbrow bobbrow added bug a bug in the product Feature: presets labels Feb 24, 2022
@elahehrashedi elahehrashedi self-assigned this Mar 1, 2022
@bobbrow bobbrow modified the milestones: On Deck, 1.10.0 Mar 9, 2022
@bobbrow
Copy link
Member

bobbrow commented Mar 9, 2022

This should be fixed in 1.10.2 (pre-release).

@github-actions github-actions bot locked and limited conversation to collaborators Apr 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug a bug in the product Feature: presets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants