-
Notifications
You must be signed in to change notification settings - Fork 474
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
Error types everywhere instead of String #942
Comments
I would definitely be interested in a PR for this. The problem is that it's mostly a trial and error process. The strings don't look as nice as "GPU_ERROR_56", but rather look like "Error when opening keyboard state: 0x5786 driver error" (so yeah, there would be some parsing to do as well). Basically what I mean is that most of the errors SDL2 returns are really hard to parse errors, aside for a few ones that are static... The documentation on the matter is also rather sparse (and sometimes non existant), you have to dig through the source code to know exactly what some error might mean. That, and even if you were to cover all string cases, there might be a case where SDL2 adds a new string error without our knowledge, so assuming we use enums instead of string, there would always be the need to have a However, as cumbersome as it may look, it would be a definitely huge feature to have. Just know that it may not be as trivial as you might think at first glance! |
Parsing all the possible strings does sound like a lot of work. I was thinking of just wrapping everything that is currently a String in an The benefit would be for the consumer being able to cast the library's errors into their own error type with a blanket |
I've done some private work on this and have adjusted all the functions that return |
Mmmh no, it doesn't make sense in my opinion to have a |
OK. In that case to make the examples neat I've tried using the |
Ah wait, we don't need the |
Some of the errors returned by the library implement the
std::error::Error
trait and some are justString
s. I propose all errors returned by the library implementstd::error::Error
to simplify error handling for consumers.In the cases where we only have a
String
to return, this can be wrapped in anenum
that implementsError
.This would of course be a breaking change.
Would you be interested in a PR for this?
The text was updated successfully, but these errors were encountered: