[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
- Is Quick Start for function creation wor...
I am trying to create a Node.js function using the Quick Start feature. It fails and tells me that it could not locate the package.json file. Isn't Quick Start ...
- Connecting server functions to GitHub re...
The project I am working in has recently moved organizations on Appwrite. The same is true for the repo on GitHub, which as moved from a private user to a organ...
- Missing C++ libstdc library in Python fu...
I have a function running Python 3.12 which suddenly started dumping errors (as of today; it worked yesterday). I hadn't changed any code so I found this odd, b...
