10000 Report OSErrors in a more human-readable way · Issue #221 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Report OSErrors in a more human-readable way #221

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

< 8000 span title="Status: Closed" data-view-component="true" class="State State--merged d-flex flex-items-center"> Closed
dhalbert opened this issue Aug 31, 2017 · 8 comments
Closed

Report OSErrors in a more human-readable way #221

dhalbert opened this issue Aug 31, 2017 · 8 comments
Milestone

Comments

@dhalbert
Copy link
Collaborator
>>> import os
>>> os.mkdir("foo34")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: 30
>>> os.rename("main.py", "foo.py")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: 30

It would be better to give some indication that the filesystem was read-only instead of a numeric error.

@tannewt
Copy link
Member
tannewt commented Sep 1, 2017

Here is what CPython 3.6 does in the REPL and what we should mimic.

>>> import os
>>> os.mkdir("/Volumes/Untitled/test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 30] Read-only file system: '/Volumes/Untitled/test'

Here are the relevant properties on it:

>>> error.errno
30
>>> error.strerror
'Read-only file system'
>>> error.filename
'/Volumes/Untitled/test'

@dhalbert
Copy link
Collaborator Author
dhalbert commented Sep 1, 2017

Revising title: on atmel-samd, all errors are reported only numerically. On esp8266 and unix, the errno name is given as well. As @tannewt shows above, both could be better.

This has to do with whether MICROPY_PY_UERRNO is enabled or not.

>>> os.listdir("main.py")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: 2

esp8266 and unix ports:

>>> os.listdir("boot.py")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 2] ENOENT

@dhalbert dhalbert changed the title atmel-samd: os file operations that would write give error 30 Report OSErrors in a more human-readable way Sep 1, 2017
@tannewt tannewt added this to the 3.0 milestone Sep 6, 2017
@Sigafoos
Copy link
Sigafoos commented Sep 12, 2017

This may be a separate issue, but OSError doesn't seem to have some of the attributes the CPython docs says it does:

This exception is derived from EnvironmentError. It is raised when a function returns a system-related error (not for illegal argument types or other incidental errors). The errno attribute is a numeric error code from errno, and the strerror attribute is the corresponding string, as would be printed by the C function perror(). See the module errno, which contains names for the error codes defined by the underlying operating system.

For exceptions that involve a file system path (such as chdir() or unlink()), the exception instance will contain a third attribute, filename, which is the file name passed to the function.

>>> try:
...     fp = open("/x", "a")
... except OSError as e:
...     v = e
...
>>> v.args[0]
30
>>> v.errno
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'OSError' object has no attribute 'errno'
>>> v.strerror
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'OSError' object has no attribute 'strerror'

@process1183
Copy link

This is something I would like to work on.

@godlygeek
Copy link

I'm going to take a swing at this one.

@godlygeek
Copy link

#837 mostly fixes this, though I still want to take a look and see if we can improve the situation for Gemma's and other boards with little flash...

@rhooper
Copy link
rhooper commented May 15, 2018

There will now a bit more flash available on gemma_m0 and trinket_m0 once my PR is merged, if that'll help?

@tannewt
Copy link
Member
tannewt commented May 17, 2018

Fixed by #837. Thanks @godlygeek and @rhooper for making space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
0