Skip to content

Commit 422396c

Browse files
committed
extmod/modbtree: Handle default value and error check.
1 parent a1eab98 commit 422396c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

extmod/modbtree.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,13 @@ STATIC mp_obj_t btree_get(size_t n_args, const mp_obj_t *args) {
9292
key.data = (void*)mp_obj_str_get_data(args[1], &key.size);
9393
int res = __bt_get(self->db, &key, &val, 0);
9494
if (res == RET_SPECIAL) {
95-
return mp_const_none;
95+
if (n_args > 2) {
96+
return args[2];
97+
} else {
98+
return mp_const_none;
99+
}
96100
}
101+
CHECK_ERROR(res);
97102
return mp_obj_new_bytes(val.data, val.size);
98103
}
99104
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(btree_get_obj, 2, 3, btree_get);

0 commit comments

Comments
 (0)