Skip to content

Commit

Permalink
Merge branch version/0-41-0-RC1 to adopt changes from PR #2737
Browse files Browse the repository at this point in the history
  • Loading branch information
as-builds committed Aug 30, 2023
2 parents 531f51d + a29a638 commit 3303387
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
5 changes: 5 additions & 0 deletions pkg/platform/api/buildplanner/model/buildplan.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (o *Operation) Unmarshal(v string) error {
}

type BuildPlannerError struct {
Err error
ValidationErrors []string
IsTransient bool
}
Expand All @@ -126,6 +127,10 @@ func (e *BuildPlannerError) UserError() string {
}

func (e *BuildPlannerError) Error() string {
if e.Err != nil {
return e.Err.Error()
}

// Append last five lines to error message
offset := 0
numLines := len(e.ValidationErrors)
Expand Down
4 changes: 2 additions & 2 deletions pkg/platform/model/buildplanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,10 @@ func processBuildPlannerError(bpErr error, fallbackMessage string) error {
if errors.As(bpErr, graphqlErr) {
code, ok := graphqlErr.Extensions[codeExtensionKey].(string)
if ok && code == clientDeprecationErrorKey {
return locale.NewInputError("err_buildplanner_deprecated", "Encountered deprecation error: {{.V0}}", graphqlErr.Message)
return &bpModel.BuildPlannerError{Err: locale.NewInputError("err_buildplanner_deprecated", "Encountered deprecation error: {{.V0}}", graphqlErr.Message)}
}
}
return errs.Wrap(bpErr, fallbackMessage)
return &bpModel.BuildPlannerError{Err: errs.Wrap(bpErr, fallbackMessage)}
}

var versionRe = regexp.MustCompile(`^\d+(\.\d+)*$`)
Expand Down
7 changes: 6 additions & 1 deletion pkg/platform/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (r *Runtime) recordCompletion(err error) {
errorType = "input"
case errs.Matches(err, &model.SolverError{}):
errorType = "solve"
case errs.Matches(err, &setup.BuildError{}) || errs.Matches(err, &buildlog.BuildError{}):
case errs.Matches(err, &setup.BuildError{}), errs.Matches(err, &buildlog.BuildError{}):
errorType = "build"
case errs.Matches(err, &bpModel.BuildPlannerError{}):
errorType = "buildplan"
Expand All @@ -259,13 +259,18 @@ func (r *Runtime) recordCompletion(err error) {
case errs.Matches(err, &setup.ArtifactInstallError{}):
errorType = "install"
// Note: do not break because there could be download errors, and those take precedence
case errs.Matches(err, &setup.BuildError{}), errs.Matches(err, &buildlog.BuildError{}):
errorType = "build"
break // it only takes one build failure to report the runtime failure as due to build error
}
}
}
// Progress/event handler errors should come last because they can wrap one of the above errors,
// and those errors actually caused the failure, not these.
case errs.Matches(err, &setup.ProgressReportError{}) || errs.Matches(err, &buildlog.EventHandlerError{}):
errorType = "progress"
case errs.Matches(err, &setup.ExecutorSetupError{}):
errorType = "postprocess"
}

var message string
Expand Down
16 changes: 13 additions & 3 deletions pkg/platform/runtime/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ type ArtifactSetupErrors struct {
errs []error
}

type ExecutorSetupError struct {
*errs.WrapperError
}

func (a *ArtifactSetupErrors) Error() string {
var errors []string
for _, err := range a.errs {
Expand Down Expand Up @@ -186,7 +190,7 @@ func (s *Setup) Update() (rerr error) {

// Update executors
if err := s.updateExecutors(artifacts); err != nil {
return errs.Wrap(err, "Failed to update executors")
return ExecutorSetupError{errs.Wrap(err, "Failed to update executors")}
}

// Mark installation as completed
Expand Down Expand Up @@ -752,12 +756,16 @@ func (s *Setup) moveToInstallPath(a artifact.ArtifactID, unpackedDir string, env
func (s *Setup) downloadArtifact(a artifact.ArtifactDownload, targetFile string) (rerr error) {
defer func() {
if rerr != nil {
rerr = &ArtifactDownloadError{errs.Wrap(rerr, "Unable to download artifact")}
if !errs.Matches(rerr, &ProgressReportError{}) {
rerr = &ArtifactDownloadError{errs.Wrap(rerr, "Unable to download artifact")}
}

if err := s.handleEvent(events.ArtifactDownloadFailure{a.ArtifactID, rerr}); err != nil {
rerr = errs.Wrap(rerr, "Could not handle ArtifactDownloadFailure event")
return
}
}

if err := s.handleEvent(events.ArtifactDownloadSuccess{a.ArtifactID}); err != nil {
rerr = errs.Wrap(rerr, "Could not handle ArtifactDownloadSuccess event")
return
Expand All @@ -772,7 +780,7 @@ func (s *Setup) downloadArtifact(a artifact.ArtifactDownload, targetFile string)
b, err := httputil.GetWithProgress(artifactURL.String(), &progress.Report{
ReportSizeCb: func(size int) error {
if err := s.handleEvent(events.ArtifactDownloadStarted{a.ArtifactID, size}); err != nil {
return errs.Wrap(err, "Could not handle ArtifactDownloadStarted event")
return ProgressReportError{errs.Wrap(err, "Could not handle ArtifactDownloadStarted event")}
}
return nil
},
Expand All @@ -786,9 +794,11 @@ func (s *Setup) downloadArtifact(a artifact.ArtifactDownload, targetFile string)
if err != nil {
return errs.Wrap(err, "Download %s failed", artifactURL.String())
}

if err := fileutils.WriteFile(targetFile, b); err != nil {
return errs.Wrap(err, "Writing download to target file %s failed", targetFile)
}

return nil
}

Expand Down

0 comments on commit 3303387

Please sign in to comment.