mooa

Lua + lubev + sandboxing
git clone https://code.literati.org/mooa.git
Log | Files | Refs | README | LICENSE

commit 20511b886183e9e697ab8d22d7bd199807afba9f
parent e7538da6786fb85cc2bee624688013793ca0de01
Author: Sean Lynch <seanl@literati.org>
Date:   Wed, 25 Jun 2014 15:04:03 -0700

Report an error and kill the task rather than aborting

Diffstat:
Mhttp.c | 5+++--
Mtask.c | 11++++++++---
2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/http.c b/http.c @@ -4,6 +4,7 @@ #include "http_parser.h" +#include "http.h" #include "utils.h" @@ -20,7 +21,7 @@ static int mooa_http_notification_cb(http_parser *parser, const char *name) { static int mooa_http_data_cb(http_parser *parser, const char *name, - const char *data, int length) { + const char *data, size_t length) { lua_State *L = (lua_State *)parser->data; lua_getfield(L, -1, name); if (!lua_isfunction(L, -1)) { @@ -110,7 +111,7 @@ static int mooa_http_parser_execute(lua_State *L) { nparsed = http_parser_execute(parser, &mooa_http_parser_settings, data, length); if (nparsed != length) { - int error = HTTP_PARSER_ERRNO(parser); + enum http_errno error = HTTP_PARSER_ERRNO(parser); return luaL_error(L, "HTTP parsing failed (error %d): %s", error, http_errno_name(error)); } diff --git a/task.c b/task.c @@ -83,6 +83,10 @@ struct ev_loop *mooa_task_get_loop(lua_State *L) { static void mooa_task_schedule(mooa_task_t *task, int nargs) { + if (task->coro == NULL) { + warnx("Attempt to schedule task %p which is dead", task); + return; + } mooa_task_state_t *state = mooa_task_get_state(task->coro); warnx("Scheduling task %p", task); task->nargs = nargs; @@ -129,6 +133,7 @@ static void mooa_task_delete(mooa_task_t *task) { static void mooa_task_step(mooa_task_t *task) { + const char *error; assert(task->coro != NULL); int result = lua_resume(task->coro, NULL, task->nargs); switch (result) { @@ -140,9 +145,9 @@ static void mooa_task_step(mooa_task_t *task) { lua_settop(task->coro, 0); break; case LUA_ERRRUN: - /* TODO: do something with the error */ - fprintf(stderr, "Runtime error\n"); - lua_error(task->coro); + error = lua_tostring(task->coro, -1); + warnx("Runtime error in task %p: %s", task, error); + mooa_task_delete(task); break; case LUA_ERRMEM: fprintf(stderr, "Memory error\n");