summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-02-04 13:32:39 -0500
committerDan Halbert <halbert@halwitz.org>2020-02-04 13:32:39 -0500
commit57b566e73614c74a9fc74cd2d2007d91cdb507db (patch)
tree46f302c21c5e243cb17997559b93bd6665289573
parenta4ebd2f7c112dc5d185d198e28e00edabd395a84 (diff)
Include filename for 'No such file/directory', etc.
-rw-r--r--extmod/vfs_fat_file.c2
-rw-r--r--py/runtime.c9
-rw-r--r--py/runtime.h1
3 files changed, 11 insertions, 1 deletions
diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c
index 3ea9cee52..dc0a893a5 100644
--- a/extmod/vfs_fat_file.c
+++ b/extmod/vfs_fat_file.c
@@ -199,7 +199,7 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
FRESULT res = f_open(&vfs->fatfs, &o->fp, fname, mode);
if (res != FR_OK) {
m_del_obj(pyb_file_obj_t, o);
- mp_raise_OSError(fresult_to_errno_table[res]);
+ mp_raise_OSError_errno_str(fresult_to_errno_table[res], fname);
}
// If we're reading, turn on fast seek.
if (mode == FA_READ) {
diff --git a/py/runtime.c b/py/runtime.c
index 48416bab2..cb174837c 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -29,10 +29,12 @@
#include <string.h>
#include <assert.h>
+
#include "extmod/vfs.h"
#include "py/parsenum.h"
#include "py/compile.h"
+#include "py/mperrno.h"
#include "py/objstr.h"
#include "py/objtuple.h"
#include "py/objtype.h"
@@ -1576,6 +1578,13 @@ NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg) {
mp_raise_msg(&mp_type_OSError, msg);
}
+NORETURN void mp_raise_OSError_errno_str(int errno_, const char *str) {
+ char decompressed[50];
+ const char *errno_str = mp_common_errno_to_str(MP_OBJ_NEW_SMALL_INT(errno_),
+ decompressed, sizeof(decompressed));
+ mp_raise_OSError_msg_varg(translate("[Errno %d] %s: %s"), errno_, errno_str, str);
+}
+
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...) {
va_list argptr;
va_start(argptr,fmt);
diff --git a/py/runtime.h b/py/runtime.h
index 4121352df..319de5bb9 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -161,6 +161,7 @@ NORETURN void mp_raise_RuntimeError(const compressed_string_t *msg);
NORETURN void mp_raise_ImportError(const compressed_string_t *msg);
NORETURN void mp_raise_IndexError(const compressed_string_t *msg);
NORETURN void mp_raise_OSError(int errno_);
+NORETURN void mp_raise_OSError_errno_str(int errno_, const char *str);
NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg);
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...);
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);