Use %w for error wrapping in log messages across multiple files

This commit is contained in:
2025-10-27 17:54:39 +01:00
parent 1814772fa2
commit 5ef0654cdd
8 changed files with 27 additions and 27 deletions

View File

@@ -102,7 +102,7 @@ func (l *lifecycleManager) checkTimeouts() {
for _, name := range timeoutInstances {
log.Printf("Instance %s has timed out, stopping it", name)
if _, err := l.manager.StopInstance(name); err != nil {
log.Printf("Error stopping instance %s: %v", name, err)
log.Printf("Error stopping instance %s: %w", name, err)
} else {
log.Printf("Instance %s stopped successfully", name)
}

View File

@@ -56,13 +56,13 @@ func New(globalConfig *config.AppConfig) InstanceManager {
portRange := globalConfig.Instances.PortRange
ports, err := newPortAllocator(portRange[0], portRange[1])
if err != nil {
log.Fatalf("Failed to create port allocator: %v", err)
log.Fatalf("Failed to create port allocator: %w", err)
}
// Initialize persistence
persistence, err := newInstancePersister(globalConfig.Instances.InstancesDir)
if err != nil {
log.Fatalf("Failed to create instance persister: %v", err)
log.Fatalf("Failed to create instance persister: %w", err)
}
// Initialize remote manager
@@ -83,7 +83,7 @@ func New(globalConfig *config.AppConfig) InstanceManager {
// Load existing instances from disk
if err := im.loadInstances(); err != nil {
log.Printf("Error loading instances: %v", err)
log.Printf("Error loading instances: %w", err)
}
// Start the lifecycle manager
@@ -116,7 +116,7 @@ func (im *instanceManager) Shutdown() {
defer wg.Done()
fmt.Printf("Stopping instance %s...\n", inst.Name)
if err := inst.Stop(); err != nil {
fmt.Printf("Error stopping instance %s: %v\n", inst.Name, err)
fmt.Printf("Error stopping instance %s: %w\n", inst.Name, err)
}
}(inst)
}
@@ -140,7 +140,7 @@ func (im *instanceManager) loadInstances() error {
// Process each loaded instance
for _, persistedInst := range instances {
if err := im.loadInstance(persistedInst); err != nil {
log.Printf("Failed to load instance %s: %v", persistedInst.Name, err)
log.Printf("Failed to load instance %s: %w", persistedInst.Name, err)
continue
}
}
@@ -251,12 +251,12 @@ func (im *instanceManager) autoStartInstances() {
// Remote instance - use remote manager with context
ctx := context.Background()
if _, err := im.remote.startInstance(ctx, node, inst.Name); err != nil {
log.Printf("Failed to auto-start remote instance %s: %v", inst.Name, err)
log.Printf("Failed to auto-start remote instance %s: %w", inst.Name, err)
}
} else {
// Local instance - call Start() directly
if err := inst.Start(); err != nil {
log.Printf("Failed to auto-start instance %s: %v", inst.Name, err)
log.Printf("Failed to auto-start instance %s: %w", inst.Name, err)
}
}
}

View File

@@ -166,7 +166,7 @@ func (im *instanceManager) CreateInstance(name string, options *instance.Options
// Persist instance (best-effort, don't fail if persistence fails)
if err := im.persistInstance(inst); err != nil {
log.Printf("Warning: failed to persist instance %s: %v", name, err)
log.Printf("Warning: failed to persist instance %s: %w", name, err)
}
return inst, nil
@@ -394,7 +394,7 @@ func (im *instanceManager) StartInstance(name string) (*instance.Instance, error
// Persist instance (best-effort, don't fail if persistence fails)
if err := im.persistInstance(inst); err != nil {
log.Printf("Warning: failed to persist instance %s: %v", name, err)
log.Printf("Warning: failed to persist instance %s: %w", name, err)
}
return inst, nil
@@ -453,7 +453,7 @@ func (im *instanceManager) StopInstance(name string) (*instance.Instance, error)
// Persist instance (best-effort, don't fail if persistence fails)
if err := im.persistInstance(inst); err != nil {
log.Printf("Warning: failed to persist instance %s: %v", name, err)
log.Printf("Warning: failed to persist instance %s: %w", name, err)
}
return inst, nil
@@ -499,7 +499,7 @@ func (im *instanceManager) RestartInstance(name string) (*instance.Instance, err
// Persist the restarted instance
if err := im.persistInstance(inst); err != nil {
log.Printf("Warning: failed to persist instance %s: %v", name, err)
log.Printf("Warning: failed to persist instance %s: %w", name, err)
}
return inst, nil

View File

@@ -162,8 +162,8 @@ func (p *instancePersister) loadAll() ([]*instance.Instance, error) {
inst, err := p.loadInstanceFile(instanceName, instancePath)
if err != nil {
log.Printf("Failed to load instance %s: %v", instanceName, err)
loadErrors = append(loadErrors, fmt.Sprintf("%s: %v", instanceName, err))
log.Printf("Failed to load instance %s: %w", instanceName, err)
loadErrors = append(loadErrors, fmt.Sprintf("%s: %w", instanceName, err))
continue
}