Commit 1ec3f5cf authored by George Wort's avatar George Wort

Add exception checks for file system.

parent 94a20be5
......@@ -137,6 +137,7 @@ static mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args) {
const char *filename = mp_obj_str_get_data(args[0], &name_len);
RETURN_ON_EXCEPTION(MP_OBJ_NULL)
file_descriptor_obj *res = microbit_file_open(filename, name_len, read == 0, text == 0);
RETURN_ON_EXCEPTION(MP_OBJ_NULL)
if (res == NULL) {
return mp_raise_msg_o(&mp_type_OSError, "file not found");
}
......
......@@ -463,6 +463,7 @@ mp_lexer_t *microbit_file_lexer(qstr src_name, file_descriptor_obj *fd) {
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
file_descriptor_obj *fd = microbit_file_open(filename, strlen(filename), false, false);
RETURN_ON_EXCEPTION(NULL)
if (fd == NULL)
return NULL;
qstr string = qstr_from_str(filename);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment