Open
Description
In flutter/engine#50255 @jonahwilliams and I debugged a tough "this program doesn't catch errors" bug.
It was basically narrowed down to this minimal program:
void main() async {
try {
innerProgram();
} catch (e, s) {
exit(1);
}
}
void innerProgram() async {
try {
await runAndFail();
} finally {
// BUG: Even if a failure happens, the program will terminate.
exit(0);
}
}
void runAndFail() async {
throw 'Fail';
}
https://dart.dev/tools/linter-rules/control_flow_in_finally appears to be able to philosophically catch this bug.
I wonder if we could enhance it to lint functions that return Never
, i.e.:
void main() {
try {} finally {
// LINT
throw 'Big Bad';
}
}
void main() {
Never panic() => throw 'Big Bad';
try {} finally {
// LINT
panic();
}
}
void main() {
try {} finally {
// LINT
exit(0);
}
}