Skip to content

Commit

Permalink
fix(server): fallback error template not returned, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nedpals committed Mar 14, 2024
1 parent 43165e8 commit 511edb1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions server/daemon/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ func (s *Server) collect(ctx context.Context, payload types.CollectPayload) (rec
result := helpers.AnalyzeError(s.engine, payload.WorkingDir, payload.Error)
r, p, err := result.Stats()
s.ServerLog.Printf("collect: %d recognized, %d processed\n", r, p)

// if payload has zero error code and error message, then it is successful
if len(payload.Error) == 0 && payload.ErrorCode < 1 {
s.notifyErrors(ctx, []resultError{
{
Expand Down
10 changes: 7 additions & 3 deletions server/helpers/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package helpers

import (
"io/fs"
"strings"

eg "github.com/nedpals/errgoengine"
"github.com/nedpals/errgoengine/error_templates"
Expand All @@ -26,8 +27,8 @@ func DefaultEngine() *eg.ErrgoEngine {
type AnalyzerResult struct {
Template *eg.CompiledErrorTemplate
Data *eg.ContextData
Exp string
Output string
Exp string // main explanation
Output string // full explanation / output
Err error
}

Expand All @@ -39,10 +40,12 @@ func GetAnalyzerStats(template *eg.CompiledErrorTemplate, exp string, err error)
recognized := 0
processed := 0

// mark as recognized if the template is not nil and not the fallback error template
if template != nil && template != eg.FallbackErrorTemplate {
recognized++
}

// mark as processed if the error is nil and the exp is not empty
if err == nil && len(exp) > 0 {
processed++
}
Expand All @@ -64,7 +67,8 @@ func AnalyzeError(engine *eg.ErrgoEngine, workingDir string, msg string) (res An
res.Err = err

if err != nil {
if err.Error() == "template not found" {
// return fallback error template if there is no template found
if t == nil && strings.HasPrefix(err.Error(), "template not found") {
t = eg.FallbackErrorTemplate
} else {
return
Expand Down

0 comments on commit 511edb1

Please sign in to comment.