ax(mining): replace banned fmt import with MiningError in container.go
container.go used fmt.Errorf for all error construction, violating the AX banned-imports rule. Replaced with ErrInternal().WithCause() using the package's own error primitives, consistent with the rest of pkg/mining. Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
237a22e9a5
commit
8b00af67d7
1 changed files with 7 additions and 8 deletions
|
|
@ -2,7 +2,6 @@ package mining
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"forge.lthn.ai/Snider/Mining/pkg/database"
|
||||
|
|
@ -83,13 +82,13 @@ func (c *Container) Initialize(ctx context.Context) error {
|
|||
defer c.mutex.Unlock()
|
||||
|
||||
if c.initialized {
|
||||
return fmt.Errorf("container already initialized")
|
||||
return ErrInternal("container already initialized")
|
||||
}
|
||||
|
||||
// 1. Initialize database (optional)
|
||||
if c.config.Database.Enabled {
|
||||
if err := database.Initialize(c.config.Database); err != nil {
|
||||
return fmt.Errorf("failed to initialize database: %w", err)
|
||||
return ErrInternal("failed to initialize database").WithCause(err)
|
||||
}
|
||||
c.hashrateStore = database.DefaultStore()
|
||||
logging.Info("database initialized", logging.Fields{"retention_days": c.config.Database.RetentionDays})
|
||||
|
|
@ -102,7 +101,7 @@ func (c *Container) Initialize(ctx context.Context) error {
|
|||
var err error
|
||||
c.profileManager, err = NewProfileManager()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to initialize profile manager: %w", err)
|
||||
return ErrInternal("failed to initialize profile manager").WithCause(err)
|
||||
}
|
||||
|
||||
// 3. Initialize miner manager
|
||||
|
|
@ -138,7 +137,7 @@ func (c *Container) Start(ctx context.Context) error {
|
|||
defer c.mutex.RUnlock()
|
||||
|
||||
if !c.initialized {
|
||||
return fmt.Errorf("container not initialized")
|
||||
return ErrInternal("container not initialized")
|
||||
}
|
||||
|
||||
// Start event hub
|
||||
|
|
@ -178,7 +177,7 @@ func (c *Container) Shutdown(ctx context.Context) error {
|
|||
// 2. Stop node transport (only if it was started)
|
||||
if c.nodeService != nil && c.transportStarted {
|
||||
if err := c.nodeService.StopTransport(); err != nil {
|
||||
errs = append(errs, fmt.Errorf("node transport: %w", err))
|
||||
errs = append(errs, ErrInternal("node transport shutdown failed").WithCause(err))
|
||||
}
|
||||
c.transportStarted = false
|
||||
}
|
||||
|
|
@ -195,14 +194,14 @@ func (c *Container) Shutdown(ctx context.Context) error {
|
|||
|
||||
// 5. Close database
|
||||
if err := database.Close(); err != nil {
|
||||
errs = append(errs, fmt.Errorf("database: %w", err))
|
||||
errs = append(errs, ErrInternal("database shutdown failed").WithCause(err))
|
||||
}
|
||||
|
||||
c.initialized = false
|
||||
close(c.shutdownCh)
|
||||
|
||||
if len(errs) > 0 {
|
||||
return fmt.Errorf("shutdown errors: %v", errs)
|
||||
return ErrInternal("shutdown completed with errors").WithCause(errs[0])
|
||||
}
|
||||
|
||||
logging.Info("service container shutdown complete", nil)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue