Skip to content

Commit 57b566e

Browse files
committed
Include filename for 'No such file/directory', etc.
1 parent a4ebd2f commit 57b566e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

extmod/vfs_fat_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar
199199
FRESULT res = f_open(&vfs->fatfs, &o->fp, fname, mode);
200200
if (res != FR_OK) {
201201
m_del_obj(pyb_file_obj_t, o);
202-
mp_raise_OSError(fresult_to_errno_table[res]);
202+
mp_raise_OSError_errno_str(fresult_to_errno_table[res], fname);
203203
}
204204
// If we're reading, turn on fast seek.
205205
if (mode == FA_READ) {

py/runtime.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@
2929
#include <string.h>
3030
#include <assert.h>
3131

32+
3233
#include "extmod/vfs.h"
3334

3435
#include "py/parsenum.h"
3536
#include "py/compile.h"
37+
#include "py/mperrno.h"
3638
#include "py/objstr.h"
3739
#include "py/objtuple.h"
3840
#include "py/objtype.h"
@@ -1576,6 +1578,13 @@ NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg) {
15761578
mp_raise_msg(&mp_type_OSError, msg);
15771579
}
15781580

1581+
NORETURN void mp_raise_OSError_errno_str(int errno_, const char *str) {
1582+
char decompressed[50];
1583+
const char *errno_str = mp_common_errno_to_str(MP_OBJ_NEW_SMALL_INT(errno_),
1584+
decompressed, sizeof(decompressed));
1585+
mp_raise_OSError_msg_varg(translate("[Errno %d] %s: %s"), errno_, errno_str, str);
1586+
}
1587+
15791588
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...) {
15801589
va_list argptr;
15811590
va_start(argptr,fmt);

py/runtime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ NORETURN void mp_raise_RuntimeError(const compressed_string_t *msg);
161161
NORETURN void mp_raise_ImportError(const compressed_string_t *msg);
162162
NORETURN void mp_raise_IndexError(const compressed_string_t *msg);
163163
NORETURN void mp_raise_OSError(int errno_);
164+
NORETURN void mp_raise_OSError_errno_str(int errno_, const char *str);
164165
NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg);
165166
NORETURN void mp_raise_OSError_msg_varg(const compressed_string_t *fmt, ...);
166167
NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy