From fd3ca8a2ef298544ddeb04ca532ed73d7f94e1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= Date: Mon, 10 Mar 2025 13:39:14 +0100 Subject: [PATCH 1/3] Fix for exception-unhandled "forked" Promise chain See https://github.com/django-commons/django-debug-toolbar/pull/2100 --- .../static/debug_toolbar/js/toolbar.js | 18 +++++++++++++----- docs/changes.rst | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index 329bce669..b6bec5202 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -321,16 +321,24 @@ const djdt = { const origFetch = window.fetch; window.fetch = function (...args) { + // Heads up! Before modifying this code, please be aware of the + // possible unhandled errors that might arise from changing this. + // For details, see + // https://github.com/django-commons/django-debug-toolbar/pull/2100 const promise = origFetch.apply(this, args); - promise.then((response) => { + return promise.then((response) => { if (response.headers.get("djdt-store-id") !== null) { - handleAjaxResponse(response.headers.get("djdt-store-id")); + try { + handleAjaxResponse( + response.headers.get("djdt-store-id")); + } catch (err) { + throw new Error( + `A(n) "${err.name}" happened within ` + `django-debug-toolbar: ${err.message}`) + } } - // Don't resolve the response via .json(). Instead - // continue to return it to allow the caller to consume as needed. return response; }); - return promise; }; }, cookie: { diff --git a/docs/changes.rst b/docs/changes.rst index 608843e0f..f11d4889e 100644 --- a/docs/changes.rst +++ b/docs/changes.rst @@ -15,6 +15,7 @@ Pending * Added a Makefile target (``make help``) to get a quick overview of each target. * Avoided reinitializing the staticfiles storage during instrumentation. +* Fix for exception-unhandled "forked" Promise chain in rebound window.fetch 5.0.1 (2025-01-13) ------------------ From 40ad59170e2b8878f3badccc24ba7da8b5681d35 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Mar 2025 12:43:52 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- debug_toolbar/static/debug_toolbar/js/toolbar.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index b6bec5202..cda34df30 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -330,11 +330,12 @@ const djdt = { if (response.headers.get("djdt-store-id") !== null) { try { handleAjaxResponse( - response.headers.get("djdt-store-id")); + response.headers.get("djdt-store-id") + ); } catch (err) { throw new Error( - `A(n) "${err.name}" happened within ` - `django-debug-toolbar: ${err.message}`) + `A(n) "${err.name}" happened within ``django-debug-toolbar: ${err.message}` + ); } } return response; From ca2d9c2b3a4b0047b8030397e8554bd4fbf5a074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20K=C3=A1rolyi?= <987055+karolyi@users.noreply.github.com> Date: Mon, 10 Mar 2025 13:05:46 +0000 Subject: [PATCH 3/3] Update debug_toolbar/static/debug_toolbar/js/toolbar.js Co-authored-by: Tim Schilling --- debug_toolbar/static/debug_toolbar/js/toolbar.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debug_toolbar/static/debug_toolbar/js/toolbar.js b/debug_toolbar/static/debug_toolbar/js/toolbar.js index cda34df30..077bc930a 100644 --- a/debug_toolbar/static/debug_toolbar/js/toolbar.js +++ b/debug_toolbar/static/debug_toolbar/js/toolbar.js @@ -334,7 +334,7 @@ const djdt = { ); } catch (err) { throw new Error( - `A(n) "${err.name}" happened within ``django-debug-toolbar: ${err.message}` + `"${err.name}" occurred within django-debug-toolbar: ${err.message}` ); } }