Skip to content

Fix "Cannot read property 'name' of undefined" when Promise is rejected without a reason#129

Merged
niemyjski merged 2 commits intomasterfrom
copilot/fix-unhandled-rejection-error
Feb 27, 2026
Merged

Fix "Cannot read property 'name' of undefined" when Promise is rejected without a reason#129
niemyjski merged 2 commits intomasterfrom
copilot/fix-unhandled-rejection-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 25, 2026

When Promise.reject() is called without an argument, onunhandledrejection fires with e.reason as undefined/null. Passing this to computeStackTrace causes a crash in the final fallback return where ex.name and ex.message are accessed unconditionally.

Changes

  • tracekit.js: Guard property access in the computeStackTrace fallback return using short-circuit evaluation:

    // Before
    return { 'name': ex.name, 'message': ex.message, 'mode': 'failed' };
    
    // After
    return { 'name': ex && ex.name, 'message': ex && ex.message, 'mode': 'failed' };
  • spec/tracekit-spec.js: Add tests covering computeStackTrace(undefined) and computeStackTrace(null) to prevent regression.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • accounts.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=3926 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-79623365 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7964489220704497771,8279194133401378956,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --user-data-dir=/tmp/karma-79623365 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu http://localhost:9876/?id=79623365 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222 (dns block)
  • clients2.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=3926 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-79623365 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7964489220704497771,8279194133401378956,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --user-data-dir=/tmp/karma-79623365 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu http://localhost:9876/?id=79623365 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222 (dns block)
  • clientservices.googleapis.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=3926 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-79623365 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7964489220704497771,8279194133401378956,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --user-data-dir=/tmp/karma-79623365 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu http://localhost:9876/?id=79623365 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222 (dns block)
  • redirector.gvt1.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=3926 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-79623365 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7964489220704497771,8279194133401378956,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --user-data-dir=/tmp/karma-79623365 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu http://localhost:9876/?id=79623365 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222 (dns block)
  • safebrowsingohttpgateway.googleapis.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=3926 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-79623365 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7964489220704497771,8279194133401378956,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --user-data-dir=/tmp/karma-79623365 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu http://localhost:9876/?id=79623365 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222 (dns block)
  • www.google.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --no-sandbox --disable-dev-shm-usage --use-angle=swiftshader-webgl --crashpad-handler-pid=3926 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/karma-79623365 --change-stack-guard-on-fork=enable --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7964489220704497771,8279194133401378956,262144 --disable-features=PaintHolding --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /opt/google/chrome/chrome /usr/bin/google-chrome --user-data-dir=/tmp/karma-79623365 --enable-automation --no-default-browser-check --no-first-run --disable-default-apps --disable-popup-blocking --disable-translate --disable-REDACTED-timer-throttling --disable-renderer-REDACTEDing --disable-device-discovery-notifications --no-sandbox --disable-gpu http://localhost:9876/?id=79623365 --headless --disable-gpu --disable-dev-shm-usage --remote-debugging-port=9222 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Cannot read property 'name' of undefined</issue_title>
<issue_description>I've got an error like in title. It's in function computeStackTrace in last return when tries to get ex.name.

It is called by function traceKitWindowOnUnhandledRejection (and I don't have more stacktrace).

Could you tell me why I got this error? </issue_description>

<agent_instructions>Make sure we have test coverage and can reproduce before fixing. make sure you look at the linked pr and also make sure you look at how the fix in their main branch has changed any. If the code has been replaced, look at what it looked like right before they replaced (if they are no longer using tracekit)</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@niemyjski This is a function that is wired up to https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onunhandledrejection and handles this type of event. Sounds like that event can be null. Can you let us know how you reproduced it and with the specifics of what browser/os you were using with specific versions.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…defined

Co-authored-by: niemyjski <1020579+niemyjski@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix 'Cannot read property name of undefined' error Fix "Cannot read property 'name' of undefined" when Promise is rejected without a reason Feb 25, 2026
Copilot AI requested a review from niemyjski February 25, 2026 15:07
@niemyjski niemyjski marked this pull request as ready for review February 25, 2026 15:11
@liviuconcioiu
Copy link

liviuconcioiu commented Feb 25, 2026

Change looks good. Thank you for the fix. If a new version can be released, that will be awesome!

@niemyjski niemyjski merged commit 64937f8 into master Feb 27, 2026
1 check passed
@niemyjski niemyjski deleted the copilot/fix-unhandled-rejection-error branch February 27, 2026 03:44
@niemyjski
Copy link
Collaborator

Pushed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot read property 'name' of undefined

3 participants