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
Size: 1400
Language: Swift
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
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))
Add github "daehn/die"
to your Cartfile