Skip to content

Commit 8ca18de

Browse files
authored
Merge pull request #2518 from daghack/handle-build-err-during-lint-request
update the lint subrequest call to error
2 parents 917d2f4 + 366328b commit 8ca18de

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

commands/build.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,34 @@ func printResult(f *controllerapi.PrintFunc, res map[string]string) error {
866866
case "subrequests.describe":
867867
return printValue(subrequests.PrintDescribe, subrequests.SubrequestsDescribeDefinition.Version, f.Format, res)
868868
case "lint":
869-
return printValue(lint.PrintLintViolations, lint.SubrequestLintDefinition.Version, f.Format, res)
869+
err := printValue(lint.PrintLintViolations, lint.SubrequestLintDefinition.Version, f.Format, res)
870+
if err != nil {
871+
return err
872+
}
873+
874+
lintResults := lint.LintResults{}
875+
if result, ok := res["result.json"]; ok {
876+
if err := json.Unmarshal([]byte(result), &lintResults); err != nil {
877+
return err
878+
}
879+
}
880+
if lintResults.Error != nil {
881+
// Print the error message and the source
882+
// Normally, we would use `errdefs.WithSource` to attach the source to the
883+
// error and let the error be printed by the handling that's already in place,
884+
// but here we want to print the error in a way that's consistent with how
885+
// the lint warnings are printed via the `lint.PrintLintViolations` function,
886+
// which differs from the default error printing.
887+
fmt.Println()
888+
lintBuf := bytes.NewBuffer([]byte(lintResults.Error.Message + "\n"))
889+
sourceInfo := lintResults.Sources[lintResults.Error.Location.SourceIndex]
890+
source := errdefs.Source{
891+
Info: sourceInfo,
892+
Ranges: lintResults.Error.Location.Ranges,
893+
}
894+
source.Print(lintBuf)
895+
return errors.New(lintBuf.String())
896+
}
870897
default:
871898
if dt, ok := res["result.json"]; ok && f.Format == "json" {
872899
fmt.Println(dt)

tests/build.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ COPy --from=base \
817817
stderr := bytes.Buffer{}
818818
cmd.Stdout = &stdout
819819
cmd.Stderr = &stderr
820-
require.NoError(t, cmd.Run(), stdout.String(), stderr.String())
820+
require.Error(t, cmd.Run(), stdout.String(), stderr.String())
821821

822822
var res lint.LintResults
823823
require.NoError(t, json.Unmarshal(stdout.Bytes(), &res))

0 commit comments

Comments
 (0)