Include filename for 'No such file/directory', etc.

This commit is contained in:
Dan Halbert 2020-02-04 13:32:39 -05:00
parent a4ebd2f7c1
commit 57b566e736
3 changed files with 11 additions and 1 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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);