Skip to content

Commit f7bc50d

Browse files
committed
fix: resolve compilation errors in workflows
- Add gorilla/websocket dependency and imports - Fix CategoryRetryConfig type conflicts between packages - Remove duplicate OptimizedClientConfig definitions - Add missing TryRecoverFromError method to ErrorAwareClient - Clean up unused imports in websocket and broadcaster files
1 parent d2a7afd commit f7bc50d

File tree

10 files changed

+76
-53
lines changed

10 files changed

+76
-53
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ require (
3030
github.com/go-logr/logr v1.4.2 // indirect
3131
github.com/go-logr/stdr v1.2.2 // indirect
3232
github.com/godbus/dbus/v5 v5.1.0 // indirect
33+
github.com/gorilla/websocket v1.5.3 // indirect
3334
github.com/kylelemons/godebug v1.1.0 // indirect
3435
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
3536
github.com/pmezard/go-difflib v1.0.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU
2424
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
2525
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
2626
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
27+
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
28+
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
2729
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
2830
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
2931
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=

pkg/api/error_aware_client.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ func (eac *ErrorAwareClient) Close() error {
128128
return nil
129129
}
130130

131+
// TryRecoverFromError attempts to recover from an error using the error manager
132+
func (eac *ErrorAwareClient) TryRecoverFromError(ctx context.Context, err error) error {
133+
if eac.errorManager == nil {
134+
return err
135+
}
136+
137+
// Convert to AppError if needed
138+
var appErr *types.AppError
139+
if ae, ok := err.(*types.AppError); ok {
140+
appErr = ae
141+
} else {
142+
appErr = types.NewAppError(types.ErrOperationFailed, err.Error(), err)
143+
}
144+
145+
// Try recovery
146+
return eac.errorManager.TryRecover(ctx, appErr)
147+
}
148+
131149
// ErrorAwareOptimizedClient wraps OptimizedTraktAPIClient with unified error handling
132150
type ErrorAwareOptimizedClient struct {
133151
client OptimizedTraktAPIClient

pkg/api/factory.go

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,12 @@ func (f *DefaultClientFactory) CreateBasicClient(cfg *config.Config) (TraktAPICl
6060
// CreateOptimizedClient creates an optimized Trakt API client
6161
func (f *DefaultClientFactory) CreateOptimizedClient(cfg OptimizedClientConfig) (OptimizedTraktAPIClient, error) {
6262
// Validate configuration
63-
if cfg.BaseConfig == nil {
63+
if cfg.Config == nil {
6464
return nil, fmt.Errorf("base configuration cannot be nil")
6565
}
6666

67-
// Set defaults for optimized client config
68-
optimizedConfig := OptimizedClientConfig{
69-
Config: cfg.BaseConfig,
70-
Logger: cfg.Logger,
71-
WorkerPoolSize: cfg.WorkerPoolSize,
72-
RateLimitPerSec: cfg.RateLimitPerSec,
73-
ConnectionPool: cfg.ConnectionPool,
74-
RequestTimeout: cfg.RequestTimeout,
75-
}
76-
77-
// Set cache config defaults
78-
if cfg.CacheConfig != nil {
79-
optimizedConfig.CacheConfig = *cfg.CacheConfig
80-
} else {
81-
optimizedConfig.CacheConfig = cache.CacheConfig{
82-
Capacity: 1000,
83-
TTL: 24 * time.Hour,
84-
}
85-
}
67+
// Configuration is already complete - just create the client
68+
optimizedConfig := cfg
8669

8770
// Create optimized client
8871
client := NewOptimizedClient(optimizedConfig)
@@ -106,11 +89,21 @@ func (f *DefaultClientFactory) CreateClientWithCapabilities(cfg ClientCapabiliti
10689

10790
// If advanced capabilities are requested, create optimized client
10891
if cfg.EnableCaching || cfg.EnableMetrics || cfg.EnableConcurrency || cfg.WorkerPoolSize > 0 {
92+
var cacheConfig cache.CacheConfig
93+
if cfg.CacheConfig != nil {
94+
cacheConfig = *cfg.CacheConfig
95+
} else {
96+
cacheConfig = cache.CacheConfig{
97+
Capacity: 1000,
98+
TTL: 24 * time.Hour,
99+
}
100+
}
101+
109102
optimizedConfig := OptimizedClientConfig{
110-
BaseConfig: cfg.BaseConfig,
103+
Config: cfg.BaseConfig,
111104
Logger: nil, // Would need to be provided
112105
WorkerPoolSize: cfg.WorkerPoolSize,
113-
CacheConfig: cfg.CacheConfig,
106+
CacheConfig: cacheConfig,
114107
}
115108

116109
if cfg.WorkerPoolSize <= 0 {
@@ -124,14 +117,3 @@ func (f *DefaultClientFactory) CreateClientWithCapabilities(cfg ClientCapabiliti
124117
return f.CreateBasicClient(cfg.BaseConfig)
125118
}
126119

127-
// OptimizedClientConfig represents the configuration for optimized clients
128-
// This extends the interface definition with implementation details
129-
type OptimizedClientConfig struct {
130-
BaseConfig *config.Config
131-
Logger logger.Logger
132-
CacheConfig cache.CacheConfig
133-
WorkerPoolSize int
134-
RateLimitPerSec int
135-
ConnectionPool int
136-
RequestTimeout time.Duration
137-
}

pkg/api/unified_example.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func UnifiedAPIExample() error {
3838

3939
// 6. Create an optimized client
4040
optimizedConfig := OptimizedClientConfig{
41-
BaseConfig: cfg,
41+
Config: cfg,
4242
Logger: log,
4343
WorkerPoolSize: 10,
4444
RateLimitPerSec: 100,

pkg/errors/handlers/config.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package handlers
2+
3+
import "time"
4+
5+
// CategoryRetryConfig defines retry configuration per error category
6+
type CategoryRetryConfig struct {
7+
MaxAttempts int
8+
InitialDelay time.Duration
9+
MaxDelay time.Duration
10+
BackoffFactor float64
11+
EnableJitter bool
12+
CircuitBreaker bool
13+
}

pkg/errors/handlers/network.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ type NetworkErrorHandler struct {
1616
Config *CategoryRetryConfig
1717
}
1818

19-
// CategoryRetryConfig defines retry configuration per error category
20-
type CategoryRetryConfig struct {
21-
MaxAttempts int
22-
InitialDelay time.Duration
23-
MaxDelay time.Duration
24-
BackoffFactor float64
25-
EnableJitter bool
26-
CircuitBreaker bool
27-
}
2819

2920
// NewNetworkErrorHandler creates a new network error handler
3021
func NewNetworkErrorHandler(logger logger.Logger, config *CategoryRetryConfig) *NetworkErrorHandler {

pkg/errors/manager.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,21 +411,24 @@ func (em *ErrorManager) defaultHandle(ctx context.Context, err *types.AppError)
411411
// initializeDefaultHandlers sets up default error handlers
412412
func (em *ErrorManager) initializeDefaultHandlers() {
413413
// Network errors handler
414+
networkConfig := em.config.RetryConfig.PerCategoryConfig[types.CategoryNetwork]
414415
em.handlers[types.CategoryNetwork] = &handlers.NetworkErrorHandler{
415416
Logger: em.logger,
416-
Config: em.config.RetryConfig.PerCategoryConfig[types.CategoryNetwork],
417+
Config: convertToHandlerConfig(networkConfig),
417418
}
418419

419420
// Authentication errors handler
421+
authConfig := em.config.RetryConfig.PerCategoryConfig[types.CategoryAuthentication]
420422
em.handlers[types.CategoryAuthentication] = &handlers.AuthErrorHandler{
421423
Logger: em.logger,
422-
Config: em.config.RetryConfig.PerCategoryConfig[types.CategoryAuthentication],
424+
Config: convertToHandlerConfig(authConfig),
423425
}
424426

425427
// Operation errors handler
428+
opConfig := em.config.RetryConfig.PerCategoryConfig[types.CategoryOperation]
426429
em.handlers[types.CategoryOperation] = &handlers.OperationErrorHandler{
427430
Logger: em.logger,
428-
Config: em.config.RetryConfig.PerCategoryConfig[types.CategoryOperation],
431+
Config: convertToHandlerConfig(opConfig),
429432
}
430433
}
431434

@@ -457,4 +460,20 @@ func contains(s string, substrings ...string) bool {
457460
}
458461
}
459462
return false
463+
}
464+
465+
// convertToHandlerConfig converts CategoryRetryConfig to handlers.CategoryRetryConfig
466+
func convertToHandlerConfig(config *CategoryRetryConfig) *handlers.CategoryRetryConfig {
467+
if config == nil {
468+
return nil
469+
}
470+
471+
return &handlers.CategoryRetryConfig{
472+
MaxAttempts: config.MaxAttempts,
473+
InitialDelay: config.InitialDelay,
474+
MaxDelay: config.MaxDelay,
475+
BackoffFactor: config.BackoffFactor,
476+
EnableJitter: config.EnableJitter,
477+
CircuitBreaker: config.CircuitBreaker,
478+
}
460479
}

pkg/web/realtime/broadcaster.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package realtime
22

33
import (
4-
"context"
54
"encoding/json"
65
"fmt"
76
"os"

pkg/web/realtime/websocket.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
package realtime
22

33
import (
4-
"bufio"
5-
"crypto/sha1"
6-
"encoding/base64"
74
"encoding/json"
85
"fmt"
96
"net/http"
10-
"strings"
117
"time"
128

9+
"github.com/gorilla/websocket"
1310
"github.com/JohanDevl/Export_Trakt_4_Letterboxd/pkg/logger"
1411
)
1512

1613
// WebSocketHandler handles WebSocket connections
1714
type WebSocketHandler struct {
18-
hub *Hub
19-
logger logger.Logger
15+
hub *Hub
16+
logger logger.Logger
17+
upgrader websocket.Upgrader
2018
}
2119

2220
// NewWebSocketHandler creates a new WebSocket handler

0 commit comments

Comments
 (0)