[SOLVED] Uncatched exception in a function forces sync execution to wait till timeout to receive 500
- 0
- Functions
For example the first one is just for bad json, And you can try to send bad json to the function to see this error.
Also, When you're executing this function what is happening?
what do you mean by higher level? After completing runZoneGuarded (finishes also after throw) response.body
gettter should throw and error should be catched by the last catch braces
I see crash stacktrace in runtime container but executor container is waiting till timeout
ok I found it
Okay, So let's summarized,
These two exceptions has nothing to do with your server code
} on FormatException catch (_) {
return shelf.Response(500, body: jsonEncode({
'stderr': 'Unable to properly load request body',
'stdout': userLogs.join('\n')
}), headers: headers);
} catch (e) {
return shelf.Response(500, body: jsonEncode({
'stderr': e.toString(),
'stdout': userLogs.join('\n'),
}), headers: headers);
}
They can be run only if the errro is before your code.
Your code is being executed inside a zone
await runZonedGuarded(
() async {
await user_code.start(request, response);
},
(e, stackTrace) => print('$e $stackTrace'),
zoneSpecification: ZoneSpecification(
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
userLogs.add(line);
},
),
);
So all of the exceptions made inside the function will be caught by the zone. and then they will be printed out
(e, stackTrace) => print('$e $stackTrace'),
While your output will be added to userLogs
object.
Then, after your function as complete - in your case due to exception, then these lines will run
return shelf.Response.ok(
jsonEncode({
"response": response.body,
"stdout": userLogs.join('\n'),
"stderr": ""
}),
headers: headers);
So you can see that the shelf.Response.ok
is sending the the response body
Which in your case is empty
this could be problem only with dart runtime, I will confirm that in js today
but consider this code
try {
await runZonedGuarded(
() async => throw Error(),
(error, stack) {
print('error inside $error');
},
);
print('completed');
} catch (e) {
print('error outside $e');
}
Then you shouldn't see this one
print('error outside $e');
this prints:
error inside Instance of 'Error'
Exactly
so this stuck because of this zone
and response is never send back
And yes it's probably will be only in dart due to the way of the server runtime
The reason they use zone
is to be able to collect the output of the user
print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
userLogs.add(line);
},
sure, but in the documentation this is described:
/// The zone will always be an error-zone ([Zone.errorZone]), so returning
/// a future created inside the zone, and waiting for it outside of the zone,
/// will risk the future not being seen to complete.
That's why the response is being return after the zone. All the await are inside, and the return is outside.
just confirmed that works as expected on node runtime
Thanks for support, I will create issue in open runtimes repository
<a:agooglethumbsup:635256484682530825>
[SOLVED] Uncatched exception in a function forces sync execution to wait till timeout to receive 500
this is fixed in https://github.com/open-runtimes/open-runtimes/pull/136
Recommended threads
- Need help with createExecution function
Hi, Need some help understanding createExecution. When requesting function execution via createExecution, the function handler arguments are incorrect and rese...
- HTTP POST to function returning "No Appw...
Hi everyone, I’m running into an issue with my self-hosted Appwrite instance. I’ve set up my environment variables (APPWRITE_FUNCTION_PROJECT_ID, APPWRITE_FUNC...
- Can't add dart 3.5 runtime
Modified the `.env` to enable dart 3.5 runtime on my self-hosted instance but still can't find the runtime when creating a new function. I manually pulled the i...