Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while inspecting variable in flutter web. #1814

Open
Pacane opened this issue Dec 8, 2022 · 5 comments
Open

Error while inspecting variable in flutter web. #1814

Pacane opened this issue Dec 8, 2022 · 5 comments

Comments

@Pacane
Copy link

Pacane commented Dec 8, 2022

I've reported an exception I've gotten while using emacs with lsp-dart here.

Turns out @DanTup was able to reproduce it with my repro project using VSCode. He directed me here to open an issue as it seems to be an issue a bit deeper than just the lsp plugin I'm using. I'll try to describe as best as possible was was discussed in the other issue here.


Describe the bug
When expanding a local variable (not happening with all variables), in the DAP ui mode, I get an exception.

For reference, I tried expanding the variable searchState in my case. And for more context, I'm able to inspect such variables in IntelliJ and VSCode.

To Reproduce
I'm using a closed source project, but what I'm doing specifically is trying to expand a variable that's passed as a closure, which has for type a Freezed union type value.

Expected behavior
It would expand the thing normally.

Screenshots
image

Version
Include here the result of: M-x lsp-dart-version
image

Here's the actual stacktrace

LSP :: Connected to [dart_analysis_server:2563275].
dap-request: getObject: (-32603) getObject: Unexpected error from chrome devtools:
text: Uncaught
exception:
  description: TypeError: Cannot read properties of undefined (reading ’name’)
    at <anonymous>:9:25
    at <anonymous>:83:7
    at http://localhost:37141/packages/braver_flutter_domain_ui/src/pages/profile/sections/visibility/select_professions_search_capsule.dart.lib.js:155:15
    at Generator.next (<anonymous>)
    at runBody (http://localhost:37141/dart_sdk.js:40595:34)
    at Object._async [as async] (http://localhost:37141/dart_sdk.js:40626:7)
    at SearchCapsule.new.<anonymous> (http://localhost:37141/packages/braver_flutter_domain_ui/src/pages/profile/sections/visibility/select_professions_search_capsule.dart.lib.js:154:674)
    at SearchCapsule.new.triggerBuilder (http://localhost:37141/packages/braver_flutter_ui/src/themed_app.dart.lib.js:15279:74)
    at triggerBuilder.next (<anonymous>)
    at runBody (http://localhost:37141/dart_sdk.js:40595:34)
    at Object._async [as async] (http://localhost:37141/dart_sdk.js:40626:7)
    at SearchCapsule.new.triggerBuilder (http://localhost:37141/packages/braver_flutter_ui/src/themed_app.dart.lib.js:15277:22)
    at _MapStream.new.<anonymous> (http://localhost:37141/packages/braver_flutter_ui/src/themed_app.dart.lib.js:15144:286)
    at [_handleData] (http://localhost:37141/dart_sdk.js:38392:60)
    at [_handleData] (http://localhost:37141/dart_sdk.js:38300:37)
    at _rootRunUnary (http://localhost:37141/dart_sdk.js:40864:46)
    at async._CustomZone.new.runUnary (http://localhost:37141/dart_sdk.js:40047:14)
    at async._CustomZone.new.runUnaryGuarded (http://localhost:37141/dart_sdk.js:39967:14)
    at [_sendData] (http://localhost:37141/dart_sdk.js:34170:22)
    at _DelayedData.new.perform (http://localhost:37141/dart_sdk.js:37455:28)
    at _PendingEvents.new.handleNext (http://localhost:37141/dart_sdk.js:37592:15)
    at http://localhost:37141/dart_sdk.js:37564:16
    at _rootRun (http://localhost:37141/dart_sdk.js:40852:46)
    at async._CustomZone.new.run (http://localhost:37141/dart_sdk.js:40041:14)
    at async._CustomZone.new.runGuarded (http://localhost:37141/dart_sdk.js:39955:14)
    at http://localhost:37141/dart_sdk.js:40003:33
    at _rootRun (http://localhost:37141/dart_sdk.js:40858:14)
    at async._CustomZone.new.run (http://localhost:37141/dart_sdk.js:40041:14)
    at async._CustomZone.new.runGuarded (http://localhost:37141/dart_sdk.js:39955:14)
    at async._AsyncCallbackEntry.new.callback (http://localhost:37141/dart_sdk.js:40003:33)
    at Object._microtaskLoop (http://localhost:37141/dart_sdk.js:40705:13)
    at _startMicrotaskLoop (http://localhost:37141/dart_sdk.js:40711:13)
    at http://localhost:37141/dart_sdk.js:36447:9
  type: object
  value: null
attempted JS eval: ‘    (function() {
         var sdkUtils = require(’dart_sdk’).dart;
   var library = sdkUtils.getLibrary(’package:braver_flutter_ui/src/components/forms/search_capsule.dart’);
   if (!library) throw ’cannot find library for package:braver_flutter_ui/src/components/forms/search_capsule.dart’;
  
      var result = {};
      var clazz = library["_$36_Closed"];
      var descriptor = {
          ’name’: clazz.name,
          ’dartName’: sdkUtils.typeName(clazz)
        };

      // TODO(grouma) - we display all inherited methods since we don’t provide
      // the superClass information. This is technically not correct.
      var proto = clazz.prototype;
      var methodNames = [];
      for (; proto != null; proto = Object.getPrototypeOf(proto)) {
        var methods = Object.getOwnPropertyNames(proto);
        for (var i = 0; i < methods.length; i++) {
          if (methodNames.indexOf(methods[i]) == -1
              && methods[i] != ’constructor’) {
              methodNames.push(methods[i]);
          }
        }
        if (proto.constructor.name == ’Object’) break;
      }

      descriptor[’methods’] = {};
      for (var name of methodNames) {
        descriptor[’methods’][name] = {
          // TODO(jakemac): how can we get actual const info?
          "isConst": false,
          "isStatic": false,
        }
      }

      var fields = sdkUtils.getFields(clazz);
      var fieldNames = fields ? Object.keys(fields) : [];
      descriptor[’fields’] = {};
      for (var name of fieldNames) {
        var field = fields[name];
        var libraryUri = Object.getOwnPropertySymbols(fields[name]["type"])
        .find(x => x.description == "libraryUri");
        descriptor[’fields’][name] = {
          // TODO(jakemac): how can we get actual const info?
          "isConst": false,
          "isFinal": field.isFinal,
          "isStatic": false,
          "classRefName": fields[name]["type"]["name"],
          "classRefDartName": sdkUtils.typeName(fields[name]["type"]),
          "classRefLibraryId" : field["type"][libraryUri],
        }
      }

      // TODO(elliette): The following static member information is minimal and 
      // should be replaced once DDC provides full symbol information (see 
      // https://github.com/dart-lang/sdk/issues/40273):

      descriptor[’staticFields’] = {};
      var staticFieldNames = sdkUtils.getStaticFields(clazz) ?? [];
      for (const name of staticFieldNames) {
        descriptor[’staticFields’][name] = {
          "isStatic": true,
          // DDC only provides names of static members, we set isConst/isFinal 
          // to false even though they could be true.
          "isConst": false,
          "isFinal": false,
        }
      }

      descriptor[’staticMethods’] = {};
      var staticMethodNames = sdkUtils.getStaticMethods(clazz) ?? [];
      for (var name of staticMethodNames) {
        descriptor[’methods’][name] = {
          // DDC only provides names of static members, we set isConst
          // to false even though it could be true.
          "isConst": false,
          "isStatic": true,
        } 
      }

      return descriptor;
    })()
    ‘

#0      ClassHelper._constructClass (package:dwds/src/debugging/classes.dart:178:7)
<asynchronous suspension>
#1      StackZoneSpecification._registerUnaryCallback.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart:125:47)
<asynchronous suspension>

@DanTup asked for repro steps and gave some context:

IntelliJ should generally behave the same here too. The DAP used by VS Code (and emacs here) is just wrapping the VM Service which IntelliJ also uses. It's very possible (even likely) there are some differences in how it fetches and renders data for variables, although something like this seems like it should show up in both.

If you're able to build a small repro you can share that triggers the issue I'm happy to take a look too. A full DAP traffic log would be useful too (using the same sharable repro), in case I can't reproduce it myself.


Then I posted my repro steps

There you go https://github.com/Pacane/lsp_repro

Just a bit of context for the app (tried to replicate as much of what I'm doing in my real project).

It's the regular counter app, but with a bloc to hold a value state. The state and events of the bloc are actual Freezed classes (events are union types and state is a freezed immutable object).

There's a bloc builder in the main app that renders a Text widget with the value held in the bloc.

If you add a breakpoint on the line 79 (return line), and expand bloc -> _state in the dap UI locals, you do get the error I posted earlier.

dap-request: getObject: (-32603) getObject: Unexpected error from chrome devtools:
text: Uncaught
exception:
  description: TypeError: Cannot read properties of undefined (reading ’name’)
    at <anonymous>:9:25
    at <anonymous>:83:7
    at http://localhost:38069/packages/repro_lsp/main.dart.lib.js:442:810
    at bloc$._$_MyStateWithValue.new.when (http://localhost:38069/packages/repro_lsp/bloc.dart.lib.js:556:14)
    at BlocBuilder.new.<anonymous> (http://localhost:38069/packages/repro_lsp/main.dart.lib.js:442:642)
    at BlocBuilder.new.build (http://localhost:38069/packages/flutter_bloc/src/multi_bloc_listener.dart.lib.js:803:21)
    at _BlocBuilderBaseState.new.build (http://localhost:38069/packages/flutter_bloc/src/multi_bloc_listener.dart.lib.js:892:288)
    at framework.StatefulElement.new.build (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61935:25)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29540:22)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61976:13)
    at framework.StatefulElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatefulElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61997:12)
    at framework.MultiChildRenderObjectElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.MultiChildRenderObjectElement.new.updateChildren (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25687:44)
    at framework.MultiChildRenderObjectElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:30068:36)
    at framework.SingleChildRenderObjectElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.SingleChildRenderObjectElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:39631:31)
    at framework.StatelessElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatelessElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatelessElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatelessElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61916:12)
    at framework.StatelessElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatelessElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatelessElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatelessElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61916:12)
    at framework.InheritedElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.InheritedElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.InheritedElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.InheritedElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29626:12)
    at ParentDataElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at ParentDataElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at ParentDataElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at ParentDataElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29626:12)
    at framework.MultiChildRenderObjectElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.MultiChildRenderObjectElement.new.updateChildren (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25687:44)
    at framework.MultiChildRenderObjectElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:30068:36)
    at framework.InheritedElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.InheritedElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.InheritedElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.InheritedElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29626:12)
    at framework.StatefulElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61976:13)
    at framework.StatefulElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatefulElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61997:12)
    at framework.StatefulElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61976:13)
    at framework.StatefulElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatefulElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61997:12)
    at framework.InheritedElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.InheritedElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.InheritedElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.InheritedElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29626:12)
    at framework.StatefulElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61976:13)
    at framework.StatefulElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatefulElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61997:12)
    at framework.SingleChildRenderObjectElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.SingleChildRenderObjectElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:39631:31)
    at _NotificationElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at _NotificationElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at _NotificationElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at _NotificationElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29626:12)
    at framework.SingleChildRenderObjectElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.SingleChildRenderObjectElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:39631:31)
    at framework.StatefulElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61976:13)
    at framework.StatefulElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatefulElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61997:12)
    at framework.StatefulElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61976:13)
    at framework.StatefulElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatefulElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61997:12)
    at framework.InheritedElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.InheritedElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.InheritedElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.InheritedElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29626:12)
    at _NotificationElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at _NotificationElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at _NotificationElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at _NotificationElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29626:12)
    at _NotificationElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at _NotificationElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at _NotificationElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at _NotificationElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29626:12)
    at framework.StatefulElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61976:13)
    at framework.StatefulElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatefulElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61997:12)
    at framework.InheritedElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.InheritedElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.InheritedElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.InheritedElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29626:12)
    at framework.StatefulElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61976:13)
    at framework.StatefulElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.StatefulElement.new.update (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61997:12)
    at framework.StatefulElement.new.updateChild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:24844:17)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:29563:33)
    at framework.StatefulElement.new.performRebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61976:13)
    at framework.StatefulElement.new.rebuild (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:25424:12)
    at framework.BuildOwner.new.buildScope (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:61386:21)
    at binding$5.WidgetsFlutterBinding.new.drawFrame (http://localhost:38069/packages/flutter/src/widgets/title.dart.lib.js:64198:43)
    at [_handlePersistentFrameCallback] (http://localhost:38069/packages/flutter/src/rendering/view.dart.lib.js:712:12)
    at [_invokeFrameCallback] (http://localhost:38069/packages/flutter/src/scheduler/binding.dart.lib.js:782:9)
    at binding$5.WidgetsFlutterBinding.new.handleDrawFrame (http://localhost:38069/packages/flutter/src/scheduler/binding.dart.lib.js:749:37)
    at [_handleDrawFrame] (http://localhost:38069/packages/flutter/src/scheduler/binding.dart.lib.js:696:12)
    at Object.invoke (http://localhost:38069/dart_sdk.js:196986:7)
    at _engine.EnginePlatformDispatcher.new.invokeOnDrawFrame (http://localhost:38069/dart_sdk.js:172327:15)
    at http://localhost:38069/dart_sdk.js:196709:57
    at Object._checkAndCall (http://localhost:38069/dart_sdk.js:5438:16)
    at Object.dcall (http://localhost:38069/dart_sdk.js:5443:17)
    at ret (http://localhost:38069/dart_sdk.js:62137:21)
  type: object
  value: null
attempted JS eval: ‘    (function() {
         var sdkUtils = require(’dart_sdk’).dart;
   var library = sdkUtils.getLibrary(’package:repro_lsp/bloc.dart’);
   if (!library) throw ’cannot find library for package:repro_lsp/bloc.dart’;
  
      var result = {};
      var clazz = library["_$36_MyStateWithValue"];
      var descriptor = {
          ’name’: clazz.name,
          ’dartName’: sdkUtils.typeName(clazz)
        };

      // TODO(grouma) - we display all inherited methods since we don’t provide
      // the superClass information. This is technically not correct.
      var proto = clazz.prototype;
      var methodNames = [];
      for (; proto != null; proto = Object.getPrototypeOf(proto)) {
        var methods = Object.getOwnPropertyNames(proto);
        for (var i = 0; i < methods.length; i++) {
          if (methodNames.indexOf(methods[i]) == -1
              && methods[i] != ’constructor’) {
              methodNames.push(methods[i]);
          }
        }
        if (proto.constructor.name == ’Object’) break;
      }

      descriptor[’methods’] = {};
      for (var name of methodNames) {
        descriptor[’methods’][name] = {
          // TODO(jakemac): how can we get actual const info?
          "isConst": false,
          "isStatic": false,
        }
      }

      var fields = sdkUtils.getFields(clazz);
      var fieldNames = fields ? Object.keys(fields) : [];
      descriptor[’fields’] = {};
      for (var name of fieldNames) {
        var field = fields[name];
        var libraryUri = Object.getOwnPropertySymbols(fields[name]["type"])
        .find(x => x.description == "libraryUri");
        descriptor[’fields’][name] = {
          // TODO(jakemac): how can we get actual const info?
          "isConst": false,
          "isFinal": field.isFinal,
          "isStatic": false,
          "classRefName": fields[name]["type"]["name"],
          "classRefDartName": sdkUtils.typeName(fields[name]["type"]),
          "classRefLibraryId" : field["type"][libraryUri],
        }
      }

      // TODO(elliette): The following static member information is minimal and 
      // should be replaced once DDC provides full symbol information (see 
      // https://github.com/dart-lang/sdk/issues/40273):

      descriptor[’staticFields’] = {};
      var staticFieldNames = sdkUtils.getStaticFields(clazz) ?? [];
      for (const name of staticFieldNames) {
        descriptor[’staticFields’][name] = {
          "isStatic": true,
          // DDC only provides names of static members, we set isConst/isFinal 
          // to false even though they could be true.
          "isConst": false,
          "isFinal": false,
        }
      }

      descriptor[’staticMethods’] = {};
      var staticMethodNames = sdkUtils.getStaticMethods(clazz) ?? [];
      for (var name of staticMethodNames) {
        descriptor[’methods’][name] = {
          // DDC only provides names of static members, we set isConst
          // to false even though it could be true.
          "isConst": false,
          "isStatic": true,
        } 
      }

      return descriptor;
    })()
    ‘

#0      ClassHelper._constructClass (package:dwds/src/debugging/classes.dart:178:7)
<asynchronous suspension>
#1      StackZoneSpecification._registerUnaryCallback.<anonymous closure> (package:stack_trace/src/stack_zone_specification.dart:125:47)
<asynchronous suspension>

Then , @DanTup replied


I do see the same issue in VS Code:

image

[13:26:26] [VmService] [Info] [Flutter (Chrome)] ==> {"id":"25","jsonrpc":"2.0","method":"getObject","params":{"isolateId":"1","objectId":"classes|package:repro_lsp/bloc.dart|_$36_MyStateWithValue"}}

[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <== [+25202 ms] AppInspector: getObject classes|package:repro_lsp/bloc.dart|_$36_MyStateWithValue failedError: Unexpected error from chrome devtools:
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==             text: Uncaught
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==             exception:
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==               preview: null
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==               description: TypeError: Cannot read properties of undefined (reading 'name')
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at <anonymous>:9:25
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at <anonymous>:83:7
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at http://localhost:53618/packages/repro_lsp/main.dart.lib.js:454:810
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at bloc$._$_MyStateWithValue.new.when (http://localhost:53618/packages/repro_lsp/bloc.dart.lib.js:560:14)
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at BlocBuilder.new.<anonymous> (http://localhost:53618/packages/repro_lsp/main.dart.lib.js:454:642)
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at BlocBuilder.new.build (http://localhost:53618/packages/flutter_bloc/src/multi_bloc_listener.dart.lib.js:807:21)
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at _BlocBuilderBaseState.new.build (http://localhost:53618/packages/flutter_bloc/src/multi_bloc_listener.dart.lib.js:896:288)
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at framework.StatefulElement.new.build (http://localhost:53618/packages/flutter/src/widgets/title.dart.lib.js:67601:25)
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at framework.StatefulElement.new.performRebuild (http://localhost:53618/packages/flutter/src/widgets/title.dart.lib.js:21885:22)
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at framework.StatefulElement.new.performRebuild (http://localhost:53618/packages/flutter/src/widgets/title.dart.lib.js:67637:13)
[13:26:26] [FlutterRun] [Info] [Flutter (Chrome)] <==                 at framework.StatefulElement.new.rebuild (http://localhost:53618/packages/flutter/src/widgets/title.dart.lib.js:17571:12)

The line/col in the errr at the top of the stack looks like this:

image

Unfortunately I'm not sure how to attach a JS debugger to the expressions being evaluated by DWDS here. My feeling is that there's a DWDS bug here - even if the trigger is an exception in user code, it doesn't seem like it should be failing in this way.

Given you have a good repro, I would suggest filing an issue at https://github.com/dart-lang/webdev with the repro steps above (you can link back here for some additional context, and feel free to CC me in case I can add any value).


@Pacane
Copy link
Author

Pacane commented Dec 8, 2022

cc: @kevmoo @DanTup

@DanTup feel free to add any details I could have missed. thanks!

@kevmoo
Copy link
Member

kevmoo commented Dec 8, 2022

@jacob314 – can you help route? I don't think this has to do w/ pkg:webdev

@DanTup
Copy link
Contributor

DanTup commented Dec 8, 2022

The thrown error starts with "Unexpected error from chrome devtools" so my feeling was that this might be something not being handled correctly in DWDS (although I also couldn't find the code trying to read name so I'm not sure if it's triggered by user code, or something in the generated JS).

Usually when an expression evaluation fails, there's an exception returned from the evaluateInFrame call that we display in the watch window. That is happening here, but the error message doesn't look like something the user would understand (if it is being caused by their code), but it's also being written to the flutter run output, so it fills the debug console (this is unexpected, the error should be confined to the response to the evaluateInFrame request over the VM Service).

dap-request: getObject: (-32603) getObject: Unexpected error from chrome devtools:
text: Uncaught
exception:
  description: TypeError: Cannot read properties of undefined (reading ’name’)
    at <anonymous>:9:25
    at <anonymous>:83:7
    at http://localhost:38069/packages/repro_lsp/main.dart.lib.js:442:810
    at bloc$._$_MyStateWithValue.new.when (http://localhost:38069/packages/repro_lsp/bloc.dart.lib.js:556:14)

@elliette
Copy link
Contributor

elliette commented Dec 12, 2022

I'm able to reproduce this when debugging from VSCode, but not when debugging with Flutter DevTools (expanding _state does not show an error), which makes me think there is some difference in how they are calling this.

It looks like the error is coming from here:

_logger.fine('getObject $objectId failed', e, s);
. The objectId seems strange to me:

classes|package:repro_lsp/bloc.dart|_$36_MyStateWithValue

@DanTup, is there a way to specify the Flutter SDK in VSCode to be my local Flutter to help debug? Thanks!

@DanTup
Copy link
Contributor

DanTup commented Dec 12, 2022

@elliette you can use the dart.flutterSdkPath setting to specify a Flutter SDK, although I'm not sure if that's exactly what you mean since you probably only have one Flutter SDK checked out anyway? If you do have multiple, you can also set dart.flutterSdkPaths (note the plural) to let you easily switch between them from the status bar (it's an array of paths, although if you have multiple SDKs inside the same parent folder, you can just list the parent folder here as we search 1 level deep).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants