Consolidate error handling until util, too.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3682 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
44
src/ssb.js.c
44
src/ssb.js.c
@ -160,34 +160,6 @@ static JSValue _tf_ssb_connections(JSContext* context, JSValueConst this_val, in
|
||||
return result;
|
||||
}
|
||||
|
||||
static void _check_call(JSContext* context, JSValue result)
|
||||
{
|
||||
if (JS_IsError(context, result))
|
||||
{
|
||||
const char* value = JS_ToCString(context, result);
|
||||
printf("ERROR: %s\n", value);
|
||||
JS_FreeCString(context, value);
|
||||
JSValue stack = JS_GetPropertyStr(context, result, "stack");
|
||||
if (!JS_IsUndefined(stack))
|
||||
{
|
||||
const char* stack_str = JS_ToCString(context, stack);
|
||||
printf("%s\n", stack_str);
|
||||
JS_FreeCString(context, stack_str);
|
||||
}
|
||||
JS_FreeValue(context, stack);
|
||||
}
|
||||
else if (JS_IsException(result))
|
||||
{
|
||||
js_std_dump_error(context);
|
||||
JSValue error = JS_GetException(context);
|
||||
const char* value = JS_ToCString(context, error);
|
||||
printf("Exception: %s\n", value);
|
||||
JS_FreeCString(context, value);
|
||||
JS_FreeValue(context, error);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct _sqlStream_callback_t
|
||||
{
|
||||
JSContext* context;
|
||||
@ -198,7 +170,7 @@ static void _tf_ssb_sqlStream_callback(JSValue row, void* user_data)
|
||||
{
|
||||
sqlStream_callback_t* info = user_data;
|
||||
JSValue response = JS_Call(info->context, info->callback, JS_UNDEFINED, 1, &row);
|
||||
_check_call(info->context, response);
|
||||
tf_util_report_error(info->context, response);
|
||||
JS_FreeValue(info->context, response);
|
||||
if (tf_task_get(info->context))
|
||||
{
|
||||
@ -214,7 +186,7 @@ static void _tf_ssb_sqlStream_callback(JSValue row, void* user_data)
|
||||
if (context)
|
||||
{
|
||||
JSValue result = JS_GetException(context);
|
||||
_check_call(context, result);
|
||||
tf_util_report_error(context, result);
|
||||
}
|
||||
if (r < 0)
|
||||
{
|
||||
@ -373,7 +345,7 @@ static void _tf_ssb_call_callback(tf_ssb_t* ssb, const char* name, void* user_da
|
||||
{
|
||||
JSValue args = JS_UNDEFINED;
|
||||
JSValue response = JS_Call(context, callback, JS_UNDEFINED, 0, &args);
|
||||
_check_call(context, response);
|
||||
tf_util_report_error(context, response);
|
||||
if (tf_task_get(context))
|
||||
{
|
||||
tf_task_run_jobs(tf_task_get(context));
|
||||
@ -463,7 +435,7 @@ void _tf_ssb_on_rpc(tf_ssb_connection_t* connection, uint8_t flags, int32_t requ
|
||||
JS_SetPropertyStr(context, object, "send_binary", JS_NewCFunction(context, _tf_ssb_rpc_send_binary, "send_binary", 1));
|
||||
|
||||
JSValue result = JS_Call(context, callback, JS_UNDEFINED, 1, &object);
|
||||
_check_call(context, result);
|
||||
tf_util_report_error(context, result);
|
||||
JS_FreeValue(context, result);
|
||||
JS_FreeValue(context, object);
|
||||
}
|
||||
@ -521,7 +493,7 @@ static void _tf_ssb_on_blob_want_added(tf_ssb_t* ssb, const char* id, void* user
|
||||
JSValue callback = JS_MKPTR(JS_TAG_OBJECT, user_data);
|
||||
JSValue string = JS_NewString(context, id);
|
||||
JSValue response = JS_Call(context, callback, JS_UNDEFINED, 1, &string);
|
||||
_check_call(context, response);
|
||||
tf_util_report_error(context, response);
|
||||
JS_FreeValue(context, response);
|
||||
JS_FreeValue(context, string);
|
||||
}
|
||||
@ -562,7 +534,7 @@ static void _tf_ssb_rpc_on_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_ch
|
||||
};
|
||||
printf("calling function for ptr %p IsFunction=%d\n", user_data, JS_IsFunction(context, callback));
|
||||
response = JS_Call(context, callback, JS_UNDEFINED, 2, args);
|
||||
_check_call(context, response);
|
||||
tf_util_report_error(context, response);
|
||||
JS_FreeValue(context, args[0]);
|
||||
JS_FreeValue(context, object);
|
||||
}
|
||||
@ -576,7 +548,7 @@ static void _tf_ssb_rpc_on_connections_changed_callback(tf_ssb_t* ssb, tf_ssb_ch
|
||||
object,
|
||||
};
|
||||
response = JS_Call(context, callback, JS_UNDEFINED, 2, args);
|
||||
_check_call(context, response);
|
||||
tf_util_report_error(context, response);
|
||||
JS_FreeValue(context, args[0]);
|
||||
JS_FreeValue(context, object);
|
||||
}
|
||||
@ -649,7 +621,7 @@ void tf_ssb_run_file(JSContext* context, const char* file_name)
|
||||
JSContext* context2 = NULL;
|
||||
int r = JS_ExecutePendingJob(runtime, &context2);
|
||||
JSValue result = JS_GetException(context2);
|
||||
_check_call(context, result);
|
||||
tf_util_report_error(context, result);
|
||||
if (r == 0)
|
||||
{
|
||||
break;
|
||||
|
Reference in New Issue
Block a user