Title: Thrown error no longer propagates (caught in the try-catch inside invokeTask in patchEventTarget in events.ts) · Issue #41867 · angular/angular · GitHub
Open Graph Title: Thrown error no longer propagates (caught in the try-catch inside invokeTask in patchEventTarget in events.ts) · Issue #41867 · angular/angular
X Title: Thrown error no longer propagates (caught in the try-catch inside invokeTask in patchEventTarget in events.ts) · Issue #41867 · angular/angular
Description: I have an application that performs validation on mouse events. If validation fails, it throws an Error. We catch thrown errors in our application by doing: window.addEventListener('error', (event) => { handleUncaughtError(event, logger)...
Open Graph Description: I have an application that performs validation on mouse events. If validation fails, it throws an Error. We catch thrown errors in our application by doing: window.addEventListener('error', (event)...
X Description: I have an application that performs validation on mouse events. If validation fails, it throws an Error. We catch thrown errors in our application by doing: window.addEventListener('error',...
Opengraph URL: https://github.com/angular/angular/issues/41867
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Thrown error no longer propagates (caught in the try-catch inside invokeTask in patchEventTarget in events.ts)","articleBody":"I have an application that performs validation on mouse events. If validation fails, it throws an Error. We catch thrown errors in our application by doing:\r\n`window.addEventListener('error', (event) => {\r\n handleUncaughtError(event, logger);\r\n });`\r\n\r\nThis worked fine: task.invoke() in the below code would call into our code, which would throw an error and would be caught by the above listener.\r\n```\r\nvar invokeTask = function (task, target, event) {\r\n // for better performance, check isRemoved which is set\r\n // by removeEventListener\r\n if (task.isRemoved) {\r\n return;\r\n }\r\n var delegate = task.callback;\r\n if (typeof delegate === 'object' && delegate.handleEvent) {\r\n // create the bind version of handleEvent when invoke\r\n task.callback = function (event) { return delegate.handleEvent(event); };\r\n task.originalDelegate = delegate;\r\n }\r\n // invoke static task.invoke\r\n task.invoke(task, target, [event]);\r\n var options = task.options;\r\n if (options && typeof options === 'object' && options.once) {\r\n // if options.once is true, after invoke once remove listener here\r\n // only browser need to do this, nodejs eventEmitter will cal removeListener\r\n // inside EventEmitter.once\r\n var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback;\r\n target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options);\r\n }\r\n };\r\n```\r\n\r\nHowever, now the callsite for task.invoke() looks like:\r\n```\r\nvar invokeTask = function (task, target, event) {\r\n // for better performance, check isRemoved which is set\r\n // by removeEventListener\r\n if (task.isRemoved) {\r\n return;\r\n }\r\n var delegate = task.callback;\r\n if (typeof delegate === 'object' && delegate.handleEvent) {\r\n // create the bind version of handleEvent when invoke\r\n task.callback = function (event) { return delegate.handleEvent(event); };\r\n task.originalDelegate = delegate;\r\n }\r\n // invoke static task.invoke\r\n // need to try/catch error here, otherwise, the error in one event listener\r\n // will break the executions of the other event listeners. Also error will\r\n // not remove the event listener when `once` options is true.\r\n var error;\r\n try {\r\n task.invoke(task, target, [event]);\r\n }\r\n catch (err) {\r\n error = err;\r\n }\r\n var options = task.options;\r\n if (options && typeof options === 'object' && options.once) {\r\n // if options.once is true, after invoke once remove listener here\r\n // only browser need to do this, nodejs eventEmitter will cal removeListener\r\n // inside EventEmitter.once\r\n var delegate_1 = task.originalDelegate ? task.originalDelegate : task.callback;\r\n target[REMOVE_EVENT_LISTENER].call(target, event.type, delegate_1, options);\r\n }\r\n return error;\r\n };\r\n```\r\n\r\nand it seems like the error is ignored in globalCallback()\r\n\r\n```\r\nfunction globalCallback(context, event, isCapture) {\r\n // https://github.com/angular/zone.js/issues/911, in IE, sometimes\r\n // event will be undefined, so we need to use window.event\r\n event = event || _global.event;\r\n if (!event) {\r\n return;\r\n }\r\n // event.target is needed for Samsung TV and SourceBuffer\r\n // || global is needed https://github.com/angular/zone.js/issues/190\r\n var target = context || event.target || _global;\r\n var tasks = target[exports.zoneSymbolEventNames[event.type][isCapture ? utils_1.TRUE_STR : utils_1.FALSE_STR]];\r\n if (tasks) {\r\n // invoke all tasks which attached to current target with given event.type and capture = false\r\n // for performance concern, if task.length === 1, just invoke\r\n if (tasks.length === 1) {\r\n invokeTask(tasks[0], target, event);\r\n }\r\n else {\r\n // https://github.com/angular/zone.js/issues/836\r\n // copy the tasks array before invoke, to avoid\r\n // the callback will remove itself or other listener\r\n var copyTasks = tasks.slice();\r\n var errors = [];\r\n for (var i = 0; i \u003c copyTasks.length; i++) {\r\n if (event && event[IMMEDIATE_PROPAGATION_SYMBOL] === true) {\r\n break;\r\n }\r\n var err = invokeTask(copyTasks[i], target, event);\r\n err && errors.push(err);\r\n }\r\n var _loop_1 = function (i) {\r\n var err = errors[i];\r\n api.nativeScheduleMicroTask(function () {\r\n throw err;\r\n });\r\n };\r\n for (var i = 0; i \u003c errors.length; i++) {\r\n _loop_1(i);\r\n }\r\n }\r\n }\r\n }\r\n```\r\n\r\nIIUC, this is caused by the fix for this https://github.com/angular/angular/pull/41562#issuecomment-822696973\r\n\r\nThis is a regression (I tested with a version from 3 weeks ago and it worked as expected).\r\n\r\nCan we ensure that all caught errors are rethrown? Or whatever is the Angular way to undo this regression.","author":{"url":"https://github.com/br-star","@type":"Person","name":"br-star"},"datePublished":"2021-04-28T23:00:22Z","url":"https://github.com/angular/angular/issues/41867"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:09e8cbb1-10a2-13fd-c3ed-6e904d4cc503 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C2B0:1AE20C:C6F336:FCFEB6:6B00FCC2 |
| html-safe-nonce | 554b6851f732f3397747062458b1452669df12b46d6f0882041bccb2b0cf86b1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkIwOjFBRTIwQzpDNkYzMzY6RkNGRUI2OjZCMDBGQ0MyIiwidmlzaXRvcl9pZCI6IjYzNDc4ODMxODc2NDA3OTQzMDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 52159cfed807ab340959e6b41e388416e3a2ae58544bbfdc579b6c104709632b |
| hovercard-subject-tag | issue:870468186 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular/41867/issue_layout |
| twitter:image | https://opengraph.githubassets.com/945adc58e717378a08931706660e828c63ea653c09b2a86a237f44301695b2a3/angular/angular/issues/41867 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/945adc58e717378a08931706660e828c63ea653c09b2a86a237f44301695b2a3/angular/angular/issues/41867 |
| og:image:alt | I have an application that performs validation on mouse events. If validation fails, it throws an Error. We catch thrown errors in our application by doing: window.addEventListener('error', (event)... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | br-star |
| hostname | github.com |
| expected-hostname | github.com |
| None | e208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular git https://github.com/angular/angular.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 24195339 |
| octolytics-dimension-repository_nwo | angular/angular |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 24195339 |
| octolytics-dimension-repository_network_root_nwo | angular/angular |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7dafd017fb7809a839c443dba08622af38e63c09 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width