cy99 / shedskin

Automatically exported from code.google.com/p/shedskin
0 stars 0 forks source link

OSError and IOError exceptions should be 2-tuples #113

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. shedskin ioerrortest.py

What is the expected output? What do you see instead?

$ shedskin ioerrortest.py
*** SHED SKIN Python-to-C++ Compiler 0.6 ***
Copyright 2005-2010 Mark Dufour; License GNU GPL version 3 (See LICENSE)

[iterative type analysis..]
********************************100%
[generating c++ code..]
*WARNING* ioerrortest.py: class 'IOError' has no method '__getitem__'
*WARNING* ioerrortest.py:14: variable 'status' has no type
*WARNING* ioerrortest.py:15: variable 'status' has no type
*WARNING* ioerrortest.py:18: variable 'status' has no type

This program run on CPython produces:

$ python ioerrortest.py
Try block
IOError(2, 'No such file or directory')
Error status: 2
No such file.

What version of the product are you using? On what operating system?

Shed Skin 0.6 on Cygwin on Windows 7

Please provide any additional information below.

Shed Skin has the exceptions OSError and IOError typed as strings.  But they're 
normally 2-tuples, of (errno, msg).  Many programs look at "errno" after an I/O 
or OS error, to decide on recovery actions.

The compile errors come from trying to subscript an IOError object.

IOError and OSerror objects, at least, need to accept 2-tuples.
Some way has to be provided for programs to access the error code.
Unfortunately, since the tuple is not homogeneous, that won't work
in general.  I've attached a possible approach to a workaround, but it's ugly. 
I don't like it either.  Any better ideas?

Original issue reported on code.google.com by na...@animats.com on 10 Nov 2010 at 7:57

Attachments:

GoogleCodeExporter commented 8 years ago
thanks! sorry I haven't fixed any of your issues yet, I'm sure I will get to 
this this weekend. I spent yesterday testing a new example (a 1,000+ sloccount 
ray tracer), and it took a bit longer than I expected.. it works nicely now 
though.but back to this issue :) 

I guess we could support only element 0, but please note that you can get the 
error number and message also via 'e.errno' and 'e.strerror'.. since it's so 
easy to work around this, there is a relatively clear error message, and using 
indexing is rather ugly anyway, I don't think we really want to support 
indexing here. 

I added the following to the test set, because errno and strerror apparently 
also don't work yet as expected:

    try :
        print("Try block")
        fd = open("nosuchfile") # open will fail
        print("File opened")
    except IOError as e:
        print e, repr(e)
        print e.errno, e.strerror

Original comment by mark.duf...@gmail.com on 11 Nov 2010 at 3:44

GoogleCodeExporter commented 8 years ago
That should work, once implemented.  Using fields of error types makes more 
sense than subscripting them, and CPython already supports that.  

Original comment by na...@animats.com on 11 Nov 2010 at 6:04

GoogleCodeExporter commented 8 years ago
done! there's some ugly duplication between OSError and IOError now, so I added 
that to the easy task page. thanks!

Original comment by mark.duf...@gmail.com on 13 Nov 2010 at 12:20