[Web] Destroy GPUDevice once on buffer creation error#19790
Conversation
Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the WebGPU error scope handling in webgpu.ts to use Promise.all, ensuring that device.destroy() is called at most once when multiple error types fire. The reviewer identified two important issues: a potential unhandled promise rejection if popErrorScope() rejects, and a TypeScript type narrowing issue where errors.filter does not automatically cast the array to GPUError[]. A code suggestion was provided to add a .catch() block and an explicit type guard.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
## Why In `tryCreateBuffer`, each of the three popped error scopes independently called `device.destroy()` and `console.error`, so a buffer that triggers more than one error type destroyed the device repeatedly and logged duplicate errors. ## How - Collect all three `popErrorScope()` results via `Promise.all` and call `device.destroy()` at most once - Log every captured error instead of relying on per-scope handlers --------- Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Why
In
tryCreateBuffer, each of the three popped error scopes independently calleddevice.destroy()andconsole.error, so a buffer that triggers more than one error type destroyed the device repeatedly and logged duplicate errors.How
popErrorScope()results viaPromise.alland calldevice.destroy()at most once