Skip to content
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

Improve error handling #16

Open
3 tasks
matprec opened this issue Oct 14, 2017 · 6 comments
Open
3 tasks

Improve error handling #16

matprec opened this issue Oct 14, 2017 · 6 comments

Comments

@matprec
Copy link
Owner

matprec commented Oct 14, 2017

There are a lot of unwrap()s in the code. Proper error handling with Result's would be nice.

Happy to provide guidance! Just comment on this issue.

Edit:

  • Windows
  • Fontconfig (*nix)
  • Mac
@soumya-ranjan7
Copy link

Interested

@ashkitten
Copy link

Just a personal recommendation - I really like using the error_chain crate

@matprec
Copy link
Owner Author

matprec commented Oct 14, 2017

I haven't used error_chain before, but looks nice!

@soumya-ranjan7
Look for unwraps in the src/ folder. pub fns with an unwrap in their path should return a Result.
The Error type would be an enum in src/lib.rs, with could look like this:

enum LoadingError {
    FontNotPresent,
    Platform(Error)
}

Like @ashkitten suggested, you can use the error_chain crate if you want to :)

The unwraps in win32 like this one should be converted into an expect instead of unwrap, since we're depending on correct handling by the os.
Since there are three different platforms, please add which one you are working on and comment on this thread which public interfaces were changed.

If you have questions, post them here :)

@soumya-ranjan7
Copy link

I will be working on Windows @MSleepyPanda

@ashkitten
Copy link

Isn't it better as a library especially to bubble the errors up by returning Result? That way any application using the library can deal with errors however it wants, without having to panic if something goes wrong. Generally, panicking in a library is a bad thing to do.

@matprec
Copy link
Owner Author

matprec commented Oct 15, 2017

In general, i agree. But when the OS is returning non null terminated or non utf8 strings, we have a bigger problem than the library panicking. At some point, we have to trust the OS i think.

(Fight me :P )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants