Skip to content

js-interop: Dart exceptions and errors thrown through js-interop are not un-jsified. #36363

Open
@kealjones-wk

Description

@kealjones-wk

Setup:

  • Dart SDK Version: 2.2.0
  • OS: macOS 10.14.2
  • Browser: Chrome 73.0.3683.86
  • pkg/js version: "0.6.1+1"

Does it happen in Dartium or when compiled to JavaScript?: Both
Describe the issue you're seeing:
When a dart exception is thrown and is caught by javascript if the error is then passed back into a dart callback the error comes through as a JsObject in dart2js and as a NativeJavaScriptObject in DDC. Is this an issue or is this expected behavior?

Workarounds:
We have found ways around this, that i wanted ask about and see if they are safe ways to go about re-dartifying thrown exceptions or if these solutions were potentially problematic:
In these examples _JoesException is a dart class that extends from Exception And just adds some additional fields.

in dart2js:

_JoesException joesError = js_util.getProperty(error, 'dartException');

in ddc:

_JoesException joesError = _getSymbolProperty(error, 'Symbol(_thrownValue)');

The js side function accessed in dart using package:js/js.dart in example two is:

function _getSymbolProperty(obj, key){
  var sym = Object.getOwnPropertySymbols(obj).find(function(s) {
    return String(s) === key;
  });
  return obj[sym];
}

Failing code:
It is not really failing, this is where the issue was observed. We are seeing it in componentDidCatch and getDerivedStateFromError.
PR: Workiva/react-dart#175
You can test using this file: https://github.com/cleandart/react-dart/blob/785f74ca68c8c4ecf3c051459d6357d29813f636/example/test/react_test_components.dart
Run pub run build_runner serve example [-r] and navigate to http://localhost:8080/test/react_test.html
In _Component2ErrorTestComponent you can update the componentDidCatch method to use the info argument or getDerivedStateFromError method to use the error argument.

Any insight or better more correct solutions are totally welcome! Also if you need more detail about anything let me know I am happy to share.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)web-dart2jsweb-js-interopIssues that impact all js interopweb-triage-0repro is available

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions