wireapp/die

Name: die

Owner: Wire Swiss GmbH

Description: ?-framework to exit swift scripts

Forked from: daehn/die

Created: 2017-10-09 08:36:28.0

Updated: 2017-10-09 08:36:29.0

Pushed: 2018-04-12 13:37:31.0

Homepage:

Size: 1400

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Die, ?-framework to exit swift scripts

Build Status codecov.io Swift 4.0 Carthage compatible

Usage

Calling die() or die("Oh no!") prints the name of the file, the location of the error and the optional message and calls exit(EXIT_FAILURE) afterwards. There also are multiple convenience functions to work with throwing functions:

nThrow {
try maybeThrowingFunction(["Please", "don't", "throw"])

Or using the message parameter to supply a failure reason:

nThrow("Failed to compute the answer") {
guard someValue == 42 else { throw SomeError }

And for working with throwing functions and using the result:

contents = dieOnThrow("Unable to get the contents of \(someURL)") {
let contents = try fm.contentsOfDirectoryAtURL(someURL, includingPropertiesForKeys: nil, options: [])
// Do more stuff...
return contents

Additionaly there are functions to die in case an expression evaluates to nil, or not to nil:

result = dieIfNil(someObject.methodThatMightReturnNil())
fNotNil(someObject.methodThatReturnsAnError())

As well as for true or false:

fFalse(fm.isDeletableFileAtPath(sourcePath))

nThrow("Failed to delete \(sourcePath)") {
try fm.removeItemAtPath(sourcePath)


fTrue(fm.fileExistsAtURL(sourceURL))
Installation

Add github "daehn/die" to your Cartfile


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.