forked from cory/tildefriends
Mostly fumbling with error handling.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4317 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
2158ad3c0b
commit
790f6643a4
@ -16,9 +16,7 @@
|
|||||||
- / => Something good.
|
- / => Something good.
|
||||||
- update docs
|
- update docs
|
||||||
- audit + document API exposed to apps
|
- audit + document API exposed to apps
|
||||||
- sqlStream => sqlExec or something
|
|
||||||
- fix weird HTTP warnings
|
- fix weird HTTP warnings
|
||||||
- ssb from child process?
|
|
||||||
- channels
|
- channels
|
||||||
- placeholder/missing images
|
- placeholder/missing images
|
||||||
- no denial of service
|
- no denial of service
|
||||||
@ -57,6 +55,8 @@
|
|||||||
- keep working on good error feedback
|
- keep working on good error feedback
|
||||||
- build for windows
|
- build for windows
|
||||||
- installable apps (bring back an app message?)
|
- installable apps (bring back an app message?)
|
||||||
|
- sqlStream => sqlExec or something
|
||||||
|
- !ssb from child process?
|
||||||
|
|
||||||
## Done
|
## Done
|
||||||
- update LICENSE
|
- update LICENSE
|
||||||
|
41
core/core.js
41
core/core.js
@ -79,8 +79,8 @@ function printError(out, error) {
|
|||||||
out.print(error.fileName + ":" + error.lineNumber + ": " + error.message);
|
out.print(error.fileName + ":" + error.lineNumber + ": " + error.message);
|
||||||
out.print(error.stackTrace);
|
out.print(error.stackTrace);
|
||||||
} else {
|
} else {
|
||||||
for (let i in error) {
|
for (let [k, v] of Object.entries(error)) {
|
||||||
out.print(i);
|
out.print(k, v);
|
||||||
}
|
}
|
||||||
out.print(error.toString());
|
out.print(error.toString());
|
||||||
}
|
}
|
||||||
@ -360,10 +360,10 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
if (process.app) {
|
if (process.app) {
|
||||||
process.app.makeFunction(['error'])(error);
|
process.app.makeFunction(['error'])(error);
|
||||||
} else {
|
} else {
|
||||||
print(error);
|
printError({print: print}, error);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
printError({print: print}, error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
imports.ssb = Object.fromEntries(Object.keys(ssb).map(key => [key, ssb[key].bind(ssb)]));
|
imports.ssb = Object.fromEntries(Object.keys(ssb).map(key => [key, ssb[key].bind(ssb)]));
|
||||||
@ -455,19 +455,23 @@ async function getProcessBlob(blobId, key, options) {
|
|||||||
printError({print: print}, e);
|
printError({print: print}, e);
|
||||||
}
|
}
|
||||||
broadcastEvent('onSessionBegin', [getUser(process, process)]);
|
broadcastEvent('onSessionBegin', [getUser(process, process)]);
|
||||||
resolveReady(process);
|
|
||||||
if (process.app) {
|
if (process.app) {
|
||||||
process.app.send({action: "ready"});
|
process.app.send({action: "ready"});
|
||||||
process.sendPermissions();
|
process.sendPermissions();
|
||||||
}
|
}
|
||||||
await process.task.execute({name: appSourceName, source: appSource});
|
await process.task.execute({name: appSourceName, source: appSource});
|
||||||
|
resolveReady(process);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (process.app) {
|
||||||
if (process?.task?.onError) {
|
if (process?.task?.onError) {
|
||||||
process.task.onError(error);
|
process.task.onError(error);
|
||||||
} else {
|
} else {
|
||||||
printError({print: print}, error);
|
printError({print: print}, error);
|
||||||
}
|
}
|
||||||
rejectReady();
|
} else {
|
||||||
|
printError({print: print}, error);
|
||||||
|
}
|
||||||
|
rejectReady(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return process;
|
return process;
|
||||||
@ -605,7 +609,10 @@ async function useAppHandler(response, handler_blob_id, path) {
|
|||||||
let promise = new Promise(async function(resolve, reject) {
|
let promise = new Promise(async function(resolve, reject) {
|
||||||
do_resolve = resolve;
|
do_resolve = resolve;
|
||||||
});
|
});
|
||||||
let process = await getProcessBlob(handler_blob_id, 'handler_' + g_handler_index++, {
|
let process;
|
||||||
|
let result;
|
||||||
|
try {
|
||||||
|
process = await getProcessBlob(handler_blob_id, 'handler_' + g_handler_index++, {
|
||||||
script: 'handler.js',
|
script: 'handler.js',
|
||||||
imports: {
|
imports: {
|
||||||
request: {
|
request: {
|
||||||
@ -614,8 +621,14 @@ async function useAppHandler(response, handler_blob_id, path) {
|
|||||||
respond: do_resolve,
|
respond: do_resolve,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
let result = await promise;
|
await process.ready;
|
||||||
|
|
||||||
|
result = await promise;
|
||||||
|
} finally {
|
||||||
|
if (process?.task) {
|
||||||
await process.task.kill();
|
await process.task.kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -777,8 +790,16 @@ async function blobHandler(request, response, blobId, uri) {
|
|||||||
let app_object = JSON.parse(utf8Decode(await getBlobOrContent(app_id)));
|
let app_object = JSON.parse(utf8Decode(await getBlobOrContent(app_id)));
|
||||||
id = app_object.files[uri.substring(1)];
|
id = app_object.files[uri.substring(1)];
|
||||||
if (!id && app_object.files['handler.js']) {
|
if (!id && app_object.files['handler.js']) {
|
||||||
let answer = await useAppHandler(response, app_id, uri.substring(1));
|
let answer;
|
||||||
if (typeof answer.data == 'string') {
|
try {
|
||||||
|
answer = await useAppHandler(response, app_id, uri.substring(1));
|
||||||
|
} catch (error) {
|
||||||
|
data = utf8Encode(`Internal Server Error\n\n${error?.message}\n${error?.stack}`);
|
||||||
|
response.writeHead(500, {'Content-Type': 'text/plain; charset=utf-8', 'Content-Length': data.length});
|
||||||
|
response.end(data);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (answer && typeof answer.data == 'string') {
|
||||||
answer.data = utf8Encode(answer.data);
|
answer.data = utf8Encode(answer.data);
|
||||||
}
|
}
|
||||||
sendData(response, answer?.data, answer?.content_type, {
|
sendData(response, answer?.data, answer?.content_type, {
|
||||||
|
@ -992,7 +992,6 @@ static JSValue _tf_ssb_createTunnel(JSContext* context, JSValueConst this_val, i
|
|||||||
tf_ssb_connection_t* connection = tf_ssb_connection_get(ssb, portal_id);
|
tf_ssb_connection_t* connection = tf_ssb_connection_get(ssb, portal_id);
|
||||||
if (connection)
|
if (connection)
|
||||||
{
|
{
|
||||||
// let request_number = await tfrpc.rpc.connectionSendJson(portal, {name: ['tunnel', 'connect'], args: [{portal: portal, target: target}], type: 'duplex'});
|
|
||||||
int32_t request_number = tf_ssb_connection_next_request_number(connection);
|
int32_t request_number = tf_ssb_connection_next_request_number(connection);
|
||||||
JSValue message = JS_NewObject(context);
|
JSValue message = JS_NewObject(context);
|
||||||
JSValue name = JS_NewArray(context);
|
JSValue name = JS_NewArray(context);
|
||||||
|
Loading…
Reference in New Issue
Block a user