Reputation: 2576
I am getting the following error in chrome, and have no idea where it is coming from:
The only thing that is really telling about anything is that I recently refactored about 10,000 lines of code and this error appeared some time in the middle of that. This is angular. I know how to catch promises, in angular. I am using an error handler to try and catch it but that did not work I also tried:
window.addEventListener('unhandledrejection', function (promiseRejectionEvent) {
console.log(promiseRejectionEvent);
console.log('here!!!!!')
});
window.onerror = function (promiseRejectionEvent) {
console.log(promiseRejectionEvent);
console.log('AHHHH')
};
Neither one of those caught the error. I have no idea where this error is coming from. It will appear every time I reload the page.
For the truly curious I have tried going to the link in chrome and it points to ... so not really helpful.
This error does not happen in firefox.
Upvotes: 6
Views: 15513
Reputation: 563
As other responses suggest, try adding a breakpoint to where the stacktrace from the console points to. Then go up the call stack, and you probably find where a Promise is rejected in your code.
On my side, it was because we used Promise.reject()
in a function without wrapping the call within a try/catch
block. It worked fine until we added await
to the function call, which triggered the unhandled promise exception and bubbled up to zone.js
.
Upvotes: 0
Reputation: 2576
Try running your code in Incognito.
I found the answer and it was less than satisfactory. It was a Microsoft Office extension that was somehow injecting something that was getting half caught by zone.js, but kinda not. I have NO idea how that happened.
Finding the bug:
If you make chrome pause on exceptions then it WILL stop on this error. The error was in a content.js file which is not in my project so I said "hmm...". I then went to the location of the file by right clicking in the sources tab, and found that the error was in the Office extension. So if you get this Uncaught (in promise) undefined
it is because somehow zone.js error handling is catching it. I have NO idea how, but try running your code in Incognito.
Upvotes: 1
Reputation: 5181
The error tells you that there is an error but you don´t catch it. Most probably you can check the responsible router for the route /app/outbound/cell-dial
or any route guard function that relates to that.
For more information routing, but especially about router guards: https://angular.io/guide/router
Other options would be:
// Delete
rm -rf node_modules/
npm install
Check your repo diff from your last commit/merge/pull step by step
Check your versions, because there is a possibility that you have different dependency versions than before that wasn't setup properly.
In general this is how you can catch it (that you probably already know, but I still mention it just in case):
getAllPosts().then(response => {
console.log(response);
}).catch(e => {
console.log(e);
});
More information: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
Or with async/await:
//some async function
try {
let response = await getAllPosts();
} catch(e) {
console.log(e);
}
Upvotes: 0
Reputation: 5656
The message Uncaught (in promise)
is part of zone.js:
https://github.com/angular/zone.js/blob/master/lib/common/promise.ts#L194
Using chrome dev tools, either search all files (cmd/ctrl+shift+f) for this text or jump (cmd/ctrl + p) to zone.js and find 'Uncaught'. Put a breakpoint, reload page and inspect callstack once your breakpoint is hit.
Hope that'll point you in the right direction.
Upvotes: 7