Skip to content

Commit e53ca36

Browse files
authored
Merge pull request #26 from gomicro/errors
errors
2 parents 61774d8 + 1e1ad11 commit e53ca36

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

client/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ func (c *Client) Apply() error {
8484
for _, fn := range c.stack {
8585
err := fn()
8686
if err != nil {
87-
return err
87+
report.PrintError(err.Error())
88+
report.Println()
8889
}
8990
}
9091

client/repos.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (c *Client) AddRepoToTeam(ctx context.Context, org, team, repo, perm string
192192
return ErrRepoNotFound
193193
}
194194

195-
return fmt.Errorf("add repo to team: %w", err)
195+
return fmt.Errorf("%s/%s: add repo to team: %w", org, repo, err)
196196
}
197197

198198
if relationExists {
@@ -225,7 +225,7 @@ func (c *Client) RemoveRepoFromTeam(ctx context.Context, org, team, repo string)
225225
return ErrRepoNotFound
226226
}
227227

228-
return fmt.Errorf("remove repo from team: %w", err)
228+
return fmt.Errorf("%s/%s: remove repo from team: %w", org, repo, err)
229229
}
230230

231231
cs.PrintPost()
@@ -336,7 +336,7 @@ func (c *Client) CreateRepo(ctx context.Context, org string, repo *github.Reposi
336336
return fmt.Errorf("github: hit rate limit")
337337
}
338338

339-
return fmt.Errorf("create repo: %w", err)
339+
return fmt.Errorf("%s/%s: create repo: %w", org, repo, err)
340340
}
341341

342342
cs.PrintPost()
@@ -389,7 +389,11 @@ func (c *Client) UpdateRepo(ctx context.Context, org, repo string, edits *github
389389
return ErrRepoNotFound
390390
}
391391

392-
return fmt.Errorf("update repo: %w", err)
392+
if resp.StatusCode == http.StatusForbidden && strings.Contains(err.Error(), "was archived so is read-only") {
393+
return fmt.Errorf("%s/%s: update repo: repo is archived", org, repo)
394+
}
395+
396+
return fmt.Errorf("%s/%s: update repo: %w", org, repo, err)
393397
}
394398

395399
cs.PrintPost()
@@ -416,7 +420,7 @@ func (c *Client) SetRepoTopics(ctx context.Context, org, repo string, topics []s
416420
return ErrRepoNotFound
417421
}
418422

419-
return fmt.Errorf("set repo topics: %w", err)
423+
return fmt.Errorf("%s/%s: set repo topics: %w", org, repo, err)
420424
}
421425

422426
cs.PrintPost()
@@ -489,7 +493,11 @@ func (c *Client) ProtectBranch(ctx context.Context, org, repo, branch string, pr
489493
return ErrBranchProtectionNotFound
490494
}
491495

492-
return fmt.Errorf("protect branch: %w", err)
496+
if resp.StatusCode == http.StatusForbidden && strings.Contains(err.Error(), "was archived so is read-only") {
497+
return fmt.Errorf("%s/%s: protect branch: repo is archived", org, repo)
498+
}
499+
500+
return fmt.Errorf("%s/%s: protect branch: %w", org, repo, err)
493501
}
494502

495503
cs.PrintPost()
@@ -536,7 +544,11 @@ func (c *Client) SetRequireSignedCommits(ctx context.Context, org, repo, branch
536544
return ErrBranchProtectionNotFound
537545
}
538546

539-
return fmt.Errorf("protect branch: set signature required: %w", err)
547+
if resp.StatusCode == http.StatusForbidden && strings.Contains(err.Error(), "was archived so is read-only") {
548+
return fmt.Errorf("%s/%s: protect branch: set signature required: repo is archived", org, repo)
549+
}
550+
551+
return fmt.Errorf("%s/%s: protect branch: set signature required: %w", org, repo, err)
540552
}
541553

542554
cs.PrintPost()

cmd/apply_repos.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func reposRun(cmd *cobra.Command, args []string) error {
126126

127127
err := ensureRepo(ctx, org.Name, r)
128128
if err != nil {
129-
return handleError(cmd, err)
129+
report.PrintError(err.Error())
130130
}
131131
}
132132
}

0 commit comments

Comments
 (0)