Skip to content

Commit cccce96

Browse files
sdcard.py: improve error handling
1 parent 129775f commit cccce96

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

internal_filesystem/lib/mpos/sdcard.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ def _try_mount(self, mount_point):
2121
print(f"SD card mounted successfully at {mount_point}")
2222
return True
2323
except OSError as e:
24-
if e.errno == errno.EPERM: # EPERM is 1, meaning already mounted
24+
errno = -1
25+
try:
26+
errno = e.errno
27+
except NameError as we:
28+
print("Got this weird (sporadic) \"NameError: name 'errno' isn't defined\" again when parsing OSError: {we}")
29+
print(f"Original exception: {e}")
30+
print(dir(e))
31+
if errno == errno.EPERM: # EPERM is 1, meaning already mounted
2532
print(f"Got mount error {e} which means already mounted.")
2633
return True
2734
else:
@@ -132,7 +139,7 @@ def get():
132139
"""Get the global SD card manager instance."""
133140
if _manager is None:
134141
print("ERROR: SDCardManager not initialized")
135-
print(" - Call init(spi_bus, cs_pin) first in boot.py or main.py")
142+
print(" - Call init(spi_bus, cs_pin) first in lib/mpos/board/*.py")
136143
return _manager
137144

138145
def mount(mount_point):

0 commit comments

Comments
 (0)