Skip to content

Commit da5a4ad

Browse files
committed
fix: resolve all golangci-lint issues
- Fix misspelling: cancelled → canceled - Add type assertion checks for ElemType conversions - Add proper error handling for cleanup StorageVolDelete - Use safe type assertion with ok check for type conversions
1 parent 97157ef commit da5a4ad

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

internal/libvirt/dialers/sshcmd.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,9 @@ func (c *sshCmdConn) lastStderrLines() []string {
395395
if el == nil {
396396
return
397397
}
398-
lines = append(lines, el.(string))
398+
if str, ok := el.(string); ok {
399+
lines = append(lines, str)
400+
}
399401
})
400402

401403
return lines

internal/provider/domain_conversion.go

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2202,7 +2202,12 @@ func xmlToDomainModel(ctx context.Context, domain *libvirtxml.Domain, model *Dom
22022202
},
22032203
},
22042204
}
2205-
filesystemsList := types.ListNull(filesystemsType.ElemType.(types.ObjectType))
2205+
filesystemsObjType, ok := filesystemsType.ElemType.(types.ObjectType)
2206+
if !ok {
2207+
diags.AddError("Type Error", "Expected filesystemsType.ElemType to be ObjectType")
2208+
return diags
2209+
}
2210+
filesystemsList := types.ListNull(filesystemsObjType)
22062211

22072212
if !model.Devices.IsNull() && !model.Devices.IsUnknown() {
22082213
var existingDevices DomainDevicesModel
@@ -2310,7 +2315,12 @@ func xmlToDomainModel(ctx context.Context, domain *libvirtxml.Domain, model *Dom
23102315
},
23112316
},
23122317
}
2313-
consolesList := types.ListNull(consolesType.ElemType.(types.ObjectType))
2318+
consolesObjType, ok := consolesType.ElemType.(types.ObjectType)
2319+
if !ok {
2320+
diags.AddError("Type Error", "Expected consolesType.ElemType to be ObjectType")
2321+
return diags
2322+
}
2323+
consolesList := types.ListNull(consolesObjType)
23142324

23152325
if !model.Devices.IsNull() && !model.Devices.IsUnknown() {
23162326
var existingDevices DomainDevicesModel
@@ -2375,7 +2385,12 @@ func xmlToDomainModel(ctx context.Context, domain *libvirtxml.Domain, model *Dom
23752385
},
23762386
},
23772387
}
2378-
serialsList := types.ListNull(serialsType.ElemType.(types.ObjectType))
2388+
serialsObjType, ok := serialsType.ElemType.(types.ObjectType)
2389+
if !ok {
2390+
diags.AddError("Type Error", "Expected serialsType.ElemType to be ObjectType")
2391+
return diags
2392+
}
2393+
serialsList := types.ListNull(serialsObjType)
23792394

23802395
if !model.Devices.IsNull() && !model.Devices.IsUnknown() {
23812396
var existingDevices DomainDevicesModel
@@ -2438,7 +2453,12 @@ func xmlToDomainModel(ctx context.Context, domain *libvirtxml.Domain, model *Dom
24382453
},
24392454
},
24402455
}
2441-
rngsList := types.ListNull(rngsType.ElemType.(types.ObjectType))
2456+
rngsObjType, ok := rngsType.ElemType.(types.ObjectType)
2457+
if !ok {
2458+
diags.AddError("Type Error", "Expected rngsType.ElemType to be ObjectType")
2459+
return diags
2460+
}
2461+
rngsList := types.ListNull(rngsObjType)
24422462

24432463
if !model.Devices.IsNull() && !model.Devices.IsUnknown() {
24442464
var existingDevices DomainDevicesModel
@@ -2487,7 +2507,12 @@ func xmlToDomainModel(ctx context.Context, domain *libvirtxml.Domain, model *Dom
24872507
},
24882508
},
24892509
}
2490-
tpmsList := types.ListNull(tpmsType.ElemType.(types.ObjectType))
2510+
tpmsObjType, ok := tpmsType.ElemType.(types.ObjectType)
2511+
if !ok {
2512+
diags.AddError("Type Error", "Expected tpmsType.ElemType to be ObjectType")
2513+
return diags
2514+
}
2515+
tpmsList := types.ListNull(tpmsObjType)
24912516

24922517
if !model.Devices.IsNull() && !model.Devices.IsUnknown() {
24932518
var existingDevices DomainDevicesModel

internal/provider/domain_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,7 +1741,7 @@ func waitForInterfaceIP(ctx context.Context, client *libvirt.Client, domain goli
17411741
// Wait before next poll
17421742
select {
17431743
case <-ctx.Done():
1744-
return fmt.Errorf("context cancelled while waiting for IP")
1744+
return fmt.Errorf("context canceled while waiting for IP")
17451745
case <-time.After(pollInterval):
17461746
// Continue polling
17471747
}

internal/provider/volume_resource.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,12 @@ func (r *VolumeResource) Create(ctx context.Context, req resource.CreateRequest,
432432
// The 0 flag means start at offset 0, uploadCapacity is the length
433433
err = r.client.Libvirt().StorageVolUpload(volume, uploadStream.Reader, 0, uint64(uploadCapacity), 0)
434434
if err != nil {
435-
// Upload failed, try to clean up the volume
436-
_ = r.client.Libvirt().StorageVolDelete(volume, 0)
435+
// Upload failed, try to clean up the volume (ignore cleanup errors to preserve original error)
436+
if delErr := r.client.Libvirt().StorageVolDelete(volume, 0); delErr != nil {
437+
tflog.Warn(ctx, "Failed to delete volume during cleanup", map[string]any{
438+
"error": delErr.Error(),
439+
})
440+
}
437441
resp.Diagnostics.AddError(
438442
"Volume Upload Failed",
439443
fmt.Sprintf("Failed to upload content to volume: %s", err),

0 commit comments

Comments
 (0)