Skip to content

Error NoPermissions:Formatting on the unsaved file #16244

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

Closed
Honghe opened this issue May 14, 2021 · 9 comments
Closed

Error NoPermissions:Formatting on the unsaved file #16244

Honghe opened this issue May 14, 2021 · 9 comments
Assignees
Labels
area-editor-* User-facing catch-all bug Issue identified by VS Code Team member as probable bug

Comments

@Honghe
Copy link

Honghe commented May 14, 2021

Issue Type: Bug

Python extension output:

Error 2021-05-14 17:06:55: Failed to create a temporary file [NoPermissions (FileSystemError): Unable to write file '/Untitled-1.13264068d108c6901b3592ea654fcd57.tmp' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/Untitled-1.13264068d108c6901b3592ea654fcd57.tmp')
	at _handleError (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:87:156478)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (internal/process/task_queues.js:93:5)
	at async y.writeText (/home/jack/.vscode/extensions/ms-python.python-2021.5.829140558/out/client/extension.js:9:344845)
	at async Object.t.getTempFileWithDocumentContents (/home/jack/.vscode/extensions/ms-python.python-2021.5.829140558/out/client/extension.js:9:360722)
	at async l.provideDocumentFormattingEdits (/home/jack/.vscode/extensions/ms-python.python-2021.5.829140558/out/client/extension.js:9:373955)] {
  code: 'NoPermissions'
}

Extension version: 2021.5.840043038
VS Code version: Code 1.56.1 (e713fe9b05fc24facbec8f34fb1017133858842b, 2021-05-06T10:08:16.954Z)
OS version: Linux x64 5.4.0-42-generic
OS: Ubuntu 20.04.2

System Info
Item Value
CPUs Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
rasterization: disabled_software
skia_renderer: enabled_on
video_decode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 2, 1, 1
Memory (System) 15.55GB (0.30GB free)
Process Argv --no-sandbox --unity-launch --crash-reporter-id d1342c61-ab2f-444c-8817-05c0593ae50f
Screen Reader no
VM 67%
DESKTOP_SESSION ubuntu
XDG_CURRENT_DESKTOP Unity
XDG_SESSION_DESKTOP ubuntu
XDG_SESSION_TYPE x11
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
pythonvspyt602:30300191
vspor879:30202332
vspor708:30202333
vspor363:30204092
pythonvspyt639:30300192
pythontb:30283811
pythonvspyt551:30291414
vspre833:30267464
pythonptprofiler:30281270
vshan820:30294714
vscorecescf:30290706
pythondataviewer:30285071
vscus158:30286553
vscgsv2:30301612
bridgeflightcf:30299255
vscod805:30301674

@github-actions github-actions bot added the triage-needed Needs assignment to the proper sub-team label May 14, 2021
@karthiknadig
Copy link
Member

@Honghe Can you check if you have TMP, TEMP, TMPDIR either of them set to a directory where you have write permissions? If you are using formatter like black we currently have to use a temp file to format it.

@Honghe
Copy link
Author

Honghe commented May 15, 2021

@karrtikr The default formatting provide is autopep8. and it still doesn't work even I start code via:

mkdir $HOME/tmp
TMP=$HOME/tmp code .

@karthiknadig
Copy link
Member

@Honghe This is what I have for tmp folder:
image

I also recommend trying to set all three variants of the temp env variable. Also, see if you can use mktemp from the VS Code terminal to create a temp file.

@Honghe
Copy link
Author

Honghe commented May 18, 2021

@karthiknadig

TMP=$HOME/tmp TEMP=$TMP TMPDIR=$TMP code .

Test command in the VS Code terminal:

~/vscodeprojects
$ echo $TMP
/home/jack/tmp

~/vscodeprojects
$ echo $TMPDIR
/home/jack/tmp

~/vscodeprojects
$ echo $TEMP  
/home/jack/tmp

~/vscodeprojects
$ mktemp
/home/jack/tmp/tmp.S4hiJyuTDa

But the formatting error still occurs:

