Skip to content

Commit 39a703c

Browse files
author
Matthew Judy
committed
Add irreverent exception generarion.
1 parent 9a4ae23 commit 39a703c

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

Sources/Shared/Error+.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//
2+
// Error.swift
3+
//
4+
// Created by Matthew Judy on 7/25/19.
5+
// Copyright © 2019 NibFile.com. All rights reserved.
6+
//
7+
8+
import Foundation
9+
10+
11+
public struct AteShit: LocalizedError
12+
{
13+
public enum Fuckery : String
14+
{
15+
case initializing
16+
case parsing
17+
case converting
18+
19+
case reading
20+
case writing
21+
22+
case encoding
23+
case decoding
24+
}
25+
26+
public let whilst : Fuckery
27+
public let grimDetails : Any?
28+
29+
30+
/// I'm making a note here: the app ate shit.
31+
///
32+
/// throw AteShit(whilst: .initializing,
33+
/// "We done fucked up.")
34+
///
35+
/// - Parameters:
36+
/// - whilst:
37+
/// The general category of fuckery in which the app was engaged
38+
/// when it ate shit
39+
/// - grimDetails:
40+
/// A description of the specific clusterfuck that has caused the
41+
/// app to eat shit, or an object you want to tattle on about it.
42+
///
43+
public init(whilst: Fuckery, _ grimDetails: Any? = nil)
44+
{
45+
self.whilst = whilst
46+
self.grimDetails = grimDetails
47+
}
48+
49+
50+
public var errorDescription: String
51+
{
52+
let description = "[ERROR] The app ate shit whilst \(self.whilst)"
53+
54+
switch self.grimDetails
55+
{
56+
case .none: return description
57+
case .some(let accessory): return description.appending(": '\(String(describing: accessory))'")
58+
}
59+
}
60+
}
61+
62+

0 commit comments

Comments
 (0)