1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-07-05 00:59:04 +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()
p, res, err := c.client.GetRepo(repo.Owner, repo.Name)
if err != nil {
log.WithField("projectID", projectID).
WithField("statusCode", res.StatusCode).
WithError(err).
log := log.WithField("projectID", projectID)
if res != nil {
log = log.WithField("statusCode", res.StatusCode)
}
log.WithError(err).
Warn("error checking for default branch")
return "", err
}

View File

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

View File

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