-
Notifications
You must be signed in to change notification settings - Fork 474
API: Proper error types instead of String #1424
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
base: master
Are you sure you want to change the base?
Conversation
|
I think I noted everything down, I'll leave actually changing all strings when I'm given the green light! It is a breaking change, however migrating code should be pretty easy: |
| Self::Sdl(msg) => write!(f, "SDL error: {msg}"), | ||
| Self::Io(err) => write!(f, "IO error: {err}"), | ||
| Self::IntOverflow(name, value) => write!(f, "Integer '{name}' overflows: {value}"), | ||
| Self::InvalidString(name, nul) => write!(f, "Invalid string '{name}': {nul}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the definition the first field is the NulError, not the name.
To prevent these bugs (in this crate but also user code using this crate) I advise to use a struct like variant instead of a tuple like one. This also adds context to the context-less &'static str field. I suggest to change the definition to InvalidString { nul_err: NulError, var_name: &'static str } (or something like this) and roughly the same for IntOverflow.
| impl error::Error for Error { | ||
| fn source(&self) -> Option<&(dyn error::Error + 'static)> { | ||
| match self { | ||
| Self::Sdl(..) | Self::IntOverflow(..) => None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source may also be returned for Self::Sdl
|
bump because this would be mad useful if finished |
Work in progress. I am also taking time to unify all error types, since there were many
SdlErrors before. I would like to discuss if compatibility is necessary, e.g. it could be a feature-flag that doestype SdlError = String;See also: #1053
Summary:
OpenUrlError,PrefPathError,ShowMessageError,WindowBuildErrorandFontErrorin favor ofError::InvalidStringcommon::IntegerOrSdlErrorin favor ofError::IntOverflowset_error_from_code(internal SDL api, shouldn't be here? could add back asSdlErrorCode)NulErrortoError::InvalidString?pref_pathchecking for empty string instead of nullTODO:
TargetRenderError,TextureValueError,UpdateTextureError,UpdateTextureYUVError,AddMappingErrorttf::InitErrorcould be removed, if same ref-counting as subsystems is implemented for itttf::FontErrorwas removed, it might be good to review removingRendererableText, as aCStringis always allocated anyway?String->SdlError, however this is messy becauseRWOpsshould useError, as it currently convertsio::ErrortoString, and that should be avoided