Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

ZoneDelegate.hasTask (zone.js:418) ate my exception #706

Closed
cenkentimist opened this issue Mar 30, 2017 · 12 comments · Fixed by #709
Closed

ZoneDelegate.hasTask (zone.js:418) ate my exception #706

cenkentimist opened this issue Mar 30, 2017 · 12 comments · Fixed by #709

Comments

@cenkentimist
Copy link

cenkentimist commented Mar 30, 2017

zone.js seems to have managed to eaten an exception that I needed. Don't know if this is actually zone.js's fault or something further down the stack is suppose to handle notifying of the exception but I figured you could probably tell me. Stack trace of exception follows

(anonymous) (display.component.ngfactory.ts:486)
debugUpdateRenderer (core.es5.js:12651)
checkAndUpdateView (core.es5.js:12030)
callViewAction (core.es5.js:12340)
execComponentViewsAction (core.es5.js:12286)
checkAndUpdateView (core.es5.js:12031)
callViewAction (core.es5.js:12340)
execEmbeddedViewsAction (core.es5.js:12312)
checkAndUpdateView (core.es5.js:12026)
callViewAction (core.es5.js:12340)
execEmbeddedViewsAction (core.es5.js:12312)
checkAndUpdateView (core.es5.js:12026)
callViewAction (core.es5.js:12340)
execComponentViewsAction (core.es5.js:12286)
checkAndUpdateView (core.es5.js:12031)
callViewAction (core.es5.js:12340)
execEmbeddedViewsAction (core.es5.js:12312)
checkAndUpdateView (core.es5.js:12026)
callViewAction (core.es5.js:12340)
execEmbeddedViewsAction (core.es5.js:12312)
checkAndUpdateView (core.es5.js:12026)
callViewAction (core.es5.js:12340)
execComponentViewsAction (core.es5.js:12286)
checkAndUpdateView (core.es5.js:12031)
callViewAction (core.es5.js:12340)
execEmbeddedViewsAction (core.es5.js:12312)
checkAndUpdateView (core.es5.js:12026)
callViewAction (core.es5.js:12340)
execComponentViewsAction (core.es5.js:12286)
checkAndUpdateView (core.es5.js:12031)
callWithDebugContext (core.es5.js:13013)
debugCheckAndUpdateView (core.es5.js:12553)
ViewRef_.detectChanges (core.es5.js:10122)
(anonymous) (core.es5.js:5052)
ApplicationRef_.tick (core.es5.js:5052)
(anonymous) (core.es5.js:4932)
ZoneDelegate.invoke (zone.js:365)
onInvoke (core.es5.js:4125)
ZoneDelegate.invoke (zone.js:364)
Zone.run (zone.js:125)
NgZone.run (core.es5.js:3994)
next (core.es5.js:4932)
schedulerFn (core.es5.js:3828)
SafeSubscriber.__tryOrUnsub (Subscriber.js:234)
SafeSubscriber.next (Subscriber.js:183)
Subscriber._next (Subscriber.js:125)
Subscriber.next (Subscriber.js:89)
Subject.next (Subject.js:55)
EventEmitter.emit (core.es5.js:3814)
NgZone.checkStable (core.es5.js:4090)
NgZone.setHasMicrotask (core.es5.js:4174)
onHasTask (core.es5.js:4137)
ZoneDelegate.hasTask (zone.js:418) //caught here
ZoneDelegate._updateTaskCount (zone.js:438)
Zone._updateTaskCount (zone.js:262)
Zone.runTask (zone.js:182)
drainMicroTaskQueue (zone.js:593)
ZoneTask.invoke (zone.js:464)

edit: (attempted) clarification
An exception's information is lost, specifically here's what happened.

  1. an angular template references invalid_variable.foo
  2. this throws an error ReferenceError: invalid_variable is not defined or possibly Cannot read property 'foo' of undefined (the exact error isn't important)
  3. the exception propagates up the stack (it's an exception after all) At several points it's caught enhanced with more information and thrown again, no surprises there.
  4. ZoneDelegate.hasTask (zone.js:418) is wraped in a try catch where the catch does nothing. This catches the exception and stops handling it
    result: angular template stops rendering and it's very difficult to debug, as no stack trace or other error information are logged to the console. The error is currently silently caught and discarded.

desired behavior
The exception is at some point shown to me either by being logged at some point, or being thrown and not caught at some point.

@JiaLiPassion
Copy link
Collaborator

@cenkentimist , could you explain more about it? what kind of information was eaten?

@cenkentimist
Copy link
Author

cenkentimist commented Mar 31, 2017

a duplicate of this comment was added to the opening post after the stack trace:
@JiaLiPassion
An exception's information is lost, specifically here's what happened.

  1. an angular template references invalid_variable.foo
  2. this throws an error ReferenceError: invalid_variable is not defined or possibly Cannot read property 'foo' of undefined (the exact error isn't important)
  3. the exception propagates up the stack (it's an exception after all) At several points it's caught enhanced with more information and thrown again, no surprises there.
  4. ZoneDelegate.hasTask (zone.js:418) is wraped in a try catch where the catch does nothing. This catches the exception and stops handling it
    result: angular template stops rendering and it's very difficult to debug, as no stack trace or other error information are logged to the console. The error is currently silently caught and discarded.

desired behavior
The exception is at some point shown to me either by being logged at some point, or being thrown and not caught at some point.

@JiaLiPassion
Copy link
Collaborator

@cenkentimist, so you mean there is an exception thrown in ZoneDelegate.hasTask?
can you post a debug screenshot or a reproduce repository? thanks.

@cenkentimist
Copy link
Author

cenkentimist commented Mar 31, 2017

@JiaLiPassion
No, my problem is that ZoneDelegate.hasTask is catching an exception. I want it to throw an exception so I can debug what's going wrong in my code. There is an exception that is thrown in my code, that is caught and silenced by code in ZoneDelegate.hasTask. This is bad because it stops me from knowing what went wrong in my code.
I read the comments in the zone.js code that is catching the exception and it seems like it must not throw an exception there but this does not prevent logging or throwing the exception later. However I do not understand zone.js so I am hesitant to recommend, where the exception should be logged or thrown. I would also except a good explanation for why zone.js shouldn't do this.

@JiaLiPassion
Copy link
Collaborator

@cenkentimist , the code is here,

ZoneDelegate.prototype.hasTask = function (targetZone, isEmpty) {
            // hasTask should not throw error so other ZoneDelegate
            // can still trigger hasTask callback
            try {
                return this._hasTaskZS &&
                    this._hasTaskZS.onHasTask(this._hasTaskDlgt, this._hasTaskCurrZone, targetZone, isEmpty);
            }
            catch (err) {
            }
        };

you mean that this._hasTaskZS.onHasTask throw error and you want to debug it?

@cenkentimist
Copy link
Author

cenkentimist commented Mar 31, 2017

@JiaLiPassion
No. zone.js is not throwing an exception.
I am throwing an exception because my code is bad.
When my code is bad I need to figure out why and debug it
Exceptions if not caught have nice things called stack traces in it.
Exceptions also have nice messages.
Stack traces help me understand why my code is bad.
zone.js is catching the exception and making it so I can not see it.
Now when my code does a bad thing I can not see a stack trace or a message.
Seeing no stack trace or message makes me sad.
I need zone.js' help to make me happy
It would make me happy if I could see the stack trace

Here are some things that would make me happy.
If zone.js showed me the exception.
It could log it using a something like console.log(exception my bad code throws).

zone.js could also throw the exception.
It might be bad if zone.js throws the exception. It seems like it might be doing something important.
If the exception stops zone.js from doing an important thing that would be bad.
zone.js could store the exception. When zone.js gets done doing the important thing it could throw the exception.

@JiaLiPassion
Copy link
Collaborator

@cenkentimist , yeah, I understand your requirement, but I don't understand is that why exception happen in that place. I know the exception is happened because the bad code, and you want to where the bad code is, what I mean is I don't think even the template error or other bad code, basically no exception should throw from that location.

So I want to know the exact error of your case, thanks.

@cenkentimist
Copy link
Author

@JiaLiPassion ok I'll try to come up with a minimal test case

@cenkentimist
Copy link
Author

@JiaLiPassion Thanks for your patience here's a minimal case
https://github.com/cenkentimist/AngularSupressedException

@JiaLiPassion
Copy link
Collaborator

JiaLiPassion commented Mar 31, 2017

@cenkentimist , thanks , I can reproduce , I will debug it.

@cenkentimist
Copy link
Author

git clone https://github.com/cenkentimist/AngularSupressedException.git
cd AngularSupressedException
npm install
npm start
open http://localhost:4200/ in chrome

open the developer console (view>developer>developertools)
in the sources tab navigate to (ng:// > AppModule > SubitemComponent.html)
set a brake point by clicking the 1 line number
refresh the page (view >reload this page)
when execution stops on the breakpoint check the box ("Pause on caught exceptions")
click the arrow button above to resume execution
you should now be paused on the exception TypeError: Cannot read property 'invalid_attr' of undefined
now you can use the debugger to see the exception be propagated up the stack and caught by ZoneDelegate.hasTask (zone.js:418)

@Deltatiger
Copy link

Deltatiger commented Apr 6, 2017

Something similar happened for me.
I reverted to version 0.8.0 of zone.js because anything above breakes the exception system.

More Info : angular/angular#15791

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

Successfully merging a pull request may close this issue.

3 participants