Errors
Error handling in this extension is a little weird, but pretty simple, since the usual methods aren't really applicable to scratch. In place of these, there are a couple of blocks for basic error handling, which I will show you how to do.
when error thrown :: hat #4287f5 Error :: reporter #4287f5
This hat is run whenever an error occurs. When an error is thrown, it also sets the Error block to the error's data, in the format:
{"name":"errorName","body":"errorBody","source":"errorSource","full":"fullError"}
We can make a pretty basic error logger using the debugger addon:
when error thrown :: hat #4287f5 log (Error :: reporter #4287f5) :: #29beb8
Then we can run some very obviously wrong blocks
Run shader [awwdfaegsbrht] using bind group [your mother] dimensions x: [-15] y: [0] z: [2134] :: #4287f5
Which logs the error
{"name":"ShaderNotFound","body":"Couldn't find specified shader!","source":"RunShaderBlock","full":"Couldn't find shader \"awwdfaegsbrht\"!"}
This works fine, but you can probably check what kind of error it is depending on how you use this extension. However, the main error for you to check for is DeviceLost. This means your connection to the gpu was interrupted, so you need to reconnect. We can check for this, and use the Reconnect to gpu block:
when error thrown :: hat #4287f5 if <(value of [name] in (Error :: reporter #4287f5) :: reporter #3271D0) = [DeviceLost]> { Reconnect to GPU :: #4287f5 } else { log (Error :: reporter #4287f5) :: #29beb8 } :: controlThe "value of [name]" block is from the json extension
That's pretty much it, you can probably figure out how to handle the rest. Here's the (incomplete) list of possible error name:
Some of these are just internal catch-alls when running a webgpu operation, so it's a good idea to check the error messages.BufferReadError - Thrown when webgpu fails to read the buffer
BufferNotFound - Thrown when a buffer referenced in a block doesn't exist
InvalidInput - Thrown by various(currently only 2) sources if an input is invalid
CopyBufferToBufferError - Thrown when webgpu fails to copy one buffer to another buffer
ArrayNotFound - Thrown when the array referenced in a block doesn't exist
BindGroupCreationError - Thrown when webgpu fails to create the bind group
BindGroupCreationErrorOOM - OOM stands for Out Of Memory, this is bad and your gpu doesn't have enough memory to create the bind group
InvalidEntryDescriptor - Thrown when the bind group layout entry descriptor given to a bind group entry block is invalid
BindGroupLayoutCreationError - Thrown when webgpu fails to create the bind group layout
BindGroupLayoutCreationErrorOOM - OOM stands for Out Of Memory, this is bad and your gpu doesn't have enough memory to create the bind group layout
BufferCreationError - Thrown when webgpu fails to create the buffer
BufferCreationErrorOOM - OOM stands for Out Of Memory, this is bad and your gpu doesn't have enough memory to create the buffer
UnclassifiedRuntimeError - Thrown when webgpu fails to run your shader
UnclassifiedRuntimeErrorOOM - OOM stands for Out Of Memory, this is bad and I'm not even sure if it's possible for this to happen. Let me know if it does because I'm curious
BindGroupNotFound - Thrown when the bind group referenced in a block doesn't exist
ShaderNotFound - Thrown when the shader referenced in a block doesn't exist
ConputePipelineError - Thrown when compiling and webgpu failed to create the compute pipeline for one of your shaders
WGSLError - Thrown when compiling if your shader has some sort of error in it. The relevant error will be highlighted in **markdown bolding**
ShaderCreationError - Thrown when compiling and webgpu failed to create the shader module
BindGroupLayoutNotFound - Thrown when the bind group layout referenced in a block doesn't exist
UnexpectedInput - Thrown when you put a block where blocks aren't allowed
MissingInput - Thrown when you don't put a block where a block is supposed to go, this isn't always an error and sometimes it's just a warning
InvalidBlock - Thrown when you put an unrecognized block in a shader hat
MissingOp - Mostly for developers, thrown when trying to get a raw input's value but it's not in the list. Check the textFromOp function
DeviceLost - Thrown when the connection to webgpu is lost, you'll need to reconnect
UnclassifiedError - Thrown for any error that wasn't caught by existing internal error handling, please report these!