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

Add custom missing mandatory UFO path error types & missing mandatory UFO path checks #146

Merged

Conversation

chrissimpkins
Copy link
Collaborator

@chrissimpkins chrissimpkins commented Jul 27, 2021

Supersedes #143

New approach based on suggestion in #143 (comment)

TODO:

  • add metainfo.plist check (d9d26c4)
  • add glyphs/contents.plist check (a418ef2)
  • add tests for all new missing mandatory path checks

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

src/error.rs Outdated Show resolved Hide resolved
@chrissimpkins
Copy link
Collaborator Author

chrissimpkins commented Jul 27, 2021

I'll wrap up the items in the TODO list and then convert out of Draft for a full implementation review. If this approach seems reasonable, this should get us to read validations / error handling on all required UFO paths

@chrissimpkins chrissimpkins marked this pull request as ready for review July 27, 2021 22:12
@chrissimpkins
Copy link
Collaborator Author

chrissimpkins commented Jul 27, 2021

This PR now includes:

  • UFO directory path existence validation check and custom norad error
  • metainfo.plist @ root validation check and custom norad error
  • contents.plist in glyphs / background glyphs layer dir check and custom norad error
  • layercontents.plist @ root (if UFOv3 source) check error handling refactor with different custom norad error (same as other missing file errors)
  • new test sources & tests for each UFO spec mandatory file violation check

Ready for review.

@chrissimpkins chrissimpkins changed the title Add custom missing mandatory path error types & missing mandatory path checks Add custom missing mandatory UFO path error types & missing mandatory UFO path checks Jul 27, 2021
src/font.rs Outdated
let font_load_res = Font::load(path);
match font_load_res {
Ok(_) => panic!("unxpected Ok result"),
Err(Error::MissingUfoDir(_)) => (), // expected value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_eq!(font_load_res, Err(Error::MissingUfoDir(...))) or something maybe?

Copy link
Collaborator Author

@chrissimpkins chrissimpkins Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried. Compiler won't let me perform equality comparisons on the Result Error type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things:

As written, I would do this as,

assert!(matches!(font_load_res, Err(Error::MissingUfoDir(_))));

but there's probably a better option: explicitly testing for a panic with the should_panic attribute.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but there's probably a better option: explicitly testing for a panic with the should_panic attribute.

Ah nice, I didn't realize that you can add an expected string with should_panic. I tried this approach but I can't elicit a panic from the new custom Error. The attribute doesn't seem to catch errors like it does panics. I see this in the docs that you linked:

You can’t use the #[should_panic] annotation on tests that use Result<T, E>. Instead, you should return an Err value directly when the test should fail.

Let me tinker with the test Result approach a bit. If I can't find a better solution, I'll transition things over the matches! macro approach above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would work if you just unwrap the Result?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(but matches! is totally reasonable too)

Copy link
Collaborator Author

@chrissimpkins chrissimpkins Jul 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the use of a Result return type in unit tests is good if you expect an Ok() but there isn't a way to expect an Err. We could return a test error when the function being tested returns Ok 💥 but that seems worse than the match pattern matching approach :)

I went with the matches! macro. That allows us to confirm the custom error type and works well!

b1c17ab

@madig
Copy link
Collaborator

madig commented Jul 27, 2021

Maybe consider removing inessential files from the test UFOs, like lib.plist.

@chrissimpkins
Copy link
Collaborator Author

Maybe consider removing inessential files from the test UFOs, like lib.plist.

a25963b

Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, feel free to merge at your leisure @chrissimpkins.

@chrissimpkins
Copy link
Collaborator Author

This looks good to me, feel free to merge at your leisure @chrissimpkins.

Thank you both for all of the feedback here!

@chrissimpkins chrissimpkins merged commit 990a695 into linebender:master Jul 28, 2021
@chrissimpkins chrissimpkins deleted the custom-error-expected-paths branch August 20, 2021 22:11
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

Successfully merging this pull request may close these issues.

3 participants