This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.symlink can return wrong FileExistsError/WindowsError information
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.3
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Bad error message in os.rename, os.link, and os.symlink
View: 16074
Assigned To: Nosy List: a_b, serhiy.storchaka, sijinjoseph
Priority: normal Keywords:

Created on 2012-12-29 13:43 by a_b, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg178493 - (view) Author: Andrew Berg (a_b) Date: 2012-12-29 13:43
When attempting to make a symlink using a name that already exists, a FileExistsError is raised (and rightfully so), but it lists the source name rather than the destination name. However, the existing destination name is what causes the exception to be raised, not the existing source. Since the FileExistsError is WinError 183 and I haven't attempted this on another OS, I'm marking this as Windows-specific. Issue 13775 seems to be related.
msg178511 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-29 16:46
See also issue16074.
msg178543 - (view) Author: Andrew Berg (a_b) Date: 2012-12-29 22:46
I tested this on FreeBSD 9.1, and the error message is correct there.
msg186737 - (view) Author: Sijin Joseph (sijinjoseph) Date: 2013-04-13 16:00
This looks to work correctly in default branch,

>>> os.link('non-existent-name', 'new-name')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'non-existent-name'
msg186742 - (view) Author: Sijin Joseph (sijinjoseph) Date: 2013-04-13 16:10
Behavior for symlink is as follows

>>> os.symlink('non-existent-name', 'existing-name')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
PermissionError: [WinError 5] Access is denied: 'non-existent-name'

The error message is misleading, but can be fixed using the patch attached to issue13775

>>> os.symlink('non-existent-name1', 'non-existent-name2')
No error. This behavior is same on Windows and Linux. Seems odd, but can be justified as ok behavior.
msg186749 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-04-13 16:29
issue13775, issue16074, and issue16812 all are virtually about the same bug. There is no working patch in any issue, but the discussion in issue16074 is longer.
History
Date User Action Args
2022-04-11 14:57:39adminsetgithub: 61016
2013-04-13 16:29:32serhiy.storchakasetstatus: open -> closed
superseder: Bad error message in os.rename, os.link, and os.symlink
messages: + msg186749

resolution: duplicate
stage: resolved
2013-04-13 16:10:07sijinjosephsetmessages: + msg186742
2013-04-13 16:00:29sijinjosephsetnosy: + sijinjoseph
messages: + msg186737
2012-12-29 22:46:45a_bsetmessages: + msg178543
2012-12-29 16:46:42serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg178511
2012-12-29 13:43:54a_bcreate