Why do so many WGPU functions panic on invalid input rather than returning a result?

148 points Irument 45 comments

I've been working on a toy game engine to learn wgpu and gpu programming in general, and something i've noticed is that the vast majority of functions in wgpu choose to panic upon receiving invalid input rather than returning a result. Many of these functions also outline exactly why they panic, so my question is why can't they validate the input first and give a result instead? I did a few cursory searches on the repository and i couldn't find anyone asking the same question. Am I missing something obvious here that would make panics the better option, or is it just some weird design choice for the library?