Issue2653

classification
Title: Wrong error message when opening a busy file
Type: behaviour Severity: minor
Components: Core Versions: Jython 2.7
Milestone:
process
Status: open Resolution: remind
Dependencies: Superseder:
Assigned To: Nosy List: daniele.trimarchi@coventor.com, stefan.richthofer
Priority: low Keywords:

Created on 2018-01-24.10:44:23 by daniele.trimarchi@coventor.com, last changed 2018-01-28.21:43:26 by stefan.richthofer.

Messages
msg11699 (view) Author: DanieleTrimarchi (daniele.trimarchi@coventor.com) Date: 2018-01-24.10:44:22
This is a minor issue, but somehow annoying. 

Say there is a file that is busy because it is already opened in another application (for example: open a .csv file excel). 
When attempting to open this busy file in CPython2.7, we get a very specific error message: 

>python test.py
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    f = open('testIO.csv','w')
IOError: [Errno 13] Permission denied: 'testIO.csv'
>>>

Now attempt the same in Jython 2.7.0 and will get a misleading error: 
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_131
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('testFile.csv','w')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 2] No such file or directory: 'testFile.csv'
>>>

Is there a chance to fix this behaviour and correcly report to the user what is going on?

Thanks, 
Daniele
msg11700 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2018-01-28.21:43:24
Hello Daniele,
I can currently not allocate time to work on Jython issues and this error message issue is honestly fairly low priority compared to what else is on the tracker. That said, if it is important for you to get it fixed I would guide you through the process of fixing and creating a PR. If that turns out well I'd be happy to accept it.

To get you started, I think the error is probably generated here:
https://github.com/jythontools/jython/blob/master/src/org/python/core/io/FileIO.java#L96
You would have to assert that, e.g. by temporarily emitting a debug output from that code. Then I suppose, the FileNotFoundException fnfe need a finer analysis to capture the error case you observe. Finally you'd have to create a new if-branch there that calls Py.IOError with the appropriate errno code (Errno.EACCES I suppose).
History
Date User Action Args
2018-01-28 21:43:26stefan.richthofersetseverity: normal -> minor
nosy: + stefan.richthofer
messages: + msg11700
priority: low
type: behaviour
resolution: remind
2018-01-24 10:44:23daniele.trimarchi@coventor.comcreate