Open Noobware1 opened 11 months ago
I think this is primarily caused because error handling isn't really implemented yet in combination with async/await
, so I'll rename this issue to reflect that. In the meantime you might be able to make this work by replacing async/await stuff with Future.then() etc in the affected codepath.
It's ok I can wait that'll be more easier.
But I am confused about one thing this code is not eval code this is real dart code so error handling is done in actually dart, so it should fine right?
Well it appears that the loadMediaDetails() eval code implementation contains an await
in it or calls a function that uses await
.
So the error thrown in loadMediaDetails should catched by above catch block but It doesn't?
Yeah. Because loadMediaDetails has an await somewhere in it, that currently breaks its ability to throw exceptions across the bridge.
Ic, Thanks for the explanation.
If this issue gets resolved will I be able to bridge these type of functions and not get any error?
T? trySync<T>(T Function() fun) {
try {
return fun();
} catch (e) {
return null;
}
}
Future<T?> tryAsync<T>(Future<T> Function() fun) async {
try {
return await fun();
} catch (e) {
return null;
}
}
The first function trySync should already work, no? But yeah once I get around to fixing this you'd probably be able to use tryAsync too either as a bridge or eval function.
yeah, it works.
test('trySync', () {
final value = compiler.compileWriteAndLoad({
'example': {
'main.dart': '''
import 'package:meiyou_extensions_lib/meiyou_extensions_lib.dart';
int? main() {
return AppUtils.trySync<int>(() => StringUtils.toInt('this is not a number'));
}
'''
}
}).executeLib('package:example/main.dart', 'main');
expect((value as $Value).$value, null);
});
Any update on this?
This is a complicated issue to solve with a lot of edge cases, it's not going to be done that soon unfortunately.
Is there any way I can help cause I need this fix bad but I also understand where you coming from so it's ok if it can't be done right now
Alright, I figured out a temporary change I could do to allow errors to propagate through an await to the top-level. This isn't really correct since try/catch blocks inside dart_eval still won't work at all, but at least it should let a try/catch in real Dart that surrounds it function for the most part. Released in v0.7.3, don't close this though since it's not actually fixed in a correct way
Thanks a lot man
Alright, I figured out a temporary change I could do to allow errors to propagate through an await to the top-level. This isn't really correct since try/catch blocks inside dart_eval still won't work at all, but at least it should let a try/catch in real Dart that surrounds it function for the most part. Released in v0.7.3, don't close this though since it's not actually fixed in a correct way
try catch in real dart still isn't able to catch it sadly.
Can you give more info on the error you get? I have tested it and this test passes successfully:
test('Exception bubbles through asynchronous gap', () {
final runtime = compiler.compileWriteAndLoad({
'example': {
'main.dart': '''
import 'dart:async';
void main() async {
await Future.delayed(const Duration(milliseconds: 10));
throw 'error';
}
'''
}
});
expect(() => runtime.executeLib('package:example/main.dart', 'main'),
throwsA($String('error')));
});
here I am trying to catch the error thrown by loadMediaDetails but I am unable to do so.
I mean it should print
Caught error
but instead it prints this