Skip to content

Commit

Permalink
fix(domain): restore error handling for network operations
Browse files Browse the repository at this point in the history
Restore critical error checks for network
These checks are necessary to ensure proper error propagation when network operations fail.

Fixes #1091
  • Loading branch information
SJFCS committed Jan 11, 2025
1 parent 1cd90b7 commit d82e331
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions libvirt/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strconv"
"strings"

"github.com/davecgh/go-spew/spew"
libvirt "github.com/digitalocean/go-libvirt"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -194,10 +193,19 @@ func domainGetIfacesInfo(virConn *libvirt.Libvirt, domain libvirt.Domain, rd *sc
var interfaces []libvirt.DomainInterface
interfaces, err = virConn.DomainInterfaceAddresses(domain, addrsrc, 0)
if err != nil {
return interfaces, fmt.Errorf("error retrieving interface addresses: %w", err)
switch virErr := err.(type) {
case libvirt.Error:
// Agent can be unresponsive if being installed/setup
if addrsrc == uint32(libvirt.DomainInterfaceAddressesSrcLease) && virErr.Code != uint32(libvirt.ErrOperationInvalid) ||
addrsrc == uint32(libvirt.DomainInterfaceAddressesSrcAgent) && virErr.Code != uint32(libvirt.ErrAgentUnresponsive) {
return interfaces, fmt.Errorf("error retrieving interface addresses: %w", err)
}
// If it is ErrAgentUnresponsive, continue trying
return interfaces, nil
default:
return interfaces, fmt.Errorf("error retrieving interface addresses: %w", virErr)
}
}
log.Printf("[DEBUG] Interfaces info obtained with libvirt API:\n%s\n", spew.Sdump(interfaces))

return interfaces, nil
}

Expand Down

0 comments on commit d82e331

Please sign in to comment.