deno
bf78fefd - fix(ext/console): degrade gracefully when getKeys throws (#24980) (#34464)

Commit
191 days ago
fix(ext/console): degrade gracefully when getKeys throws (#24980) (#34464) ## Summary Fixes the `Uncaught AssertionError: Assertion failed` raised by `console.log` / `Deno.inspect` when handed a Proxy whose `getOwnPropertyDescriptor` trap throws, e.g. (from #24980): ```js console.log( new Proxy({ x: 10 }, { getOwnPropertyDescriptor: () => { throw new Error("oops"); }, }), ); ``` Before: ``` Uncaught AssertionError: Assertion failed at assert (ext:deno_web/01_console.js:…) at getKeys (ext:deno_web/01_console.js:…) … ``` After: ``` { x: 10 } ``` ## Background `getKeys` previously asserted that any error from `Object.keys(value)` was a `ReferenceError` raised by accessing an unevaluated module-namespace object, and otherwise re-threw via `assert(false)` — i.e. surfaced as `AssertionError: Assertion failed`. #34373 added proxy unwrapping in `formatValue` (when `showProxy` is `false`, Deno now inspects the proxy target instead of the proxy itself, matching Node.js). That removes the common path that brought a throwing-trap Proxy to `getKeys`, but the assertion was still load-bearing for resilience: anything else that ever throws from `Object.keys` (or, before it, `Object.getOwnProperty­Symbols`) would crash inspect with a useless message. This PR softens `getKeys` so unexpected failures degrade to a less-detailed but valid inspection instead of a crash: - `Object.keys` → on throw, fall back to `Object.getOwnPropertyNames`, then to an empty key list. - `Object.getOwnPropertySymbols` → on throw, treat as no symbols. - The enumerability filter (`propertyIsEnumerable`) is guarded too. The now-unused `assert` / `AssertionError` internal helpers are removed. ## Tests `tests/unit/console_test.ts` — extends the existing `inspectProxy` test with the exact repro from #24980 (Proxy with a throwing `getOwnPropertyDescriptor`). Closes #24980. Closes denoland/orchid#277 Co-authored-by: divybot <divybot@users.noreply.github.com> Co-authored-by: Divy Srivastava <me@littledivy.com>
Author
Parents
Loading