Repository navigation
Description
Summary
flutter test crashes with an unhandled RangeError in truncate (package:test_core/src/util/pretty_print.dart:65) called from CompactReporter._progressLine (package:test_core/src/runner/reporter/compact.dart:445) when stdout.terminalColumns (lineLength) is narrow enough that lineLength - length < 4.
Crash Telemetry (Flutter stable/3.47.7)
- Signature:
RangeError at RangeError.checkValidRange at dart:core/errors.dart-aa4dd664 - Rank: Tweak to use async/await #2 Top Crasher in
3.47.7 - Total Occurrences: 79 (15.3% of Top 10, 8.0% of all
3.47.7crashes, ~10.3 crashes/day) - Platform Distribution: Windows: 77 (97.5%), macOS: 2 (2.5%)
- Sample Command:
flutter test test/app_state_test.dart --plain-name AppState Model and Discovery State Tests 3. Clearing search restores the correct filtered results - Error:
RangeError (start): Invalid value: Not in inclusive range 0..81: 84
Stack Trace
#0 RangeError.checkValidRange (dart:core/errors.dart:387)
#1 _StringBase.substring (dart:core-patch/string_patch.dart:437)
#2 truncate (package:test_core/src/util/pretty_print.dart:65)
#3 CompactReporter._progressLine (package:test_core/src/runner/reporter/compact.dart:445)
#4 CompactReporter._onTestStarted (package:test_core/src/runner/reporter/compact.dart:216)
#5 _rootRunUnary (dart:async/zone_root.dart:56)
#6 _CustomZone.runUnary (dart:async/zone.dart:816)
#7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:710)
Root Cause
In CompactReporter._progressLine (package:test_core/src/runner/reporter/compact.dart:444-450), the reporter computes the visible prefix length var length = withoutColors(buffer.toString()).length (e.g. 11 characters for \r00:00 +0: ) and calls utils.truncate(message, lineLength - length) followed by ' ' * (lineLength - withoutColors(buffer.toString()).length). When stdout.terminalColumns (lineLength in package:test_core/src/util/io.dart:27-37) reports a narrow column width on Windows ConPTY or narrow IDE terminal panes such that maxLength = lineLength - length < 4 (for example, lineLength == 12 and length == 11, giving maxLength == 1), truncate (package:test_core/src/util/pretty_print.dart:65) computes text.substring(text.length - maxLength + 4) (81 - 1 + 4 = 84), throwing a RangeError because the start index exceeds text.length (81).
Recommendation
- In
truncate(package:test_core/src/util/pretty_print.dart), guard againstmaxLength <= 4(e.g., return''whenmaxLength <= 0and'.' * maxLengthwhenmaxLength <= 3, or clamp thesubstringstart index to0..text.length). - In
CompactReporter._progressLine(package:test_core/src/runner/reporter/compact.dart), clamplineLength - lengthto a non-negative value before callingutils.truncateand before repeating' '. - In
lineLength(package:test_core/src/util/io.dart), fall back to_defaultLineLength(or a reasonable minimum width) whenstdout.terminalColumnsreturns an abnormally small value.
Activity
theprantadutta commentedon Oct 17, 2026
The root cause is in
package:test_core(truncateinpretty_print.dart), so I've opened dart-lang/test#2799 with a fix and a regression test. The test reproduces the sameRangeError (start)as the telemetry for anymaxLengthbelow 4, and passes with the fix. Flutter will pick it up once atest_corerelease that includes it is rolled in.Fix compact reporter crash when the terminal is too narrow (#2799)
theprantadutta commentedon Oct 23, 2026
The fix for this merged upstream in dart-lang/test#2799. When the terminal is too narrow to fit any of a test's name,
truncatenow returns as much of the ellipsis as fits instead of throwing theRangeError.It reaches Flutter once
test_core0.6.22 is published and rolled intoflutter_tools, so I've left this issue open until then.