Skip to content

Commit f28d8cc

Browse files
committed
Updated SDLError
1 parent 5626109 commit f28d8cc

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

Sources/SDL/Error.swift

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Alsey Coleman Miller on 10/19/18.
66
//
77

8+
import Foundation
89
import CSDL2
910

1011
/// SDL Error
@@ -23,6 +24,18 @@ extension SDLError: CustomStringConvertible {
2324
}
2425
}
2526

27+
extension SDLError: CustomDebugStringConvertible {
28+
29+
public var debugDescription: String {
30+
31+
var description = errorMessage
32+
if let debugInformation = debugInformation {
33+
description += " " + "(\(debugInformation.description))"
34+
}
35+
return description
36+
}
37+
}
38+
2639
internal extension SDLError {
2740

2841
final class DebugInformation: CustomStringConvertible {
@@ -46,12 +59,10 @@ internal extension SDLError {
4659
self.type = String(reflecting: type)
4760
}
4861

49-
public lazy var description: String = {
50-
51-
return [file, line.description, type, function]
52-
.compactMap { $0 }
53-
.reduce("") { $0 + ($0.isEmpty ? "" : ":") + $1 }
54-
}()
62+
public var description: String {
63+
let fileName = file.components(separatedBy: "/").last ?? file
64+
return "\(fileName):\(line.description) \(type).\(function)"
65+
}
5566
}
5667
}
5768

Sources/SDLDemo/main.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,11 @@ func main() throws {
107107
}
108108

109109
do { try main() }
110+
catch let error as SDLError {
111+
print("Error: \(error.debugDescription)")
112+
exit(EXIT_FAILURE)
113+
}
110114
catch {
111115
print("Error: \(error)")
112-
dump(error)
113116
exit(EXIT_FAILURE)
114117
}

0 commit comments

Comments
 (0)