Made sure that SQL errors make it to the client.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3867 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-04-18 00:24:00 +00:00
parent 11ad344e52
commit 804359d12e
6 changed files with 53 additions and 36 deletions

View File

@ -187,6 +187,36 @@ static bool _serialize_storeInternal(tf_task_t* task, tf_taskstub_t* to, buffer_
fprintf(stderr, "Unable to store number.\n");
}
}
else if (JS_IsException(value))
{
JSValue exception = JS_GetException(context);
const char* message = JS_ToCString(context, exception);
JSValue error = JS_NewObject(context);
JS_SetPropertyStr(context, error, "message", JS_NewString(context, message ? message : "[exception]"));
if (JS_IsError(context, exception))
{
JSValue m = JS_GetPropertyStr(context, exception, "message");
if (!JS_IsUndefined(m) && !JS_IsException(m))
{
const char* ms = JS_ToCString(context, m);
JS_FreeCString(context, ms);
}
JSValue stack = JS_GetPropertyStr(context, exception, "stack");
if (!JS_IsUndefined(stack) && !JS_IsException(stack))
{
JS_SetPropertyStr(context, error, "stack", JS_DupValue(context, stack));
}
JS_FreeValue(context, stack);
}
_serialize_writeInt32(buffer, kException);
_serialize_storeInternal(task, to, buffer, error, depth + 1);
JS_FreeCString(context, message);
JS_FreeValue(context, error);
JS_FreeValue(context, exception);
}
else if (JS_IsString(value))
{
size_t len = 0;
@ -235,27 +265,6 @@ static bool _serialize_storeInternal(tf_task_t* task, tf_taskstub_t* to, buffer_
exportid_t exportId = tf_task_export_function(task, to, value);
_serialize_writeInt32(buffer, exportId);
}
else if (JS_IsException(value))
{
JSValue exception = JS_GetException(context);
JSValue error = JS_NewObject(context);
JSValue message = JS_GetPropertyStr(context, exception, "message");
if (!JS_IsException(message))
{
JS_SetPropertyStr(context, error, "message", message);
}
if (JS_IsError(context, exception))
{
JSValue stack = JS_GetPropertyStr(context, exception, "stack");
if (!JS_IsUndefined(stack))
{
JS_SetPropertyStr(context, error, "stack", JS_DupValue(context, stack));
}
}
_serialize_writeInt32(buffer, kException);
_serialize_storeInternal(task, to, buffer, error, depth + 1);
JS_FreeValue(context, error);
}
else if (JS_IsError(tf_task_get_context(task), value))
{
_serialize_writeInt32(buffer, kError);