wulkano / Aperture

Record the screen on macOS
MIT License
1.24k stars 111 forks source link

Implement proper error handling #26

Closed sindresorhus closed 7 years ago

sindresorhus commented 7 years ago

And improve and simplify a lot of the code

Swift errors will now make it all the way to Kap

StefMa commented 7 years ago

The util class should be added to the package.json, right? Otherwise it will not be packaged when we publish to npm registry...

sindresorhus commented 7 years ago

@StefMa No, the binary is compiled before publish.

sindresorhus commented 7 years ago

I would try to avoid force unwrapping as much as possible. Even where you think its okay to crash I prefer using fatalError("My message") to get more meaningful error messages than the usual "unexpectedly found nil while unwrapping an Optional value"

What's the convention for when to mark your function with throws, silencing with try?, printing an error and returning nil, or fatalError? It seems like very few APIs throw with useful error messages. Usually it's up to you to handle almost every method call, which gets verbose. I kinda feel like error handling is not yet completely figured out in Swift.

I would also consider using Swift Package Manager, and using Commander or something similar to handle command line arguments.

I'm actually planning to go in another direction: https://github.com/wulkano/aperture/issues/8#issuecomment-275308988 Could use your thoughts on the issue.

Id be happy to help out if you need anything :)

That's is very nice of you. I'm already learning a lot. Will let you know :)

LarsJK commented 7 years ago

Once you get used to the swift error handling its actually quite nice. A lot of cocoa APIs are ObjC APIs, the errors thrown are NSErrors so they are not as useful as swift ones with enums for example..

Note that errors are not typed so its useful to explain what errors can be thrown in the doc block..

sindresorhus commented 7 years ago

Awesome. Landed \o/

Thanks for all the feedback @LarsJK. I learned a lot and feel more confident in my Swift abilities now.


Btw, I did some minor additional tweaks, would you mind just checking that I didn't do anything bad: https://github.com/wulkano/aperture/pull/26/commits/b711276a4e590e6d69e16ba44c5119b006f05133 ?