@@ -52,40 +52,50 @@ extension Color {
5252}
5353
5454public enum GateEngineError : Error , Equatable , Hashable , CustomStringConvertible {
55- case failedToLocate
56- case failedToLoad( _ reason: String )
55+ /// An error to represent any kind of error
56+ case custom( _ errorName: String , _ description: String )
57+
58+ case failedToLocate( resource: String , _ reason: String ? )
59+ case failedToLoad( resource: String , _ reason: String ? )
5760 case failedToDecode( _ reason: String )
5861 case failedToEncode( _ reason: String )
59-
62+
6063 case scriptCompileError( _ reason: String )
6164 case scriptExecutionError( _ reason: String )
6265
63- case generic( _ description: String )
64-
65- case layoutFailed( _ description: String )
66+ case uiLayoutFailed( _ description: String )
6667
6768 case failedToCreateWindow( _ reason: String )
6869
6970 public var description : String {
7071 switch self {
71- case . failedToLocate:
72- return " failedToLocate "
73- case . failedToLoad( let reason) :
74- return " failedToLoad: \n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
72+ case . custom( let errorName, let reason) :
73+ return " \( errorName) : \n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
74+
75+ case . failedToLocate( let resource, let reason) :
76+ var error = " FailedToLocate: \( resource) "
77+ if let reason {
78+ error += " \n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
79+ }
80+ return error
81+ case . failedToLoad( let resource, let reason) :
82+ var error = " FailedToLoad: \( resource) "
83+ if let reason {
84+ error += " \n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
85+ }
86+ return error
7587 case . failedToDecode( let reason) :
76- return " failedToDecode :\n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
88+ return " FailedToDecode :\n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
7789 case . failedToEncode( let reason) :
78- return " failedToEncode :\n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
90+ return " FailedToEncode :\n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
7991 case . scriptCompileError( let reason) :
80- return " scriptCompileError :\n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
92+ return " ScriptCompileError :\n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
8193 case . scriptExecutionError( let reason) :
82- return " scriptExecutionError: \n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
83- case . generic( let reason) :
84- return reason
85- case . layoutFailed( let reason) :
86- return " layoutFailed: \n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
94+ return " ScriptExecutionError: \n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
95+ case . uiLayoutFailed( let reason) :
96+ return " UILayoutFailed: \n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
8797 case . failedToCreateWindow( let reason) :
88- return " failedToCreateWindow :\n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
98+ return " FailedToCreateWindow :\n \t " + reason. replacingOccurrences ( of: " \n " , with: " \n \t " )
8999 }
90100 }
91101
@@ -128,7 +138,7 @@ public enum GateEngineError: Error, Equatable, Hashable, CustomStringConvertible
128138
129139extension GateEngineError : ExpressibleByStringLiteral {
130140 public init ( stringLiteral value: StringLiteralType ) {
131- self = . generic ( value)
141+ self = . custom ( " error " , value)
132142 }
133143}
134144
0 commit comments