Error in Restricted Mode Workspace "Cannot assign to read only property 'prettierPath'"
Summary
Trying to use the extension in a VSCode workspace in Restricted Mode (i.e. not trusted) to format documents fails. The bottom status bar says:
Extension 'Prettier - Code formatter' cannot format '<file>'
The "Log (Extension host)" output contains:
[2021-09-06 13:14:38.770] [exthost] [error] Activating extension esbenp.prettier-vscode failed due to an error:
[2021-09-06 13:14:38.771] [exthost] [error] TypeError: Cannot assign to read only property 'prettierPath' of object '#<Object>'
at Object.t.getConfig (#REDACTED#\.vscode\extensions\esbenp.prettier-vscode-8.1.0\dist\extension.js:1:21627)
at e.activate (#REDACTED#\.vscode\extensions\esbenp.prettier-vscode-8.1.0\dist\extension.js:1:73344)
at Function._callActivateOptional (#REDACTED#\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:99:14900)
at Function._callActivate (#REDACTED#\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:99:14576)
at #REDACTED#\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:99:12779
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async Promise.all (index 0)
Other log outputs (including Prettier's own output) do not seem to contain anything relevant.
This might relate to or might be the underlying issue of #2047.
Steps To Reproduce:
- In the Windows Explorer create a file
test.jsonwith content:{"a":[{"b":1,"c":true}]} - Open a new VSCode window (where no documents are open initially, so Prettier is not activated yet)
- In VSCode select "Open File..." and choose the file created in step 1
- For the Workspace Trust dialog select "Open in Restricted Mode"
- In the JSON file right click and select "Format Document" :x: The bottom VSCode progress bar shows "Extension 'Prettier - Code formatter' cannot format ..."
Even after trusting the workspace by clicking on "Restricted Mode" in the bottom left corner and then selecting "Trust" Prettier can still not format the document (but there is no new exception in the log output). Only if you chose to trust the workspace initially, or when you opened the enclosing folder in restricted mode, then trusted it and then reopened VS Code, Pretter is able to format the file.
Note: In restricted mode VSCode does not offer me the "Format Document With..." command, not sure if that is relevant or related to this issue. But it might be intended according to https://github.com/microsoft/vscode/issues/112578 if Prettier indeed failed to start. Though it is a little bit weird why VSCode then tries to use Prettier anyways instead of the built-in JSON language support.
Relevant VSCode settings
- Editor: Default Formatter: None
- JSON > Format: Enable ✅
Expected result
Either:
- Prettier should be able to format the file
- OR it should explain why it cannot format the file (telling the user to change settings or trust the workspace)
Actual result
(See "Summary") VSCode says Prettier cannot format the file, and an uncaught exception is logged.
Additional information
VS Code Version: Version: 1.60.0 (user setup) Commit: e7d7e9a9348e6a8cc8c03f877d39cb72e5dfb1ff Date: 2021-09-01T10:41:52.311Z Electron: 13.1.8 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Windows_NT x64 10.0.19043
Prettier Extension Version: v8.1.0
OS and version: Microsoft Windows [Version 10.0.19043.1165]
Prettier Log Output
There is no "Prettier" button (most likely because the extension could not be activated); see also "Summary".
The "Prettier" Output only contains:
["INFO" - 13:14:38] Extension Name: esbenp.prettier-vscode.
["INFO" - 13:14:38] Extension Version: 8.1.0.
Enabling debug logging does not seem to make a difference.