Repository navigation
AnsiTerminal not populated correctly in the flutter_tools context for daemon runs #13993
Description
From @zzzev on January 4, 2018 23:51
Since updating to version 20 of the plug-in, when I run any flutter app in IntelliJ, it launches successfully, but then shows this error in the console (before any output from my app):
Error -32603 received from application: Internal error
Error initializing DevFS: NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: []("uri")
Unhandled exception:
NoSuchMethodError: The getter 'supportsColor' was called on null.
Receiver: null
Tried calling: supportsColor
#0 Object.noSuchMethod (dart:core-patch/dart:core/object_patch.dart:46)
#1 StdoutLogger.printStatus (package:flutter_tools/src/base/logger.dart:79)
#2 _AppRunLogger.printStatus (package:flutter_tools/src/commands/daemon.dart:821)
#3 printStatus (package:flutter_tools/src/globals.dart:39)
#4 FlutterDevice.startEchoingDeviceLog.<anonymous closure> (package:flutter_tools/src/resident_runner.dart:222)
#5 _rootRunUnary (dart:async/zone.dart:1134)
#6 _CustomZone.runUnary (dart:async/zone.dart:1031)
#7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933)
#8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:330)
#9 _DelayedData.perform (dart:async/stream_impl.dart:578)
#10 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:694)
#11 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:654)
#12 _rootRun (dart:async/zone.dart:1126)
#13 _CustomZone.run (dart:async/zone.dart:1023)
#14 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:949)
#15 _microtaskLoop (dart:async/schedule_microtask.dart:41)
#16 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
#17 _runPendingImmediateCallback (dart:isolate-patch/dart:isolate/isolate_patch.dart:111)
#18 _RawReceivePortImpl._handleMessage (dart:isolate-patch/dart:isolate/isolate_patch.dart:164)
After this error, IntelliJ seems to think the run failed, so even though the app is running fine in the emulator, I cannot see any logged information. Based on the patch notes, I suspect this has to do with "improved console filtering" in version 20.
This does not happen when I run the app from the command line (i.e. not through IntelliJ), so I am almost certain this is an issue with the new version of the plug-in.
Steps to Reproduce
- Run any flutter app, observe console
Version info
[✓] IntelliJ IDEA Ultimate Edition (version 2017.2)
• Flutter plugin version 20.0.2
• Dart plugin version 172.4343.25
[✓] Connected devices
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.0.0 (API 26) (emulator)
Copied from original issue: flutter/flutter-intellij#1614
Activity
devoncarew commentedon Jan 9, 2018
From @zzzev on January 5, 2018 0:1
After repro-ing this consistently all day in IntelliJ, this appears to have fixed itself. I have no idea what changed, but I'll go ahead and close this for now. Apologies for the (potentially?) false alarm.
devoncarew commentedon Jan 9, 2018
From @zzzev on January 8, 2018 19:11
This is recurring again, though I'm not sure what changed. Would appreciate any insight into how to track this down and fix it.
devoncarew commentedon Jan 9, 2018
As @tvolkert mentioned on an internal thread, it seems likely that
AnsiTerminalis not being populated in the context for daemon (IDE) runs.jcollins-g commentedon Jan 31, 2018
I am unable to reproduce this problem myself, and spot checks with the debugger seem to indicate that we get context populated correctly. However, there are at least two spots in the code where AnsiTerminal is not populated that could be relevant: here and here. Since it seems that the intention here is to default to
_kAnsiTerminalif we don't have one from the context, I think correcting this line to do that in the case where we have an unpopulated context should be safe.IMO the way dependencies are undocumented and unchecked in
AppContextobjects is going to lead to this sort of problem -- there's no way to declare if that the context has aFoo, it must also have aBar. In this case, it seems that if you haveLogger, you must have anAnsiTerminal. So bugs like this are bound to crop up.A larger refactor might:
For now though I'll try the simpler solution.
zzzev commentedon Feb 7, 2018
Thank you for looking into this, and appreciate the fix.
For posterity, I was able to figure out that this was an emulator-image-specific issue; creating a new emulator image fixed the issue. I'm not sure what about the problematic images was causing the issue, but I do have some old emulator images hanging around that will consistently repro this -- happy to help out if there's something worth investigating about those images.
jcollins-g commentedon Feb 8, 2018
@zzzev Thanks for the update! If you have time, it would be great if you could verify that the fix in #14401 is effective with your old image, as I have not been able to reproduce the original issue.
Whether or not the error occurs probably is based on whether or not flutter is trying to log something at a specific point where AnsiTerminal is not properly set up, so it makes sense that random external environment changes could impact it. Unfortunately because the log message itself is lost in the crash, I can't say what it is (though if we ran flutter with a debugger we probably could find out).
All that said, it's probably not worth the effort to research it deeply: the fix is probably what the code should have been doing originally anyway.
d1cac77 Roll src/third_party/skia 47af12aa8331..c3ff97a98b74 (3 commi…
github-actions commentedon Sep 4, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.