-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's the idiomatic way to reject a promise with structured data? #1223
Comments
I'm not sure how unique this is in the platform, but this seems to layer two problems:
Expressed a bit differently: 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 The rationale being that the Similarly, the I'm imagining that then developer tools could show more clearly where the error was in Please let me know if I'm overcomplicating this. |
Good timing! We are adding a pattern exactly for this case in #1211 . I don't think using |
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Ah, never mind them 😊 Having a look at #1211. |
@domenic so, sounds like we should subclass DOMException?
Is this ready to go? We'd be happy to add this to the WebGPU spec as soon as you give the go-ahead. |
Yes, that's the idea! Be sure to follow the full pattern shown in #1211, including the guidance in the following: * The [=identifier=] of the [=interface=] must end with <code>Error</code>, and must not be any
of the names in the <a><code>DOMException</code> names table</a>.
* The [=interface=] must have a [=constructor operation=] which sets the instance's
[=DOMException/name=] to the interface's [=identifier=].
* Their [=constructor operation=] must take as its first parameter an [=optional=] {{DOMString}}
named |message| defaulting to the empty string, and must set the instance's
[=DOMException/message=] to |message|.
* Their [=constructor operation=] should take as its second parameter a [=dictionary=] containing
the additional information that needs to be exposed.
* They should have [=read only=] [=attributes=], whose names are the same as the members of the
constructor dictionary, which return the values accepted by the constructor operation.
* They should be [=serializable objects=], whose [=serialization steps=] and
[=deserialization steps=] preserve the additional information. (The PR also contains a full example of how to do this.) Actually merging that PR is blocked on a tooling issue (plinss/widlparser#79), but you can follow its example ahead of time with no issues. |
Although I guess your spec build might also be blocked by the same tooling issue, at least if you're using Bikeshed... :-/. |
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Also be clearer about how exception names are meant to be used, at least for now (pending discussion in #1219). See discussion in #1168 (comment). Closes #1223. This also includes some updates to all exception creation and throwing, such as reflecting how messages are actually passed along in practice, or using Web IDL infrastructure to create DOMException instances instead of Construct()ing them.
Hello!
In WebGPU, the website provides shader source code as a string to the browser, for the browser to compile it. The compilation process is asynchronous and returns a promise, because it runs in the GPU Process. Of course, that shader source code string may be erroneous; if the compilation process fails, it's fairly natural to reject the promise. When we reject the promise, we'd like to provide structured data to the website that includes errors, warnings, message strings, line + column information, maybe things like the name of the function that had the error inside it, possibly error codes, etc.
This is oversimplified a lot, but an author's code would want to look somewhat vaguely like this:
However, https://www.w3.org/2001/tag/doc/promises-guide#reasons-should-be-errors says:
It's unclear how to attach structured data to an Error or a DOMException. Should we subclass
DOMException
as e.g.RTCError
does? Or maybe we should attach a dictionary to thecause
field ofError
?The text was updated successfully, but these errors were encountered: