Error Handling: Why do we not return Results anymore? #1734
Replies: 1 comment 1 reply
-
Hi, and thank you for the kind words! First, wgpu-rs doesn't return Instead, aligning it with WebGPU specification allows users to have the same code running everywhere, and not 2 different ways to handle errors. To clarify, user should be fully capable of writing an application that does NOT error. You shouldn't be trying to write run-time code dealing with errors, unless both conditions are satisfied:
The (1) means that each method would return a So, instead, you handle only errors that you opt into. Unfortunately, wgpu-rs doesn't expose this right now, but it needs to. Also, to clarify, in WebGPU upstream (as well as wgpu-rs), if you are doing something wrong, like creating a texture with bad sizes, then it would still be created. It's completely valid to continue doing operations, like create other resources, submit command buffers, or even create resources based on this texture. This is how WebGPU upstream treats it. |
Beta Was this translation helpful? Give feedback.
-
Hi! First, thanks for this awesome webgpu implementation! It's awesome to finally have a truly cross-platform graphics API. <3
That being said, I have some questions about the API design of this crate. As a completely new user, I expected most methods to return errors, or futures, or a combination thereof. Instead, I found a global error handler, which must also be static and therefore cannot borrow local context. The global error handler reminded me of using C + OpenGL back in the day, which is an unpleasant memory haha.
What are the reasons for this design? Especially when compiling shaders, it would be very difficult to check the correctness of every shader in advance, and receiving a
Result
would be much less work for all the users of this crate. Considering that this crate is meant to be the idiomatic Rust wrapper, I would propose some kind of abstraction that allows us to return Results instead of calling an error handler.I found #706 (and #638) but it seems like these changes a no longer with us.
Beta Was this translation helpful? Give feedback.
All reactions