Skip to content

Commit 24fba6a

Browse files
starbopsclaude
andcommitted
fix(executor): resolve linting issues and improve logging
Fixes all linting issues identified in the Docker client integration: - Add structured logging to DockerClient using slog.Logger - Replace fmt.Printf with proper structured logging for container warnings - Remove unused cleanupTimer field from CleanupManager - Remove unused helper functions (intPtr, int64Ptr) - Update deprecated Docker API calls: - Replace client.IsErrNotFound with errdefs.IsNotFound - Replace types.ContainerJSON with container.InspectResponse - Remove unused import of github.com/docker/docker/api/types All lint checks now pass and structured logging is consistent throughout. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent abbfe4c commit 24fba6a

3 files changed

Lines changed: 18 additions & 22 deletions

File tree

internal/executor/cleanup.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import (
1212

1313
// CleanupManager handles resource cleanup and container management
1414
type CleanupManager struct {
15-
client ContainerClient
16-
logger *slog.Logger
17-
mu sync.RWMutex
18-
containers map[string]*ContainerInfo
19-
cleanupTimer *time.Timer
15+
client ContainerClient
16+
logger *slog.Logger
17+
mu sync.RWMutex
18+
containers map[string]*ContainerInfo
2019
}
2120

2221
// ContainerInfo tracks information about running containers

internal/executor/docker_client.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"log/slog"
78
"strings"
89
"time"
910

10-
"github.com/docker/docker/api/types"
11+
"github.com/containerd/errdefs"
1112
"github.com/docker/docker/api/types/container"
1213
"github.com/docker/docker/api/types/image"
1314
"github.com/docker/docker/client"
@@ -18,14 +19,19 @@ import (
1819
type DockerClient struct {
1920
client *client.Client
2021
config *Config
22+
logger *slog.Logger
2123
}
2224

2325
// NewDockerClient creates a new Docker client with the given configuration
24-
func NewDockerClient(config *Config) (*DockerClient, error) {
26+
func NewDockerClient(config *Config, logger *slog.Logger) (*DockerClient, error) {
2527
if config == nil {
2628
config = NewDefaultConfig()
2729
}
2830

31+
if logger == nil {
32+
logger = slog.Default()
33+
}
34+
2935
if err := config.Validate(); err != nil {
3036
return nil, fmt.Errorf("invalid config: %w", err)
3137
}
@@ -42,6 +48,7 @@ func NewDockerClient(config *Config) (*DockerClient, error) {
4248
dockerClient := &DockerClient{
4349
client: cli,
4450
config: config,
51+
logger: logger,
4552
}
4653

4754
// Test connection
@@ -106,7 +113,7 @@ func (dc *DockerClient) CreateContainer(ctx context.Context, config *ContainerCo
106113
if len(resp.Warnings) > 0 {
107114
// Log warnings but don't fail
108115
for _, warning := range resp.Warnings {
109-
fmt.Printf("Container creation warning: %s\n", warning)
116+
dc.logger.Warn("container creation warning", "warning", warning)
110117
}
111118
}
112119

@@ -196,7 +203,7 @@ func (dc *DockerClient) RemoveContainer(ctx context.Context, containerID string,
196203
err := dc.client.ContainerRemove(ctx, containerID, options)
197204
if err != nil {
198205
// Don't fail if container is already removed
199-
if client.IsErrNotFound(err) {
206+
if errdefs.IsNotFound(err) {
200207
return nil
201208
}
202209
return NewContainerError(containerID, "remove_container", "failed to remove container", err)
@@ -219,7 +226,7 @@ func (dc *DockerClient) StopContainer(ctx context.Context, containerID string, t
219226
err := dc.client.ContainerStop(ctx, containerID, options)
220227
if err != nil {
221228
// Don't fail if container is already stopped
222-
if client.IsErrNotFound(err) {
229+
if errdefs.IsNotFound(err) {
223230
return nil
224231
}
225232
return NewContainerError(containerID, "stop_container", "failed to stop container", err)
@@ -308,7 +315,7 @@ func (dc *DockerClient) demultiplexLogs(logData []byte) (stdout, stderr string)
308315
}
309316

310317
// GetContainerInfo returns information about a container
311-
func (dc *DockerClient) GetContainerInfo(ctx context.Context, containerID string) (*types.ContainerJSON, error) {
318+
func (dc *DockerClient) GetContainerInfo(ctx context.Context, containerID string) (*container.InspectResponse, error) {
312319
if containerID == "" {
313320
return nil, NewContainerError("", "get_info", "container ID is empty", nil)
314321
}

internal/executor/executor.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func NewExecutor(config *Config, logger *slog.Logger) (*Executor, error) {
2929
}
3030

3131
// Create Docker client
32-
dockerClient, err := NewDockerClient(config)
32+
dockerClient, err := NewDockerClient(config, logger)
3333
if err != nil {
3434
return nil, fmt.Errorf("failed to create Docker client: %w", err)
3535
}
@@ -334,14 +334,4 @@ type ExecutorInfo struct {
334334
// Helper function to create string pointer
335335
func stringPtr(s string) *string {
336336
return &s
337-
}
338-
339-
// Helper function to create int pointer
340-
func intPtr(i int) *int {
341-
return &i
342-
}
343-
344-
// Helper function to create int64 pointer
345-
func int64Ptr(i int64) *int64 {
346-
return &i
347337
}

0 commit comments

Comments
 (0)