Skip to content

Commit 1141cfa

Browse files
aThorp96chmouel
authored andcommitted
fix: Improve error messaging during repository/event validation
Since errors returned from `PacRun.matchRepoPR` are emitted as an event to end-users, the error messaging is important to enable users to self-service when possible. This improves error messaging by wrapping certain errors with additional context. E.g. parsing the owners file previously may have errored with the message: `error unmarshaling JSON: error decoding JSON: ...` After this change, the error is wrapped with a more helpful message: `Cannot parse OWNERS file Approvers and Reviewers: error unmarshaling JSON: ...` Addresses https://issues.redhat.com/browse/SRVKP-7322
1 parent 6f8a9e5 commit 1141cfa

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

pkg/acl/owners.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package acl
22

33
import (
4+
"fmt"
5+
46
"sigs.k8s.io/yaml"
57
)
68

@@ -28,15 +30,15 @@ func UserInOwnerFile(ownersContent, ownersAliasesContent, sender string) (bool,
2830
ac := aliasesConfig{}
2931
err := yaml.Unmarshal([]byte(ownersContent), &sc)
3032
if err != nil {
31-
return false, err
33+
return false, fmt.Errorf("cannot parse OWNERS file Approvers and Reviewers: %w", err)
3234
}
3335
err = yaml.Unmarshal([]byte(ownersContent), &fc)
3436
if err != nil {
35-
return false, err
37+
return false, fmt.Errorf("cannot parse OWNERS file Filters: %w", err)
3638
}
3739
err = yaml.Unmarshal([]byte(ownersAliasesContent), &ac)
3840
if err != nil {
39-
return false, err
41+
return false, fmt.Errorf("cannot parse OWNERS_ALIASES: %w", err)
4042
}
4143

4244
var approvers, reviewers []string

pkg/pipelineascode/match.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (p *PacRun) verifyRepoAndUser(ctx context.Context) (*v1alpha1.Repository, e
4747
// Match the Event URL to a Repository URL,
4848
repo, err := matcher.MatchEventURLRepo(ctx, p.run, p.event, "")
4949
if err != nil {
50-
return nil, err
50+
return nil, fmt.Errorf("error matching Repository for event: %w", err)
5151
}
5252

5353
if repo == nil {
@@ -405,7 +405,7 @@ func (p *PacRun) checkNeedUpdate(_ string) (string, bool) {
405405
func (p *PacRun) checkAccessOrErrror(ctx context.Context, repo *v1alpha1.Repository, status provider.StatusOpts, viamsg string) (bool, error) {
406406
allowed, err := p.vcx.IsAllowed(ctx, p.event)
407407
if err != nil {
408-
return false, err
408+
return false, fmt.Errorf("unable to verify event authorization: %w", err)
409409
}
410410
if allowed {
411411
return true, nil

0 commit comments

Comments
 (0)