DieKit

0.1.0

💀 Comprehensive error printer for Swift
nzrsky/DieKit

What's New

0.1.0

2023-11-10T23:13:52Z

DieKit

Error Printer for Swift

Danger Swift Codecov

DieKit, a Swift package designed to streamline and enhance error handling in your Swift applications. It makes exception handling more robust and insightful.

Key Features

  • Enhanced Error Reporting: It catches, prints, and rethrows errors for comprehensive debugging.
  • Wide Error Support: DieKit extends support to various Swift and Core Foundation error types, providing a versatile tool for a broad range of applications.

Installation

Add DieKit to your Swift project by including it in your Package.swift dependencies:

dependencies: [
    .package(url: "https://github.com/nzrsky/DieKit.git", from: "1.0.0")
]

Usage

Here's how simple it is to use DieKit:

import DieKit

// ❌ This code doesn't compile
let x = env["SECRET_KEY"] ?? fatalError()

// ❌ Also compilation error here
let x = env["SECRET_KEY"] ?? { fatalError() }

// ✅ But this is OK
let x = env["SECRET_KEY"] ?? die("Specify SECRET_KEY")

Print error to stderr and proceed handling:

// Usage of printOnException
do {
    let result = try printOnException { try throwingOperation() }
    // prints error message to stderr according error's type
} catch error {
    // handle error
}

// Usage of dieOnException
let result = dieOnException { try throwingOperation() }
// prints error message to stderr and die

Posix errors:

throw NSError(posixError: EFAULT)

Print formatted errors:

// Default behaviour
print(CGError.illegalArgument)
// The operation couldn’t be completed. (__C.CGError 1003)

// With DieKit
print(CGError.illegalArgument)
// error: The operation couldn’t be completed. (CGError: Illegal Argument)

Contributing

Contributions make the open-source community an amazing place to learn, inspire, and create. Any contributions you make to DieKit are greatly appreciated.

License

Distributed under the MIT License. See LICENSE for more information.

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

Last updated: Sat Nov 18 2023 14:03:28 GMT-1000 (Hawaii-Aleutian Standard Time)