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

[piet-cairo] Provide propper error for strings containing null before passing to cairo #447

Open
JAicewizard opened this issue May 26, 2021 · 1 comment

Comments

@JAicewizard
Copy link
Contributor

Currently creating something like a piet label containing a null byte as character will crash the program with a vague error and backtrace.

This could be improved by providing a proper error. Ideally cairo-rs should handle this, and I might end up filling an issue on them as well tomorrow.

@cmyr
Copy link
Member

cmyr commented Jun 7, 2021

This error is definitely a cairo-specific error; the piet text API does not explicitly disallow nul bytes in strings. The piet crate provides a single Error::Platform variant that holds all platform originating errors.

So two thoughts:

  • improving the quality of error messages upstream is a good approach. They're receptive to PRs, and so trying to just improve this in cairo-rs would be my first thought.
  • The PlatformError does not need to just be us boxing whatever error we get back from cairo; we could, in piet-cairo, define our own error variant that provides more information in some cases; then when we got an error back from cairo-rs we might inspect it and then determine how best to convert it into a piet-cairo error. This is a pragmatic solution; it gives us more control and flexibility, and also allows us to add more context; for instance if an error occurs when trying to create a text layout, we could include the problem string in the error, on our side.

Thinking about this a bit more, I actually think I'm leaning towards the second option? I think the flexibility could be very helpful.

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

No branches or pull requests

2 participants