1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-13 01:30:50 +02:00

fix: possible nil pointers on logs

refs https://github.com/goreleaser/goreleaser/pull/3966/files#r1460694856

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Carlos Alexandro Becker
2024-01-21 21:46:59 -03:00
parent ac398de727
commit 6097ea50f5
3 changed files with 39 additions and 26 deletions

View File

@ -96,9 +96,11 @@ func (c *giteaClient) getDefaultBranch(_ *context.Context, repo Repo) (string, e
projectID := repo.String() projectID := repo.String()
p, res, err := c.client.GetRepo(repo.Owner, repo.Name) p, res, err := c.client.GetRepo(repo.Owner, repo.Name)
if err != nil { if err != nil {
log.WithField("projectID", projectID). log := log.WithField("projectID", projectID)
WithField("statusCode", res.StatusCode). if res != nil {
WithError(err). log = log.WithField("statusCode", res.StatusCode)
}
log.WithError(err).
Warn("error checking for default branch") Warn("error checking for default branch")
return "", err return "", err
} }

View File

@ -132,8 +132,11 @@ func (c *githubClient) getDefaultBranch(ctx *context.Context, repo Repo) (string
c.checkRateLimit(ctx) c.checkRateLimit(ctx)
p, res, err := c.client.Repositories.Get(ctx, repo.Owner, repo.Name) p, res, err := c.client.Repositories.Get(ctx, repo.Owner, repo.Name)
if err != nil { if err != nil {
log.WithField("projectID", repo.String()). log := log.WithField("projectID", repo.String())
WithField("statusCode", res.StatusCode). if res != nil {
log = log.WithField("statusCode", res.StatusCode)
}
log.
WithError(err). WithError(err).
Warn("error checking for default branch") Warn("error checking for default branch")
return "", err return "", err

View File

@ -88,11 +88,11 @@ func (c *gitlabClient) getDefaultBranch(_ *context.Context, repo Repo) (string,
projectID := repo.String() projectID := repo.String()
p, res, err := c.client.Projects.GetProject(projectID, nil) p, res, err := c.client.Projects.GetProject(projectID, nil)
if err != nil { if err != nil {
log. log := log.WithField("projectID", projectID)
WithField("projectID", projectID). if res != nil {
WithField("statusCode", res.StatusCode). log = log.WithField("statusCode", res.StatusCode)
WithError(err). }
Warn("error checking for default branch") log.WithError(err).Warn("error checking for default branch")
return "", err return "", err
} }
return p.DefaultBranch, nil return p.DefaultBranch, nil
@ -182,12 +182,14 @@ func (c *gitlabClient) CreateFile(
_, res, err := c.client.RepositoryFiles.GetFile(repo.String(), fileName, opts) _, res, err := c.client.RepositoryFiles.GetFile(repo.String(), fileName, opts)
if err != nil && (res == nil || res.StatusCode != 404) { if err != nil && (res == nil || res.StatusCode != 404) {
log. log := log.
WithField("fileName", fileName). WithField("fileName", fileName).
WithField("ref", ref). WithField("ref", ref).
WithField("projectID", projectID). WithField("projectID", projectID)
WithField("statusCode", res.StatusCode). if res != nil {
WithError(err). log = log.WithField("statusCode", res.StatusCode)
}
log.WithError(err).
Error("error getting file for brew formula") Error("error getting file for brew formula")
return err return err
} }
@ -213,12 +215,14 @@ func (c *gitlabClient) CreateFile(
} }
fileInfo, res, err := c.client.RepositoryFiles.CreateFile(projectID, fileName, createOpts) fileInfo, res, err := c.client.RepositoryFiles.CreateFile(projectID, fileName, createOpts)
if err != nil { if err != nil {
log. log := log.
WithField("fileName", fileName). WithField("fileName", fileName).
WithField("branch", branch). WithField("branch", branch).
WithField("projectID", projectID). WithField("projectID", projectID)
WithField("statusCode", res.StatusCode). if res != nil {
WithError(err). log = log.WithField("statusCode", res.StatusCode)
}
log.WithError(err).
Error("error creating brew formula file") Error("error creating brew formula file")
return err return err
} }
@ -247,23 +251,27 @@ func (c *gitlabClient) CreateFile(
updateFileInfo, res, err := c.client.RepositoryFiles.UpdateFile(projectID, fileName, updateOpts) updateFileInfo, res, err := c.client.RepositoryFiles.UpdateFile(projectID, fileName, updateOpts)
if err != nil { if err != nil {
log. log := log.
WithField("fileName", fileName). WithField("fileName", fileName).
WithField("branch", branch). WithField("branch", branch).
WithField("projectID", projectID). WithField("projectID", projectID)
WithField("statusCode", res.StatusCode). if res != nil {
WithError(err). log = log.WithField("statusCode", res.StatusCode)
}
log.WithError(err).
Error("error updating brew formula file") Error("error updating brew formula file")
return err return err
} }
log. log := log.
WithField("fileName", fileName). WithField("fileName", fileName).
WithField("branch", branch). WithField("branch", branch).
WithField("projectID", projectID). WithField("projectID", projectID).
WithField("filePath", updateFileInfo.FilePath). WithField("filePath", updateFileInfo.FilePath)
WithField("statusCode", res.StatusCode). if res != nil {
Debug("updated brew formula file") log = log.WithField("statusCode", res.StatusCode)
}
log.Debug("updated brew formula file")
return nil return nil
} }