exyte / Macaw

Powerful and easy-to-use vector graphics Swift library with SVG support
MIT License
6.01k stars 553 forks source link

Removing force unwrapping #732

Open TomasLinhart opened 3 years ago

TomasLinhart commented 3 years ago

Currently, there are a lot of force-unwraps of optionals in the codebase. For example, SVGParser contains a few unchecked force-unwraps that can result in a crash for non-ideal SVGs. We had a chance to experience these crashes.

Would you be open to removing these force-unwraps?

It also seems it is more prevalent use x != nil ... x! instead of using if let or guard let.

Would you accept a pull request that addresses the force-unwraps and replaces them with safer options (errors, logging, fallbacks)?

ystrot commented 3 years ago

Hi Tomas!

That's definitely a must-have parser improvement. I'd like to use logger during parsing and provide different methods in SVGParser:

  1. Safe parse which ignores all errors and return what it can get.
  2. Usual parse which throws error when something logged.
  3. Provide Logger as an argument to handle all cases on your own.

I'd be happy to accept such a pull request. There are probably a lot of work, so it makes sense to split it to different PRs. Also we need to keep backward compatibility, so existing API should work as before (except logging to console, this should be avoided no doubt).