Skip to content

Commit

Permalink
Merge branch 'main' into log-rm-err
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 authored Jan 10, 2024
2 parents 40d5195 + 00df53e commit 736e196
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 47 deletions.
14 changes: 7 additions & 7 deletions agent/rpc/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (c *client) Next(ctx context.Context, f rpc.Filter) (*rpc.Workflow, error)
// https://github.com/woodpecker-ci/woodpecker/issues/717#issuecomment-1049365104
log.Trace().Err(err).Msg("grpc: to many keepalive pings without sending data")
} else {
log.Err(err).Msgf("grpc error: done(): code: %v: %s", status.Code(err), err)
log.Error().Err(err).Msgf("grpc error: done(): code: %v", status.Code(err))
}

switch status.Code(err) {
Expand Down Expand Up @@ -136,7 +136,7 @@ func (c *client) Wait(ctx context.Context, id string) (err error) {
break
}

log.Err(err).Msgf("grpc error: wait(): code: %v: %s", status.Code(err), err)
log.Error().Err(err).Msgf("grpc error: wait(): code: %v", status.Code(err))

switch status.Code(err) {
case
Expand Down Expand Up @@ -177,7 +177,7 @@ func (c *client) Init(ctx context.Context, id string, state rpc.State) (err erro
break
}

log.Err(err).Msgf("grpc error: init(): code: %v: %s", status.Code(err), err)
log.Error().Err(err).Msgf("grpc error: init(): code: %v", status.Code(err))

switch status.Code(err) {
case
Expand Down Expand Up @@ -218,7 +218,7 @@ func (c *client) Done(ctx context.Context, id string, state rpc.State) (err erro
break
}

log.Err(err).Msgf("grpc error: done(): code: %v: %s", status.Code(err), err)
log.Error().Err(err).Msgf("grpc error: done(): code: %v", status.Code(err))

switch status.Code(err) {
case
Expand Down Expand Up @@ -252,7 +252,7 @@ func (c *client) Extend(ctx context.Context, id string) (err error) {
break
}

log.Err(err).Msgf("grpc error: extend(): code: %v: %s", status.Code(err), err)
log.Error().Err(err).Msgf("grpc error: extend(): code: %v", status.Code(err))

switch status.Code(err) {
case
Expand Down Expand Up @@ -293,7 +293,7 @@ func (c *client) Update(ctx context.Context, id string, state rpc.State) (err er
break
}

log.Err(err).Msgf("grpc error: update(): code: %v: %s", status.Code(err), err)
log.Error().Err(err).Msgf("grpc error: update(): code: %v", status.Code(err))

switch status.Code(err) {
case
Expand Down Expand Up @@ -332,7 +332,7 @@ func (c *client) Log(ctx context.Context, logEntry *rpc.LogEntry) (err error) {
break
}

log.Err(err).Msgf("grpc error: log(): code: %v: %s", status.Code(err), err)
log.Error().Err(err).Msgf("grpc error: log(): code: %v", status.Code(err))

switch status.Code(err) {
case
Expand Down
6 changes: 3 additions & 3 deletions cli/internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ func NewClient(c *cli.Context) (woodpecker.Client, error) {
// if no server url is provided we can default
// to the hosted Woodpecker service.
if len(server) == 0 {
return nil, fmt.Errorf("Error: you must provide the Woodpecker server address")
return nil, fmt.Errorf("you must provide the Woodpecker server address")
}
if len(token) == 0 {
return nil, fmt.Errorf("Error: you must provide your Woodpecker access token")
return nil, fmt.Errorf("you must provide your Woodpecker access token")
}

// attempt to find system CA certs
certs, err := x509.SystemCertPool()
if err != nil {
log.Error().Msgf("failed to find system CA certs: %v", err)
log.Error().Err(err).Msg("failed to find system CA certs")
}
tlsConfig := &tls.Config{
RootCAs: certs,
Expand Down
4 changes: 2 additions & 2 deletions cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func run(c *cli.Context) error {
if c.Bool("healthcheck") {
go func() {
if err := http.ListenAndServe(c.String("healthcheck-addr"), nil); err != nil {
log.Error().Msgf("cannot listen on address %s: %v", c.String("healthcheck-addr"), err)
log.Error().Err(err).Msgf("cannot listen on address %s", c.String("healthcheck-addr"))
}
}()
}
Expand Down Expand Up @@ -210,7 +210,7 @@ func run(c *cli.Context) error {

err := client.ReportHealth(ctx)
if err != nil {
log.Err(err).Msgf("Failed to report health")
log.Err(err).Msg("Failed to report health")
return
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func setupStore(c *cli.Context) (store.Store, error) {

if driver == "sqlite3" {
if datastore.SupportedDriver("sqlite3") {
log.Debug().Msgf("server has sqlite3 support")
log.Debug().Msg("server has sqlite3 support")
} else {
log.Debug().Msgf("server was built without sqlite3 support!")
log.Debug().Msg("server was built without sqlite3 support!")
}
}

Expand Down
4 changes: 2 additions & 2 deletions pipeline/backend/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ func configFromCliContext(ctx context.Context) (*config, error) {
// Unmarshal label and annotation settings here to ensure they're valid on startup
if labels := c.String("backend-k8s-pod-labels"); labels != "" {
if err := yaml.Unmarshal([]byte(labels), &config.PodLabels); err != nil {
log.Error().Msgf("could not unmarshal pod labels '%s': %s", c.String("backend-k8s-pod-labels"), err)
log.Error().Err(err).Msgf("could not unmarshal pod labels '%s'", c.String("backend-k8s-pod-labels"))
return nil, err
}
}
if annotations := c.String("backend-k8s-pod-annotations"); annotations != "" {
if err := yaml.Unmarshal([]byte(c.String("backend-k8s-pod-annotations")), &config.PodAnnotations); err != nil {
log.Error().Msgf("could not unmarshal pod annotations '%s': %s", c.String("backend-k8s-pod-annotations"), err)
log.Error().Err(err).Msgf("could not unmarshal pod annotations '%s'", c.String("backend-k8s-pod-annotations"))
return nil, err
}
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/backend/kubernetes/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func resourceList(resources map[string]string) (v1.ResourceList, error) {
resName := v1.ResourceName(key)
resVal, err := resource.ParseQuantity(val)
if err != nil {
return nil, fmt.Errorf("resource request '%v' quantity '%v': %w", key, val, err)
return nil, fmt.Errorf("resource request '%s' quantity '%s': %w", key, val, err)
}
requestResources[resName] = resVal
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/backend/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func (e *local) DestroyStep(_ context.Context, _ *types.Step, _ string) error {

// DestroyWorkflow the pipeline environment.
func (e *local) DestroyWorkflow(_ context.Context, _ *types.Config, taskUUID string) error {
log.Trace().Str("taskUUID", taskUUID).Msgf("delete workflow environment")
log.Trace().Str("taskUUID", taskUUID).Msg("delete workflow environment")

state, err := e.getState(taskUUID)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions server/api/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ func HandleAuth(c *gin.Context) {
_store := store.FromContext(c)
_forge := server.Config.Services.Forge

// when dealing with redirects we may need to adjust the content type. I
// when dealing with redirects, we may need to adjust the content type. I
// cannot, however, remember why, so need to revisit this line.
c.Writer.Header().Del("Content-Type")

tmpuser, err := _forge.Login(c, c.Writer, c.Request)
if err != nil {
log.Error().Msgf("cannot authenticate user. %s", err)
log.Error().Err(err).Msg("cannot authenticate user")
c.Redirect(http.StatusSeeOther, server.Config.Server.RootPath+"/login?error=oauth_error")
return
}
// this will happen when the user is redirected by the forge as
// this will happen when the forge redirects the user as
// part of the authorization workflow.
if tmpuser == nil {
return
Expand Down Expand Up @@ -101,7 +101,7 @@ func HandleAuth(c *gin.Context) {

// insert the user into the database
if err := _store.CreateUser(u); err != nil {
log.Error().Msgf("cannot insert %s. %s", u.Login, err)
log.Error().Err(err).Msgf("cannot insert %s", u.Login)
c.Redirect(http.StatusSeeOther, server.Config.Server.RootPath+"/login?error=internal_error")
return
}
Expand Down Expand Up @@ -137,15 +137,15 @@ func HandleAuth(c *gin.Context) {
}

if err := _store.UpdateUser(u); err != nil {
log.Error().Msgf("cannot update %s. %s", u.Login, err)
log.Error().Err(err).Msgf("cannot update %s", u.Login)
c.Redirect(http.StatusSeeOther, server.Config.Server.RootPath+"/login?error=internal_error")
return
}

exp := time.Now().Add(server.Config.Server.SessionExpires).Unix()
tokenString, err := token.New(token.SessToken, u.Login).SignExpires(u.Hash, exp)
if err != nil {
log.Error().Msgf("cannot create token for %s. %s", u.Login, err)
log.Error().Msgf("cannot create token for %s", u.Login)
c.Redirect(http.StatusSeeOther, server.Config.Server.RootPath+"/login?error=internal_error")
return
}
Expand All @@ -157,7 +157,7 @@ func HandleAuth(c *gin.Context) {
continue
}
if err != nil {
log.Error().Msgf("cannot list repos for %s. %s", u.Login, err)
log.Error().Err(err).Msgf("cannot list repos for %s", u.Login)
c.Redirect(http.StatusSeeOther, "/login?error=internal_error")
return
}
Expand All @@ -173,7 +173,7 @@ func HandleAuth(c *gin.Context) {
perm.UserID = u.ID
perm.Synced = time.Now().Unix()
if err := _store.PermUpsert(perm); err != nil {
log.Error().Msgf("cannot update permissions for %s. %s", u.Login, err)
log.Error().Err(err).Msgf("cannot update permissions for %s", u.Login)
c.Redirect(http.StatusSeeOther, "/login?error=internal_error")
return
}
Expand Down
2 changes: 1 addition & 1 deletion server/api/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func LookupOrg(c *gin.Context) {
} else if !user.Admin {
perm, err := server.Config.Services.Membership.Get(c, user, org.Name)
if err != nil {
log.Error().Msgf("Failed to check membership: %v", err)
log.Error().Err(err).Msg("Failed to check membership")
c.Status(http.StatusInternalServerError)
return
}
Expand Down
2 changes: 1 addition & 1 deletion server/api/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ func repairRepo(c *gin.Context, repo *model.Repo, withPerms, skipOnErr bool) {
if !skipOnErr {
c.AbortWithStatus(http.StatusNotFound)
}
log.Error().Err(err).Msgf("could not get user on repo repair")
log.Error().Err(err).Msg("could not get user on repo repair")
} else {
_ = c.AbortWithError(http.StatusInternalServerError, err)
}
Expand Down
8 changes: 4 additions & 4 deletions server/api/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func LogStreamSSE(c *gin.Context) {
}
pl, err := _store.GetPipelineNumber(repo, pipeline)
if err != nil {
log.Debug().Msgf("stream cannot get pipeline number: %v", err)
log.Debug().Err(err).Msg("stream cannot get pipeline number")
logWriteStringErr(io.WriteString(rw, "event: error\ndata: pipeline not found\n\n"))
return
}
Expand All @@ -173,7 +173,7 @@ func LogStreamSSE(c *gin.Context) {
}
step, err := _store.StepLoad(stepID)
if err != nil {
log.Debug().Msgf("stream cannot get step number: %v", err)
log.Debug().Err(err).Msg("stream cannot get step number")
logWriteStringErr(io.WriteString(rw, "event: error\ndata: process not found\n\n"))
return
}
Expand All @@ -197,12 +197,12 @@ func LogStreamSSE(c *gin.Context) {
context.Background(),
)

log.Debug().Msgf("log stream: connection opened")
log.Debug().Msg("log stream: connection opened")

defer func() {
cancel(nil)
close(logc)
log.Debug().Msgf("log stream: connection closed")
log.Debug().Msg("log stream: connection closed")
}()

go func() {
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/auth_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (s *WoodpeckerAuthServer) getAgent(agentID int64, agentToken string) (*mode
agent.Capacity = -1
err := s.store.AgentCreate(agent)
if err != nil {
log.Err(err).Msgf("Error creating system agent: %s", err)
log.Error().Err(err).Msg("Error creating system agent")
return nil, err
}
return agent, nil
Expand Down
2 changes: 1 addition & 1 deletion server/grpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (s *RPC) Init(c context.Context, id string, state rpc.State) error {
Pipeline: *currentPipeline,
})
if err != nil {
log.Error().Err(err).Msgf("could not marshal JSON")
log.Error().Err(err).Msg("could not marshal JSON")
return
}
s.pubsub.Publish(message)
Expand Down
5 changes: 2 additions & 3 deletions server/pipeline/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ func Restart(ctx context.Context, store store.Store, lastPipeline *model.Pipelin
// fetch the old pipeline config from the database
configs, err := store.ConfigsForPipeline(lastPipeline.ID)
if err != nil {
msg := fmt.Sprintf("failure to get pipeline config for %s. %s", repo.FullName, err)
log.Error().Msgf(msg)
return nil, &ErrNotFound{Msg: msg}
log.Error().Err(err).Msgf("failure to get pipeline config for %s", repo.FullName)
return nil, &ErrNotFound{Msg: fmt.Sprintf("failure to get pipeline config for %s. %s", repo.FullName, err)}
}

for _, y := range configs {
Expand Down
2 changes: 1 addition & 1 deletion server/plugins/encryption/tink_keyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (svc *tinkEncryptionService) loadKeyset() error {
defer func(file *os.File) {
err = file.Close()
if err != nil {
log.Err(err).Msgf(logTemplateTinkFailedClosingKeysetFile, svc.keysetFilePath)
log.Error().Err(err).Msgf(logTemplateTinkFailedClosingKeysetFile, svc.keysetFilePath)
}
}(file)

Expand Down
4 changes: 2 additions & 2 deletions server/plugins/encryption/tink_keyset_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ func (svc *tinkEncryptionService) handleFileEvents() {
log.Warn().Msgf(logTemplateTinkKeysetFileChanged, event.Name)
err := svc.rotate()
if err != nil {
log.Fatal().Err(err).Msgf(errMessageFailedRotatingEncryption) //nolint:forbidigo
log.Fatal().Err(err).Msg(errMessageFailedRotatingEncryption) //nolint:forbidigo
}
return
}
case err, ok := <-svc.keysetFileWatcher.Errors:
if !ok {
log.Fatal().Err(err).Msgf(errMessageTinkKeysetFileWatchFailed) //nolint:forbidigo
log.Fatal().Err(err).Msg(errMessageTinkKeysetFileWatchFailed) //nolint:forbidigo
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/queue/persistent.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (q *persistentQueue) Poll(c context.Context, agentID int64, f FilterFn) (*m
if task != nil {
log.Debug().Msgf("pull queue item: %s: remove from backup", task.ID)
if derr := q.store.TaskDelete(task.ID); derr != nil {
log.Error().Msgf("pull queue item: %s: failed to remove from backup: %s", task.ID, derr)
log.Error().Err(derr).Msgf("pull queue item: %s: failed to remove from backup", task.ID)
} else {
log.Debug().Msgf("pull queue item: %s: successfully removed from backup", task.ID)
}
Expand Down
7 changes: 4 additions & 3 deletions server/router/middleware/session/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/gin-gonic/gin"
"github.com/rs/zerolog/log"

"go.woodpecker-ci.org/woodpecker/v2/server"

"go.woodpecker-ci.org/woodpecker/v2/server/model"
Expand Down Expand Up @@ -73,7 +74,7 @@ func SetRepo() gin.HandlerFunc {
}

// debugging
log.Debug().Err(err).Msgf("Cannot find repository %s.", fullName)
log.Debug().Err(err).Msgf("Cannot find repository %s", fullName)

if user == nil {
c.AbortWithStatus(http.StatusUnauthorized)
Expand Down Expand Up @@ -112,8 +113,8 @@ func SetPerm() gin.HandlerFunc {
var err error
perm, err = _store.PermFind(user, repo)
if err != nil {
log.Error().Msgf("Error fetching permission for %s %s. %s",
user.Login, repo.FullName, err)
log.Error().Err(err).Msgf("Error fetching permission for %s %s",
user.Login, repo.FullName)
}
if time.Unix(perm.Synced, 0).Add(time.Hour).Before(time.Now()) {
_repo, err := server.Config.Services.Forge.Repo(c, user, repo.ForgeRemoteID, repo.Owner, repo.Name)
Expand Down
2 changes: 1 addition & 1 deletion server/router/middleware/session/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func MustOrgMember(admin bool) gin.HandlerFunc {

perm, err := server.Config.Services.Membership.Get(c, user, org.Name)
if err != nil {
log.Error().Msgf("Failed to check membership: %v", err)
log.Error().Err(err).Msg("Failed to check membership")
c.String(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError))
c.Abort()
return
Expand Down
4 changes: 2 additions & 2 deletions server/web/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func Config(c *gin.Context) {
"json": func(v any) string {
a, err := json.Marshal(v)
if err != nil {
log.Error().Err(err).Msgf("could not marshal JSON")
log.Error().Err(err).Msg("could not marshal JSON")
return ""
}
return string(a)
Expand All @@ -65,7 +65,7 @@ func Config(c *gin.Context) {
tmpl := template.Must(template.New("").Funcs(funcMap).Parse(configTemplate))

if err := tmpl.Execute(c.Writer, configData); err != nil {
log.Error().Err(err).Msgf("could not execute template")
log.Error().Err(err).Msg("could not execute template")
c.AbortWithStatus(http.StatusInternalServerError)
return
}
Expand Down

0 comments on commit 736e196

Please sign in to comment.