@@ -39,6 +39,9 @@ func (tmp *CompiledErrorTemplate) StackTraceRegex() *regexp.Regexp {
39
39
}
40
40
41
41
func (tmp * CompiledErrorTemplate ) ExtractVariables (msg string ) map [string ]string {
42
+ if tmp .Pattern == nil {
43
+ return map [string ]string {}
44
+ }
42
45
variables := map [string ]string {}
43
46
groupNames := tmp .Pattern .SubexpNames ()
44
47
for _ , submatches := range tmp .Pattern .FindAllStringSubmatch (msg , - 1 ) {
@@ -55,10 +58,13 @@ func (tmp *CompiledErrorTemplate) ExtractVariables(msg string) map[string]string
55
58
56
59
func (tmp * CompiledErrorTemplate ) ExtractStackTrace (cd * ContextData ) TraceStack {
57
60
traceStack := TraceStack {}
58
- workingPath := cd .WorkingPath
61
+ stackTraceRegex := tmp .StackTraceRegex ()
62
+ if stackTraceRegex == nil {
63
+ return traceStack
64
+ }
59
65
66
+ workingPath := cd .WorkingPath
60
67
rawStackTraceItem := cd .Variables ["stacktrace" ]
61
- stackTraceRegex := tmp .StackTraceRegex ()
62
68
symbolGroupIdx := stackTraceRegex .SubexpIndex ("symbol" )
63
69
pathGroupIdx := stackTraceRegex .SubexpIndex ("path" )
64
70
posGroupIdx := stackTraceRegex .SubexpIndex ("position" )
@@ -94,6 +100,9 @@ func (tmp *CompiledErrorTemplate) ExtractStackTrace(cd *ContextData) TraceStack
94
100
}
95
101
96
102
func (tmp * CompiledErrorTemplate ) Match (str string ) bool {
103
+ if tmp == FallbackErrorTemplate {
104
+ return true
105
+ }
97
106
return tmp .Pattern .MatchString (str )
98
107
}
99
108
@@ -187,5 +196,28 @@ func (tmps ErrorTemplates) Find(language, name string) *CompiledErrorTemplate {
187
196
}
188
197
189
198
func TemplateKey (language , name string ) string {
199
+ if len (language ) == 0 {
200
+ return name
201
+ }
190
202
return fmt .Sprintf ("%s.%s" , language , name )
191
203
}
204
+
205
+ var FallbackErrorTemplate = & CompiledErrorTemplate {
206
+ ErrorTemplate : ErrorTemplate {
207
+ Name : "UnknownError" ,
208
+ Pattern : `.*` ,
209
+ OnGenExplainFn : func (cd * ContextData , gen * ExplainGenerator ) {
210
+ gen .Add ("There are no available error templates for this error.\n " )
211
+ gen .Add ("```\n " )
212
+ gen .Add (cd .Variables ["message" ])
213
+ gen .Add ("\n ```" )
214
+ },
215
+ },
216
+ Language : & Language {
217
+ AnalyzerFactory : func (cd * ContextData ) LanguageAnalyzer {
218
+ return nil
219
+ },
220
+ },
221
+ Pattern : nil ,
222
+ StackTracePattern : nil ,
223
+ }
0 commit comments