Skip to content

Commit

Permalink
update the lint subrequest call to error when a build error was encou…
Browse files Browse the repository at this point in the history
…ntered during linting

Signed-off-by: Talon Bowler <talon.bowler@docker.com>
(cherry picked from commit 927fb67)
  • Loading branch information
daghack authored and tonistiigi committed Jun 18, 2024
1 parent 2375e88 commit fe728e7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,28 @@ func printResult(f *controllerapi.PrintFunc, res map[string]string) error {
case "subrequests.describe":
return printValue(subrequests.PrintDescribe, subrequests.SubrequestsDescribeDefinition.Version, f.Format, res)
case "lint":
return printValue(lint.PrintLintViolations, lint.SubrequestLintDefinition.Version, f.Format, res)
err := printValue(lint.PrintLintViolations, lint.SubrequestLintDefinition.Version, f.Format, res)
if err != nil {
return err
}

lintResults := lint.LintResults{}
if result, ok := res["result.json"]; ok {
if err := json.Unmarshal([]byte(result), &lintResults); err != nil {
return err
}
}
if lintResults.Error != nil {
fmt.Println()
lintBuf := bytes.NewBuffer([]byte(lintResults.Error.Message + "\n"))
sourceInfo := lintResults.Sources[lintResults.Error.Location.SourceIndex]
source := errdefs.Source{
Info: sourceInfo,
Ranges: lintResults.Error.Location.Ranges,
}
source.Print(lintBuf)
return errors.New(lintBuf.String())
}
default:
if dt, ok := res["result.json"]; ok && f.Format == "json" {
fmt.Println(dt)
Expand Down
2 changes: 1 addition & 1 deletion tests/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ COPy --from=base \
stderr := bytes.Buffer{}
cmd.Stdout = &stdout
cmd.Stderr = &stderr
require.NoError(t, cmd.Run(), stdout.String(), stderr.String())
require.Error(t, cmd.Run(), stdout.String(), stderr.String())

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

0 comments on commit fe728e7

Please sign in to comment.