Skip to content

Commit

Permalink
Fix MachineNotFound custom error type checking (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-innis authored Jan 3, 2023
1 parent 1fd0f13 commit 78364b2
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
var mnfErr *MachineNotFoundError
return errors.As(err, &mnfErr)
}

Expand Down

0 comments on commit 78364b2

Please sign in to comment.