avoid-missing-completer-stack-trace
preset: recommended
Warns when Completer.completeError
is called without providing a stack trace.
By default, completeError
gets an empty stack trace. Consider passing StackTrace.current
or Error(...).stackTrace
to the invocation.
Example
❌ Bad:
import 'dart:async';
void fn() {
final completer = Completer();
// LINT: This invocation will result in an empty stack trace. To avoid this, try passing a second argument (e.g. 'StackTrace.current' or 'error.stackTrace').
completer.completeError('foo');
// LINT: This invocation will result in an empty stack trace. To avoid this, try passing a second argument (e.g. 'StackTrace.current' or 'error.stackTrace').
Completer().completeError('foo');
}
✅ Good:
import 'dart:async';
void fn() {
final completer = Completer();
completer.completeError('foo', StackTrace.current); // Correct, passes stack trace
Completer().completeError('foo', Error(...).stackTrace); // Correct, passes stack trace
}