Skip to content

Commit

Permalink
Remove panic on errors; Add project and SHA info when no pipeline found
Browse files Browse the repository at this point in the history
  • Loading branch information
gregfurman committed Apr 27, 2024
1 parent 1563923 commit e85de89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/gateway/github_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (c *GitHubClient) GetPipelineBySha(id, sha string) (*Pipeline, error) {
}

if len(runs.WorkflowRuns) == 0 {
return nil, fmt.Errorf("no pipelines found")
return nil, fmt.Errorf("no pipelines found for project %s@%s", id, sha)
}

return workflowToPipeline(runs.WorkflowRuns[0]), nil
Expand Down
2 changes: 1 addition & 1 deletion internal/gateway/gitlab_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c *GitLabClient) GetPipelineBySha(id string, sha string) (*Pipeline, error
}

if len(pipelines) == 0 {
return nil, fmt.Errorf("no pipelines found")
return nil, fmt.Errorf("no pipelines found for project %s@%s", id, sha)
}

return &Pipeline{
Expand Down
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func main() {
// Define clients
gitClient, err := git.New(*fgitDirectoryLoc)
if err != nil {
panic(err)
exit(err)
}

var gatewayClient gateway.Client
Expand All @@ -45,15 +45,15 @@ func main() {
}

if err != nil {
panic(err)
exit(err)
}

// Define service
svc := checker.New(gatewayClient, gitClient)

// Run polling
if err := run(svc, *fpollFrequency); err != nil {
panic(err)
exit(err)
}

if *fplaySoundOnComplete {
Expand Down Expand Up @@ -102,3 +102,8 @@ func setFromEnv(name, defaultValue string) string {

return defaultValue
}

func exit(err error) {
slog.Error(err.Error())
os.Exit(1)
}

0 comments on commit e85de89

Please sign in to comment.