diff options
author | earl-warren <earl-warren@noreply.code.forgejo.org> | 2025-01-09 11:29:17 +0100 |
---|---|---|
committer | earl-warren <earl-warren@noreply.code.forgejo.org> | 2025-01-09 11:29:17 +0100 |
commit | e3e1ac2d6f15f5eac9dfd972d2624c59d28dd401 (patch) | |
tree | 1aeaa6f3a2e6d1c128fa7ca9d27796ee217d87c0 | |
parent | Merge pull request 'feat: export runtime token as FORGEJO_TOKEN' (#88) from x... (diff) | |
parent | refactor: Improve logging of error messages (diff) | |
download | forgejo-act-e3e1ac2d6f15f5eac9dfd972d2624c59d28dd401.tar.xz forgejo-act-e3e1ac2d6f15f5eac9dfd972d2624c59d28dd401.zip |
Merge pull request 'feat: Improve logging of error messages' (#90) from vpotyarkin/act:feature/improve-error-logging into main
Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/90
Reviewed-by: earl-warren <earl-warren@noreply.code.forgejo.org>
-rw-r--r-- | pkg/artifacts/server.go | 2 | ||||
-rw-r--r-- | pkg/container/docker_run.go | 16 |
2 files changed, 11 insertions, 7 deletions
diff --git a/pkg/artifacts/server.go b/pkg/artifacts/server.go index 4b88ea4..160dd4d 100644 --- a/pkg/artifacts/server.go +++ b/pkg/artifacts/server.go @@ -300,7 +300,7 @@ func Serve(ctx context.Context, artifactPath string, addr string, port string) c go func() { logger.Infof("Start server on http://%s:%s", addr, port) if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed { - logger.Fatal(err) + logger.Fatalf("http listener: %v", err) } }() diff --git a/pkg/container/docker_run.go b/pkg/container/docker_run.go index 3232c14..08bf53d 100644 --- a/pkg/container/docker_run.go +++ b/pkg/container/docker_run.go @@ -526,8 +526,9 @@ func (cr *containerReference) extractFromImageEnv(env *map[string]string) common inspect, _, err := cr.cli.ImageInspectWithRaw(ctx, cr.input.Image) if err != nil { + err = fmt.Errorf("inspect image: %w", err) logger.Error(err) - return fmt.Errorf("inspect image: %w", err) + return err } if inspect.Config == nil { @@ -536,8 +537,9 @@ func (cr *containerReference) extractFromImageEnv(env *map[string]string) common imageEnv, err := godotenv.Unmarshal(strings.Join(inspect.Config.Env, "\n")) if err != nil { + err = fmt.Errorf("unmarshal image env: %w", err) logger.Error(err) - return fmt.Errorf("unmarshal image env: %w", err) + return err } for k, v := range imageEnv { @@ -709,7 +711,7 @@ func (cr *containerReference) waitForCommand(ctx context.Context, isTerminal boo return ctx.Err() case err := <-cmdResponse: if err != nil { - logger.Error(err) + logger.Errorf("command response: %v", err) } return nil @@ -754,11 +756,11 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string, useGitIgno name := tarFile.Name() err := tarFile.Close() if err != nil && !errors.Is(err, os.ErrClosed) { - logger.Error(err) + logger.Errorf("close tar file: %s: %v", name, err) } err = os.Remove(name) if err != nil { - logger.Error(err) + logger.Errorf("remove file: %s: %v", name, err) } }(tarFile) tw := tar.NewWriter(tarFile) @@ -797,6 +799,8 @@ func (cr *containerReference) copyDir(dstPath string, srcPath string, useGitIgno return err } if err := tw.Close(); err != nil { + err = fmt.Errorf("close tar writer: %w", err) + logger.Debug(err) return err } @@ -875,7 +879,7 @@ func (cr *containerReference) attach() common.Executor { _, err = io.Copy(outWriter, out.Reader) } if err != nil { - common.Logger(ctx).Error(err) + common.Logger(ctx).Errorf("redirect container output: %v", err) } }() return nil |