Skip to content

Commit

Permalink
fix: do not hide unparsable issues
Browse files Browse the repository at this point in the history
  • Loading branch information
twelvelabs committed Jun 1, 2023
1 parent 1a90cc5 commit ade3820
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
34 changes: 31 additions & 3 deletions internal/stylist/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"runtime"
"strings"
"time"

mapset "github.com/deckarep/golang-set/v2"
Expand Down Expand Up @@ -94,8 +95,9 @@ func (c *Command) executeBatch(
}
stderr := &bytes.Buffer{}
stdout := &bytes.Buffer{}
cmd.Stderr = stderr
cmd.Stdout = stdout
combined := &bytes.Buffer{}
cmd.Stderr = io.MultiWriter(stderr, combined)
cmd.Stdout = io.MultiWriter(stdout, combined)

logger.Debugln("Command:", cmd.String())

Expand Down Expand Up @@ -130,11 +132,36 @@ func (c *Command) executeBatch(
if err != nil {
return nil, err
}
if len(parsed) == 0 && output.ExitCode > 0 {
// The command didn't exit successfully, but we were unable
// to parse anything.
// We don't know which path triggered the issue,
// so return a result for each one w/ the combined output
// (likely containing an error message of some kind).
contextBody := ansiRegexp.ReplaceAllString(combined.String(), "")
contextLines := strings.Split(contextBody, "\n")
for _, path := range paths {
result := &Result{
Level: ResultLevelError,
Location: ResultLocation{
Path: path,
},
Rule: ResultRule{
Description: "Unknown issue",
},
ContextLang: "plaintext",
ContextLines: contextLines,
}
parsed = append(parsed, result)
}
}

// Do a little post processing on the results.
pathSet := mapset.NewSet(paths...)
transformed := []*Result{}
for _, r := range parsed {
for idx, r := range parsed {
logger.Debugf("Parsed[%v]: %#v", idx, r)

// Add the processor name to the results
r.Source = name
// InputTypeNone doesn't pass `paths` to the command, so there may
Expand All @@ -143,6 +170,7 @@ func (c *Command) executeBatch(
transformed = append(transformed, r)
}
}

return transformed, nil
}

Expand Down
16 changes: 15 additions & 1 deletion internal/stylist/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,21 @@ func TestPipeline_Check(t *testing.T) {
pathSpecs: []string{
"testdata/txt",
},
expected: []*Result{},
expected: []*Result{
{
Level: ResultLevelError,
Location: ResultLocation{
Path: "testdata/txt/ccc.txt",
},
Rule: ResultRule{
Description: "Unknown issue",
},
ContextLang: "plaintext",
ContextLines: []string{
"lint failure",
},
},
},
},
{
desc: "should return errors for any commands that fail unexpectedly",
Expand Down

0 comments on commit ade3820

Please sign in to comment.