Skip to content

Commit

Permalink
Fix MachineNotFound custom error type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis committed Jan 3, 2023
1 parent 4c1d3b2 commit 825ee47
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pkg/cloudprovider/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package cloudprovider
import (
"context"
"errors"
"fmt"

"github.com/samber/lo"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -140,13 +141,25 @@ func (ofs Offerings) Cheapest() Offering {
}

// MachineNotFoundError is an error type returned by CloudProviders when the reason for failure is NotFound
type MachineNotFoundError error
type MachineNotFoundError struct {
Err error
}

func NewMachineNotFoundError(err error) *MachineNotFoundError {
return &MachineNotFoundError{
Err: err,
}
}

func (e *MachineNotFoundError) Error() string {
return fmt.Sprintf("machine not found, %s", e.Err)
}

func IsMachineNotFoundError(err error) bool {
if err == nil {
return false
}
var mnfErr MachineNotFoundError
mnfErr := &MachineNotFoundError{}
return errors.As(err, &mnfErr)
}

Expand Down

0 comments on commit 825ee47

Please sign in to comment.