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> { ...@@ -249,7 +249,7 @@ class AsyncSnapshot<T> {
if (hasData) if (hasData)
return data!; return data!;
if (hasError) 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'); throw StateError('Snapshot has neither data nor error');
} }
......
...@@ -12,6 +12,20 @@ void main() { ...@@ -12,6 +12,20 @@ void main() {
return Text(snapshot.toString(), textDirection: TextDirection.ltr); return Text(snapshot.toString(), textDirection: TextDirection.ltr);
} }
group('AsyncSnapshot', () { 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', () { test('requiring data succeeds if data is present', () {
expect( expect(
const AsyncSnapshot<String>.withData(ConnectionState.done, 'hello').requireData, 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