Skip to content

Commit ad8fea1

Browse files
zakisksavitaashture
authored andcommitted
fix: Split error message of yaml validation on push
When a PipelineRun template in the .tekton/ directory contains a YAML syntax error, the error message was prefixed with a confusing "cannot locate templates in .tekton directory" message. This change ensures the error accurately reflects that a file was found but failed to parse, avoiding confusion between empty .tekton directory and a malformed one. Signed-off-by: Zaki Shaikh <[email protected]>
1 parent 86da7d4 commit ad8fea1

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

pkg/pipelineascode/match.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,23 @@ func (p *PacRun) getPipelineRunsFromRepo(ctx context.Context, repo *v1alpha1.Rep
192192

193193
return nil, err
194194
}
195+
196+
// This is for push event error logging because we can't create comment for yaml validation errors on push
195197
if err != nil || rawTemplates == "" {
196-
msg := fmt.Sprintf("cannot locate templates in %s/ directory for this repository in %s", tektonDir, p.event.HeadBranch)
198+
msg := ""
199+
reason := "RepositoryPipelineRunNotFound"
200+
logLevel := zap.InfoLevel
197201
if err != nil {
202+
reason = "RepositoryInvalidPipelineRunTemplate"
203+
logLevel = zap.ErrorLevel
204+
if strings.Contains(err.Error(), "error unmarshalling yaml file") {
205+
msg = "PipelineRun YAML validation"
206+
}
198207
msg += fmt.Sprintf(" err: %s", err.Error())
208+
} else {
209+
msg = fmt.Sprintf("cannot locate templates in %s/ directory for this repository in %s", tektonDir, p.event.HeadBranch)
199210
}
200-
p.eventEmitter.EmitMessage(nil, zap.InfoLevel, "RepositoryPipelineRunNotFound", msg)
211+
p.eventEmitter.EmitMessage(nil, logLevel, reason, msg)
201212
return nil, nil
202213
}
203214

0 commit comments

Comments
 (0)