Skip to content

Commit

Permalink
Give better names for invalid pipelines errors (#1805)
Browse files Browse the repository at this point in the history
If a pipeline didn't have a name, we would just call it "" in a warning,
which wasn't super helpful, instead we'll default name -> uses -> index
if the previous option doesn't exist.

This also gives more context on which pipeline failed to validate when
dealing with recursive pipelines.

Signed-off-by: Jon Johnson <jon.johnson@chainguard.dev>
  • Loading branch information
jonjohnsonjr authored Feb 21, 2025
1 parent f519133 commit 61a5936
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1563,9 +1563,21 @@ func (cfg Configuration) validate(ctx context.Context) error {
return nil
}

func pipelineName(p Pipeline, i int) string {
if p.Name != "" {
return strconv.Quote(p.Name)
}

if p.Uses != "" {
return strconv.Quote(p.Uses)
}

return fmt.Sprintf("[%d]", i)
}

func validatePipelines(ctx context.Context, ps []Pipeline) error {
log := clog.FromContext(ctx)
for _, p := range ps {
for i, p := range ps {
if p.With != nil && p.Uses == "" {
return fmt.Errorf("pipeline contains with but no uses")
}
Expand All @@ -1575,15 +1587,15 @@ func validatePipelines(ctx context.Context, ps []Pipeline) error {
}

if p.Uses != "" && len(p.Pipeline) > 0 {
log.Warnf("pipeline %q contains both uses and a pipeline", p.Name)
log.Warnf("pipeline %s contains both uses and a pipeline", pipelineName(p, i))
}

if len(p.With) > 0 && p.Runs != "" {
return fmt.Errorf("pipeline cannot contain both with and runs")
}

if err := validatePipelines(ctx, p.Pipeline); err != nil {
return err
return fmt.Errorf("validating pipeline %s children: %w", pipelineName(p, i), err)
}
}
return nil
Expand Down

0 comments on commit 61a5936

Please sign in to comment.