mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-07-05 02:57:41 +08:00
Merge pull request #2518 from daghack/handle-build-err-during-lint-request
update the lint subrequest call to error
This commit is contained in:
commit
8ca18dee2d
@ -866,7 +866,34 @@ func printResult(f *controllerapi.PrintFunc, res map[string]string) error {
|
|||||||
case "subrequests.describe":
|
case "subrequests.describe":
|
||||||
return printValue(subrequests.PrintDescribe, subrequests.SubrequestsDescribeDefinition.Version, f.Format, res)
|
return printValue(subrequests.PrintDescribe, subrequests.SubrequestsDescribeDefinition.Version, f.Format, res)
|
||||||
case "lint":
|
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 {
|
||||||
|
// Print the error message and the source
|
||||||
|
// Normally, we would use `errdefs.WithSource` to attach the source to the
|
||||||
|
// error and let the error be printed by the handling that's already in place,
|
||||||
|
// but here we want to print the error in a way that's consistent with how
|
||||||
|
// the lint warnings are printed via the `lint.PrintLintViolations` function,
|
||||||
|
// which differs from the default error printing.
|
||||||
|
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:
|
default:
|
||||||
if dt, ok := res["result.json"]; ok && f.Format == "json" {
|
if dt, ok := res["result.json"]; ok && f.Format == "json" {
|
||||||
fmt.Println(dt)
|
fmt.Println(dt)
|
||||||
|
@ -817,7 +817,7 @@ COPy --from=base \
|
|||||||
stderr := bytes.Buffer{}
|
stderr := bytes.Buffer{}
|
||||||
cmd.Stdout = &stdout
|
cmd.Stdout = &stdout
|
||||||
cmd.Stderr = &stderr
|
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
|
var res lint.LintResults
|
||||||
require.NoError(t, json.Unmarshal(stdout.Bytes(), &res))
|
require.NoError(t, json.Unmarshal(stdout.Bytes(), &res))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user