Daniel Danilatos
2016-11-09 01:11:24 UTC
Hi,
For $reasons, I have a global error handler registered via javascript
(window.onerror), to deal with uncaught exceptions by sending them to the
server for deobfuscation using sourcemaps.
It's working fine for most errors, however, we're getting some stack traces
that deobfuscate to the following:
(unknown): Instance of 'oX'
1
File "../packages/$sdk/lib/_internal/js_runtime/lib/js_helper.dart" line
1729 col 17 in Object.t
2
File "../packages/$sdk/lib/async/zone.dart" line 938 col 20 in acL.$0
3
File "../packages/$sdk/lib/async/schedule_microtask.dart" line 41 col 6 in
Object.acJ
4
File "../packages/$sdk/lib/async/schedule_microtask.dart" line 50 col 5 in
a2V.dart.akM
5
File "../packages/$sdk/lib/_internal/js_runtime/lib/async_patch.dart" line
54 col 9 in a9v.dart.a9v.$1
6
File "../packages/$sdk/lib/_internal/js_runtime/lib/js_helper.dart" line
2409 col 48 in ah6.$0
7
File "../packages/$sdk/lib/_internal/js_runtime/lib/isolate_helper.dart"
line 462 col 16 in pS.kr
8
File "../packages/$sdk/lib/_internal/js_runtime/lib/isolate_helper.dart"
line 54 col 16 in Object.jO
9
File "../packages/$sdk/lib/_internal/js_runtime/lib/js_helper.dart" line
2409 col 14 in dart.ah4
10
File "../packages/$sdk/lib/_internal/js_runtime/lib/js_helper.dart" line
2429 col 14 in MutationObserver.<anonymous>
I.e. uninformative (nothing in the stack trace comes from our application
code). While it's probably some unhandled async code error, I'd expect to
at least see one stack trace line from inside our application code.
Digging around, it looks like dart js runtime likes to wrap the exceptions
for some reason If I do the following hack, then I can get the actual
stack trace and error message for exceptions thrown in both regular code
and async code:
window.onerror = function (message, filename, lineno, colno, error) {
if (ct[k] instanceof Object && 'stack' in ct[k]) {
scenarios, nor be stable across new releases of the dart sdk. Looking at
the implementation of "unwrapException" in the dart js runtime, there seems
to be a lot more work required to do it "properly" (though it's unclear how
much matters for just getting a stack trace).
Is there a clean way to unwrap the exception from javascript? (even
calling into dart code would be fine)
Taking a step back, what is the cleanest way to install a global error
handler that can get the useful stacktrace from exceptions thrown in either
normal js or dart js code, whether sync or async, etc?
Thanks
Dan
For $reasons, I have a global error handler registered via javascript
(window.onerror), to deal with uncaught exceptions by sending them to the
server for deobfuscation using sourcemaps.
It's working fine for most errors, however, we're getting some stack traces
that deobfuscate to the following:
(unknown): Instance of 'oX'
1
File "../packages/$sdk/lib/_internal/js_runtime/lib/js_helper.dart" line
1729 col 17 in Object.t
2
File "../packages/$sdk/lib/async/zone.dart" line 938 col 20 in acL.$0
3
File "../packages/$sdk/lib/async/schedule_microtask.dart" line 41 col 6 in
Object.acJ
4
File "../packages/$sdk/lib/async/schedule_microtask.dart" line 50 col 5 in
a2V.dart.akM
5
File "../packages/$sdk/lib/_internal/js_runtime/lib/async_patch.dart" line
54 col 9 in a9v.dart.a9v.$1
6
File "../packages/$sdk/lib/_internal/js_runtime/lib/js_helper.dart" line
2409 col 48 in ah6.$0
7
File "../packages/$sdk/lib/_internal/js_runtime/lib/isolate_helper.dart"
line 462 col 16 in pS.kr
8
File "../packages/$sdk/lib/_internal/js_runtime/lib/isolate_helper.dart"
line 54 col 16 in Object.jO
9
File "../packages/$sdk/lib/_internal/js_runtime/lib/js_helper.dart" line
2409 col 14 in dart.ah4
10
File "../packages/$sdk/lib/_internal/js_runtime/lib/js_helper.dart" line
2429 col 14 in MutationObserver.<anonymous>
I.e. uninformative (nothing in the stack trace comes from our application
code). While it's probably some unhandled async code error, I'd expect to
at least see one stack trace line from inside our application code.
Digging around, it looks like dart js runtime likes to wrap the exceptions
for some reason If I do the following hack, then I can get the actual
stack trace and error message for exceptions thrown in both regular code
and async code:
window.onerror = function (message, filename, lineno, colno, error) {
console.log(window.lastErr = error);
var stack;
if (error.$cachedTrace) {
// new Future.microtask(() => throw new Exception("Test Async
Exception"));
var ct = error.$cachedTrace;var stack;
if (error.$cachedTrace) {
// new Future.microtask(() => throw new Exception("Test Async
Exception"));
for (var k in ct) {
// actual _exception property name is minifiedif (ct[k] instanceof Object && 'stack' in ct[k]) {
stack = ct[k].stack;
}
}
} else {
stack = error.stack;
}
console.log("Stack: ", stack);
}
It's quite brittle though, and I'm not sure if it will work for all}
}
} else {
stack = error.stack;
}
console.log("Stack: ", stack);
}
scenarios, nor be stable across new releases of the dart sdk. Looking at
the implementation of "unwrapException" in the dart js runtime, there seems
to be a lot more work required to do it "properly" (though it's unclear how
much matters for just getting a stack trace).
Is there a clean way to unwrap the exception from javascript? (even
calling into dart code would be fine)
Taking a step back, what is the cleanest way to install a global error
handler that can get the useful stacktrace from exceptions thrown in either
normal js or dart js code, whether sync or async, etc?
Thanks
Dan
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+***@dartlang.org.