Error 2021-05-18 16:36:46: Failed to create a temporary file [NoPermissions (FileSystemError): Unable to write file '/Untitled-1.13264068d108c6901b3592ea654fcd57.tmp' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/Untitled-1.13264068d108c6901b3592ea654fcd57.tmp')
	at _handleError (/usr/share/code/resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:87:156478)
	at processTicksAndRejections (internal/process/task_queues.js:93:5)
	at async y.writeText (/home/jack/.vscode/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:9:344845)
	at async Object.t.getTempFileWithDocumentContents (/home/jack/.vscode/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:9:360722)
	at async l.provideDocumentFormattingEdits (/home/jack/.vscode/extensions/ms-python.python-2021.5.842923320/out/client/extension.js:9:373955)] {
  code: 'NoPermissions'
}

@karthiknadig karthiknadig self-assigned this May 18, 2021
@karthiknadig karthiknadig added area-editor-* User-facing catch-all triage bug Issue identified by VS Code Team member as probable bug and removed triage-needed Needs assignment to the proper sub-team labels May 18, 2021
@karthiknadig
Copy link
Member

@Honghe This is very strange. You get the NoPermissions because it is trying to create a temp file in the root directory. The reason that happens is the os-tmpdir library is not able to find the temp directory. Not really sure why this is the case, because providing TMP, TMPDIR or TEMP should work. This might be a good question for StackOverflow.

@craigds
Copy link

craigds commented Jul 5, 2021

I've been getting this same error for a few days now (python ext is v2021.7.992362372-dev):

This is in the Log (Extension Host) in my output tab


Error (FileSystemError): Unable to write file '/Untitled-2.387795c86765346eca0c041bac00348b.tmp' (Unknown (FileSystemError): Error: EROFS: read-only file system, open '/Untitled-2.387795c86765346eca0c041bac00348b.tmp')
	at _handleError (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:84:155975)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (internal/process/task_queues.js:93:5)
	at async y.writeText (/Users/cdestigter/.vscode/extensions/ms-python.python-2021.7.992362372-dev/out/client/extension.js:9:344068)
	at async Object.t.getTempFileWithDocumentContents (/Users/cdestigter/.vscode/extensions/ms-python.python-2021.7.992362372-dev/out/client/extension.js:9:359945)
	at async h.provideDocumentFormattingEdits (/Users/cdestigter/.vscode/extensions/ms-python.python-2021.7.992362372-dev/out/client/extension.js:9:373178)

Not sure if related, but the Python log has this stuff in it:

Python interpreter path: /usr/local/bin/python3.8
Python interpreter path: /usr/local/bin/python3.7
Python interpreter path: /usr/local/bin/python3.8
Python interpreter path: /usr/local/bin/python3.7
Python interpreter path: /usr/local/bin/python3.8
Python interpreter path: /usr/local/bin/python3.7

Every time I switch context to a python file, one more of each interpreter shows up in the log. Weird huh? My interpreter in the User settings is set to /usr/local/bin/python3.7 so I'm not clear on where the 3.8 is coming from.

With either of those interpreters, I can run import tempfile ; print(tempfile.gettempdir()) and I get the expected result: /var/folders/4b/xwkgxs8x5y55f33bqm_8mjdc0000gn/T (which is the value of the TMPDIR env var)

This doesn't happen if I downgrade to 2021.6.0 (but vscode immediately nags me to reload to re-upgrade again - why is it forcing upgrades to a dev version?)

@RedHeadphone
Copy link

RedHeadphone commented Nov 15, 2021

I am getting same error(my OS is windows)
image

I have set TMP, TEMP, TMPDIR path to a different folder still it saves temp file at path / while formatting python code without saving

@RedHeadphone
Copy link

@karthiknadig

@karthiknadig
Copy link
Member

This happens if the VS Code instance for some reason does not pick up TMP, TEMP changes. Unfortunately, the temp file creation is handled by an external library. A generic solution to this is to not create the temp file in the first place. We have plans to implement this via Language Server Protocol. This will allow us to solve formatting problem for python files and notebook scenarios.

So closing this in favor of #17918

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-editor-* User-facing catch-all bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

4 participants