|
4 | 4 | "bytes"
|
5 | 5 | "fmt"
|
6 | 6 | "io/fs"
|
7 |
| - "path/filepath" |
8 | 7 |
|
9 | 8 | sitter "github.com/smacker/go-tree-sitter"
|
10 | 9 | )
|
@@ -58,52 +57,11 @@ func (e *ErrgoEngine) Analyze(workingPath, msg string) (*CompiledErrorTemplate,
|
58 | 57 | contextData.Analyzer = template.Language.AnalyzerFactory(contextData)
|
59 | 58 | contextData.AddVariable("message", msg)
|
60 | 59 |
|
61 |
| - groupNames := template.Pattern.SubexpNames() |
62 |
| - for _, submatches := range template.Pattern.FindAllStringSubmatch(msg, -1) { |
63 |
| - for idx, matchedContent := range submatches { |
64 |
| - if len(groupNames[idx]) == 0 { |
65 |
| - continue |
66 |
| - } |
67 |
| - |
68 |
| - contextData.AddVariable(groupNames[idx], matchedContent) |
69 |
| - } |
70 |
| - } |
| 60 | + // extract variables from the error message |
| 61 | + contextData.AddVariables(template.ExtractVariables(msg)) |
71 | 62 |
|
72 | 63 | // extract stack trace
|
73 |
| - rawStackTraceItem := contextData.Variables["stacktrace"] |
74 |
| - symbolGroupIdx := template.StackTraceRegex().SubexpIndex("symbol") |
75 |
| - pathGroupIdx := template.StackTraceRegex().SubexpIndex("path") |
76 |
| - posGroupIdx := template.StackTraceRegex().SubexpIndex("position") |
77 |
| - stackTraceMatches := template.StackTraceRegex().FindAllStringSubmatch(rawStackTraceItem, -1) |
78 |
| - |
79 |
| - for _, submatches := range stackTraceMatches { |
80 |
| - if len(submatches) == 0 { |
81 |
| - continue |
82 |
| - } |
83 |
| - |
84 |
| - rawSymbolName := "" |
85 |
| - if symbolGroupIdx != -1 { |
86 |
| - rawSymbolName = submatches[symbolGroupIdx] |
87 |
| - } |
88 |
| - rawPath := submatches[pathGroupIdx] |
89 |
| - rawPos := submatches[posGroupIdx] |
90 |
| - |
91 |
| - // convert relative paths to absolute for parsing |
92 |
| - if len(workingPath) != 0 && !filepath.IsAbs(rawPath) { |
93 |
| - rawPath = filepath.Clean(filepath.Join(workingPath, rawPath)) |
94 |
| - } |
95 |
| - |
96 |
| - stLoc := template.Language.LocationConverter(LocationConverterContext{ |
97 |
| - Path: rawPath, |
98 |
| - Pos: rawPos, |
99 |
| - ContextData: contextData, |
100 |
| - }) |
101 |
| - if contextData.TraceStack == nil { |
102 |
| - contextData.TraceStack = TraceStack{} |
103 |
| - } |
104 |
| - |
105 |
| - contextData.TraceStack.Add(rawSymbolName, stLoc) |
106 |
| - } |
| 64 | + contextData.TraceStack = template.ExtractStackTrace(contextData) |
107 | 65 |
|
108 | 66 | // open contents of the extracted stack file locations
|
109 | 67 | parser := sitter.NewParser()
|
|
0 commit comments