Skip to content

AnsiTerminal not populated correctly in the flutter_tools context for daemon runs #13993

Closed

Description

@devoncarew

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

  1. 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

  1. devoncarew commented on Jan 9, 2018

    @devoncarew
    ContributorAuthor

    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.

  2. devoncarew commented on Jan 9, 2018

    @devoncarew
    ContributorAuthor

    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.

  3. devoncarew commented on Jan 9, 2018

    @devoncarew
    ContributorAuthor

    As @tvolkert mentioned on an internal thread, it seems likely that AnsiTerminal is not being populated in the context for daemon (IDE) runs.

  4. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Jan 9, 2018
  5. self-assigned this
    on Jan 31, 2018
  6. jcollins-g commented on Jan 31, 2018

    @jcollins-g
    Contributor

    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 _kAnsiTerminal if 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 AppContext objects is going to lead to this sort of problem -- there's no way to declare if that the context has a Foo, it must also have a Bar. In this case, it seems that if you have Logger, you must have an AnsiTerminal. So bugs like this are bound to crop up.

    A larger refactor might:

    • Figure out some way to have each object in a context declare its dependencies (possibly a static getter returning a list of types)
    • Have a context.finalize() that freezes the context and checks dependencies, throwing if they are not satisfied
    • Have a set of default objects like AnsiTerminal in the context that are always there unless overridden by the user

    For now though I'll try the simpler solution.

  7. zzzev commented on Feb 7, 2018

    @zzzev
    Contributor

    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.

  8. jcollins-g commented on Feb 8, 2018

    @jcollins-g
    Contributor

    @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.

  9. added a commit that references this issue on Nov 23, 2019
  10. github-actions commented on Sep 4, 2021

    @github-actions

    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 -v and a minimal reproduction of the issue.

  11. locked as resolved and limited conversation to collaborators on Sep 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

toolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions