fix(ui-ext): log and clear error in ui_comp_event (#21147)

* fix: log and clear error in ui_comp_event

* fix: handling error in each map_foreach_value iteration

* fix: handling error decl in for_each loop

* fix: updating initerr to const, removing initerr free-ing

* fix: using ERROR_SET for error check

* fix: wrapping ERROR_INIT in parens to allow for including inside macro
This commit is contained in:
Andrew Willette
2022-11-30 14:32:57 -06:00
committed by GitHub
parent ef5ab2bf76
commit 282dda643a
3 changed files with 7 additions and 4 deletions

View File

@@ -12,7 +12,7 @@
#define ARRAY_DICT_INIT KV_INITIAL_VALUE
#define STRING_INIT { .data = NULL, .size = 0 }
#define OBJECT_INIT { .type = kObjectTypeNil }
#define ERROR_INIT { .type = kErrorTypeNone, .msg = NULL }
#define ERROR_INIT ((Error) { .type = kErrorTypeNone, .msg = NULL })
#define REMOTE_TYPE(type) typedef handle_T type
#define ERROR_SET(e) ((e)->type != kErrorTypeNone)

View File

@@ -186,7 +186,7 @@ void unpacker_init(Unpacker *p)
mpack_parser_init(&p->parser, 0);
p->parser.data.p = p;
mpack_tokbuf_init(&p->reader);
p->unpack_error = (Error)ERROR_INIT;
p->unpack_error = ERROR_INIT;
p->arena = (Arena)ARENA_EMPTY;
}

View File

@@ -706,15 +706,18 @@ static void ui_comp_grid_resize(UI *ui, Integer grid, Integer width, Integer hei
static void ui_comp_event(UI *ui, char *name, Array args)
{
Error err = ERROR_INIT;
UIEventCallback *event_cb;
bool handled = false;
map_foreach_value(&ui_event_cbs, event_cb, {
Error err = ERROR_INIT;
Object res = nlua_call_ref(event_cb->cb, name, args, false, &err);
if (res.type == kObjectTypeBoolean && res.data.boolean == true) {
handled = true;
}
if (ERROR_SET(&err)) {
ELOG("Error while executing ui_comp_event callback: %s", err.msg);
}
api_clear_error(&err);
})
if (!handled) {