Re: [whatwg/webidl] What's the idiomatic way to reject a promise with structured data? (Issue #1223)

I'm not sure how unique this is in the platform, but this seems to layer two problems: 

1. a potential error at the call site (`compileShader()`). 
2. a compilation error at the GPU level as **the cause** of the exception. 

Expressed a bit differently:

```JS
const shaderProgram = `
    fn bar(foo: Foo) {
        let baz = foo * 7; // Structs can't be multiplied by 7; this is a compile error
    }
`;
try {
  await compileShader(shaderProgram);
} catch (err) {
   // err is maybe TypeError or some new GPUError, as the type of input was bad. 
   // err.cause as SyntaxError in shaderProgram at some line, column.
}
```

If a `TypeError` or some new `GPUError` would depend on the various different ways `compileShader()` can fail. 

The rationale being that the `.cause` would contain the "structured data" represented as a `SyntaxError` for the column/line number  of `shaderProgram`.

Similarly, the `TypeError` or `GPUError` would give you the stack for where `.compileShader()` was called from. 

I'm imagining that then developer tools could show more clearly where the error was in `shaderProgram` by linking everything together (same way that dev tools does today when running code in console). 

Please let me know if I'm overcomplicating this. 

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/webidl/issues/1223#issuecomment-1284608389
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/webidl/issues/1223/1284608389@github.com>

Received on Wednesday, 19 October 2022 21:47:52 UTC