We replace createBuffer() with tryCreateBuffer(), in which we catch all three types of errors. For now, we treat any error occurred in createBuffer() fatal and hence do device.destroy(). When a device is initiated, we use device.lost.then() to listen to the event of device.destroy(), upon which we log the error and call Instance.dispose(), prompting the user to re-initialize.
Prior to this PR, WebGPU errors such as OOM are only logged as a warning without affecting the program. This PR handles WebGPU error using
pushErrorScope()
andpopErrorScope()
following https://github.com/gpuweb/gpuweb/blob/main/design/ErrorHandling.md.We replace
createBuffer()
withtryCreateBuffer()
, in which we catch all three types of errors. For now, we treat any error occurred increateBuffer()
fatal and hence dodevice.destroy()
. When a device is initiated, we usedevice.lost.then()
to listen to the event ofdevice.destroy()
, upon which we log the error and callInstance.dispose()
, prompting the user to re-initialize.See https://github.com/mlc-ai/web-llm/issues/356 for motivation.
Tested end-to-end with WebLLM.