Unverified Commit e05ddcbd authored by Remi Rousselet's avatar Remi Rousselet Committed by GitHub

Requiring data preserves the stackTrace (#93592)

parent af9cf734
......@@ -249,7 +249,7 @@ class AsyncSnapshot<T> {
if (hasData)
return data!;
if (hasError)
throw error!; // ignore: only_throw_errors, since we're just propagating an existing error
Error.throwWithStackTrace(error!, stackTrace!);
throw StateError('Snapshot has neither data nor error');
}
......
......@@ -12,6 +12,20 @@ void main() {
return Text(snapshot.toString(), textDirection: TextDirection.ltr);
}
group('AsyncSnapshot', () {
test('requiring data preserves the stackTrace', () {
final StackTrace originalStackTrace = StackTrace.current;
try {
AsyncSnapshot<String>.withError(
ConnectionState.done,
Error(),
originalStackTrace,
).requireData;
fail('requireData did not throw');
} catch (error, stackTrace) {
expect(stackTrace, originalStackTrace);
}
});
test('requiring data succeeds if data is present', () {
expect(
const AsyncSnapshot<String>.withData(ConnectionState.done, 'hello').requireData,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment