Requiring data preserves the stackTrace (#93592)
This commit is contained in:
parent
af9cf734e8
commit
e05ddcbd9e
@ -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() {
|
|||||||
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,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user