Skip to content
Snippets Groups Projects
Commit 6d9c1b69 authored by rahix's avatar rahix Committed by rahix
Browse files

uctx: Raise exception for unknown fonts

Don't return None when a font is not found, but instead raise a
ValueError.  This is more pythonic along the lines of

	- Errors should never pass silently.
	- Ask forgiveness, not permission.
parent 8cb88b90
Branches
No related tags found
No related merge requests found
...@@ -430,8 +430,10 @@ static mp_obj_t mp_ctx_get_font_name(mp_obj_t self_in, mp_obj_t no_in) { ...@@ -430,8 +430,10 @@ static mp_obj_t mp_ctx_get_font_name(mp_obj_t self_in, mp_obj_t no_in) {
mp_ctx_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_ctx_obj_t *self = MP_OBJ_TO_PTR(self_in);
int no = mp_obj_get_int(no_in); int no = mp_obj_get_int(no_in);
const char *name = ctx_get_font_name(self->ctx, no); const char *name = ctx_get_font_name(self->ctx, no);
if (name) return mp_obj_new_str(name, strlen(name)); if (name)
return mp_const_none; return mp_obj_new_str(name, strlen(name));
else
mp_raise_ValueError("font with given index does not exist");
} }
MP_DEFINE_CONST_FUN_OBJ_2(mp_ctx_get_font_name_obj, mp_ctx_get_font_name); MP_DEFINE_CONST_FUN_OBJ_2(mp_ctx_get_font_name_obj, mp_ctx_get_font_name);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment