Skip to content

Commit

Permalink
chore: improved logging and added stack trace if --log-level=trace is…
Browse files Browse the repository at this point in the history
… used (#138)
  • Loading branch information
lindell authored Jun 14, 2021
1 parent 7c719c0 commit abccc5f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
15 changes: 14 additions & 1 deletion internal/multigitter/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,15 @@ func (pr dryRunPullRequest) String() string {
return fmt.Sprintf("%s #0", pr.Repository.FullName())
}

type stackTracer interface {
StackTrace() errors.StackTrace
}

// Run runs a script for multiple repositories and creates PRs with the changes made
func (r Runner) Run(ctx context.Context) error {
repos, err := r.VersionController.GetRepositories(ctx)
if err != nil {
return err
return errors.Wrap(err, "could not fetch repositories")
}

rc := repocounter.NewCounter()
Expand Down Expand Up @@ -104,6 +108,15 @@ func (r Runner) Run(ctx context.Context) error {
logger.Info(err)
}
rc.AddError(err, repos[i])
if log.IsLevelEnabled(log.TraceLevel) {
if err, ok := err.(stackTracer); ok {
trace := ""
for _, f := range err.StackTrace() {
trace += fmt.Sprintf("%+s:%d\n", f, f)
}
log.Trace(trace)
}
}
return
}

Expand Down
11 changes: 8 additions & 3 deletions internal/scm/github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ type RepositoryReference struct {
Name string
}

// String returns the string representation of a repo reference
func (rr RepositoryReference) String() string {
return fmt.Sprintf("%s/%s", rr.OwnerName, rr.Name)
}

type repository struct {
url url.URL
name string
Expand Down Expand Up @@ -169,23 +174,23 @@ func (g Github) getRepositories(ctx context.Context) ([]*github.Repository, erro
for _, org := range g.Organizations {
repos, err := g.getOrganizationRepositories(ctx, org)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "could not get organization repositories for %s", org)
}
allRepos = append(allRepos, repos...)
}

for _, user := range g.Users {
repos, err := g.getUserRepositories(ctx, user)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "could not get user repositories for %s", user)
}
allRepos = append(allRepos, repos...)
}

for _, repoRef := range g.Repositories {
repo, err := g.getRepository(ctx, repoRef)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "could not get information about %s", repoRef.String())
}
allRepos = append(allRepos, repo)
}
Expand Down

0 comments on commit abccc5f

Please sign in to comment.