From 2d9c33dbce694562eb077da7b9e106a3d9838138 Mon Sep 17 00:00:00 2001 From: Ned Palacios Date: Mon, 25 Mar 2024 12:09:39 +0800 Subject: [PATCH] fix: return context data regardless of template matching result --- errgoengine.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/errgoengine.go b/errgoengine.go index 80c5f6c..211923a 100644 --- a/errgoengine.go +++ b/errgoengine.go @@ -49,16 +49,19 @@ func (e *ErrgoEngine) AttachMainFS(instance fs.ReadFileFS) { func (e *ErrgoEngine) Analyze(workingPath, msg string) (*CompiledErrorTemplate, *ContextData, error) { template := e.ErrorTemplates.Match(msg) - if template == nil { - return nil, nil, fmt.Errorf("template not found. \nMessage: %s", msg) - } // initial context data extraction contextData := NewContextData(e.SharedStore, workingPath) - contextData.Analyzer = template.Language.AnalyzerFactory(contextData) contextData.AddVariable("message", msg) contextData.FS = e.FS + // return context data if template is not found + if template == nil { + return nil, contextData, fmt.Errorf("template not found. \nMessage: %s", msg) + } + + contextData.Analyzer = template.Language.AnalyzerFactory(contextData) + // extract variables from the error message contextData.AddVariables(template.ExtractVariables(msg))