Skip to content

Commit

Permalink
Refactor an error message
Browse files Browse the repository at this point in the history
  • Loading branch information
whywaita committed Dec 16, 2024
1 parent ec1c1f4 commit 8c50119
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions pkg/datastore/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,21 @@ func SearchRepo(ctx context.Context, ds Datastore, repo string) (*Target, error)
repoTarget, err := ds.GetTargetByScope(ctx, repo)
if err == nil && repoTarget.CanReceiveJob() {
return repoTarget, nil
} else if err != nil && err != ErrNotFound {
} else if err != nil && !errors.Is(err, ErrNotFound) {
return nil, fmt.Errorf("failed to get target from repo: %w", err)
}

// repo is not found, so search org target
org := sep[0]
orgTarget, err := ds.GetTargetByScope(ctx, org)
if err != nil || !orgTarget.CanReceiveJob() {
if err != nil {
return nil, fmt.Errorf("failed to get target from organization: %w", err)
}

if !orgTarget.CanReceiveJob() {
return nil, fmt.Errorf("target is not active")
}

return orgTarget, nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/metric/scrape_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func scrapePendingRuns(ctx context.Context, ds datastore.Datastore, ch chan<- pr
installationID := value.(int64)
target, err := datastore.SearchRepo(ctx, ds, repoName)
if err != nil {
logger.Logf(false, "failed to get target by scope (%s): %+v", repoName, err)
logger.Logf(false, "failed to scrape pending run: failed to get target by scope (%s): %+v", repoName, err)
return true
}
owner, repo := target.OwnerRepo()
Expand All @@ -74,7 +74,7 @@ func scrapePendingRuns(ctx context.Context, ds datastore.Datastore, ch chan<- pr
}
runs, err := gh.ListRuns(owner, repo)
if err != nil {
logger.Logf(false, "failed to list pending runs: %+v", err)
logger.Logf(false, "failed to scrape pending run: failed to list pending runs: %+v", err)
return true
}

Expand Down

0 comments on commit 8c50119

Please sign in to comment.