fix(debugger): handle Invalid Date in snapshot processor#7944
fix(debugger): handle Invalid Date in snapshot processor#7944
Conversation
Calling `toISOString()` on an Invalid Date throws a RangeError. This
could happen when a user has a variable holding `new Date('invalid')`
at a breakpoint. Fall back to the raw description string when the
date is not valid.
Overall package sizeSelf size: 5.47 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.0 | 81.15 kB | 815.98 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7944 +/- ##
==========================================
- Coverage 74.25% 71.06% -3.20%
==========================================
Files 769 768 -1
Lines 36068 36058 -10
==========================================
- Hits 26783 25623 -1160
- Misses 9285 10435 +1150 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: 74d70b2 | Docs | Datadog PR Page | Was this helpful? React with 👍/👎 or give us feedback! |
BenchmarksBenchmark execution time: 2026-04-07 19:52:48 Comparing candidate commit 74d70b2 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 229 metrics, 31 unstable metrics. |
| // in the `description` field. Unfortunately that's all we get from the Chrome DevTools Protocol. | ||
| return { type: obj.className, value: `${new Date(obj.description).toISOString().slice(0, -5)}Z` } | ||
| const date = new Date(obj.description) | ||
| const value = isNaN(date.getTime()) ? obj.description : `${date.toISOString().slice(0, -5)}Z` |
There was a problem hiding this comment.
| const value = isNaN(date.getTime()) ? obj.description : `${date.toISOString().slice(0, -5)}Z` | |
| const value = Number.isNaN(date.getTime()) ? obj.description : `${date.toISOString().slice(0, -5)}Z` |

What does this PR do?
Fixes a
RangeErrorcrash in the Dynamic Instrumentation snapshot processor when capturing an Invalid Date object at a breakpoint.Date.prototype.toISOString()throws aRangeErrorwhen called on an Invalid Date (e.g.new Date('invalid')). Since the Chrome DevTools Protocol still reports these assubtype: 'date', the snapshot processor would hit this code path and crash. The fix checksdate.getTime()forNaNbefore callingtoISOString(), falling back to the rawdescriptionstring ("Invalid Date") when the date is not valid.Motivation
If a variable holding an Invalid Date exists at a breakpoint location, the
RangeErroris thrown inside theDebugger.pausedevent handler. Since this runs in the devtools client worker thread, it would not crash the instrumented application itself, but it would cause the snapshot collection to fail silently — the breakpoint would appear to hang and no snapshot data would be sent to Datadog.Additional Notes
A test for this case has been added to the existing
complex-typessnapshot test suite.