bmclib/errors/errors.go
Joel Rebello 6e87e841a8
providers/redfish: check session is active before executing action
This returns the Error type ErrNotAuthenticated to the caller,
so that the caller can realize a new session needs to be setup,
instead of just ending up with a panic.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x17b78fc]

goroutine 30 [running]:
github.com/bmc-toolbox/bmclib/v2/providers/redfish.(*Conn).status(0x17cb315?, {0xc0002f6470?, 0x0?})
        /go/pkg/mod/github.com/bmc-toolbox/bmclib/v2@v2.0.0/providers/redfish/redfish.go:236 +0x1c
github.com/bmc-toolbox/bmclib/v2/providers/redfish.(*Conn).PowerStateGet(0x18768c0?, {0x1b4ac18?, 0xc000433f80?})
        /go/pkg/mod/github.com/bmc-toolbox/bmclib/v2@v2.0.0/providers/redfish/redfish.go:178 +0x25
github.com/bmc-toolbox/bmclib/v2/bmc.getPowerState({0x1b4ac18, 0xc000433f80}, {0xc0003fa990?, 0x0?, 0x0?})
        /go/pkg/mod/github.com/bmc-toolbox/bmclib/v2@v2.0.0/bmc/power.go:102 +0x28d
github.com/bmc-toolbox/bmclib/v2/bmc.GetPowerStateFromInterfaces({0x1b4ac18?, 0xc000433f80?}, {0xc0002f6460?, 0x1?, 0x1?})
        /go/pkg/mod/github.com/bmc-toolbox/bmclib/v2@v2.0.0/bmc/power.go:131 +0x1c5
github.com/bmc-toolbox/bmclib/v2.(*Client).GetPowerState(0xc000196e10, {0x1b4ac18, 0xc000433f80})
        /go/pkg/mod/github.com/bmc-toolbox/bmclib/v2@v2.0.0/client.go:178 +0x1e7
2022-11-07 10:29:33 +01:00

102 lines
4.4 KiB
Go

package errors
import (
"errors"
"fmt"
)
var (
// ErrLoginFailed is returned when we fail to login to a bmc
ErrLoginFailed = errors.New("failed to login")
// ErrLogoutFailed is returned when we fail to logout from a bmc
ErrLogoutFailed = errors.New("failed to logout")
// ErrNotAuthenticated is returned when the session is not active.
ErrNotAuthenticated = errors.New("not authenticated")
// ErrNon200Response is returned when bmclib recieves an unexpected non-200 status code for a query
ErrNon200Response = errors.New("non-200 response returned for the endpoint")
// ErrNotImplemented is returned for not implemented methods called
ErrNotImplemented = errors.New("this feature hasn't been implemented yet")
// ErrRetrievingUserAccounts is returned when bmclib is unable to retrieve user accounts from the BMC
ErrRetrievingUserAccounts = errors.New("error retrieving user accounts")
// ErrInvalidUserRole is returned when the given user account role is not valid
ErrInvalidUserRole = errors.New("invalid user account role")
// ErrUserParamsRequired is returned when all the required user parameters are not provided - username, password, role
ErrUserParamsRequired = errors.New("username, password and role are required parameters")
// ErrUserAccountExists is returned when a user account with the username is already present
ErrUserAccountExists = errors.New("user account already exists")
// ErrNoUserSlotsAvailable is returned when there are no user account slots available
ErrNoUserSlotsAvailable = errors.New("no user account slots available")
// ErrUserAccountNotFound is returned when the user account is not present
ErrUserAccountNotFound = errors.New("given user account does not exist")
// ErrUserAccountUpdate is returned when the user account failed to be updated
ErrUserAccountUpdate = errors.New("user account attributes could not be updated")
// ErrRedfishChassisOdataID is returned when no compatible Chassis Odata IDs were identified
ErrRedfishChassisOdataID = errors.New("no compatible Chassis Odata IDs identified")
// ErrRedfishSystemOdataID is returned when no compatible System Odata IDs were identified
ErrRedfishSystemOdataID = errors.New("no compatible System Odata IDs identified")
// ErrRedfishManagerOdataID is returned when no compatible Manager Odata IDs were identified
ErrRedfishManagerOdataID = errors.New("no compatible Manager Odata IDs identified")
// ErrRedfishServiceNil is returned when a redfish method is invoked on a nil redfish (gofish) Service object
ErrRedfishServiceNil = errors.New("redfish connection returned a nil redfish Service object")
// ErrRedfishSoftwareInventory is returned when software inventory could not be collected over redfish
ErrRedfishSoftwareInventory = errors.New("error collecting redfish software inventory")
// ErrFirmwareUpload is returned when a firmware upload method fails
ErrFirmwareUpload = errors.New("error uploading firmware")
// ErrFirmwareInstall is returned for firmware install failures
ErrFirmwareInstall = errors.New("error updating firmware")
// ErrFirmwareInstallStatus is returned for firmware install status read
ErrFirmwareInstallStatus = errors.New("error querying firmware install status")
// ErrRedfishUpdateService is returned on redfish update service errors
ErrRedfishUpdateService = errors.New("redfish update service error")
// ErrTaskNotFound is returned when the (redfish) task could not be found
ErrTaskNotFound = errors.New("task not found")
// ErrTaskPurge is returned when a (redfish) task could not be purged
ErrTaskPurge = errors.New("unable to purge task")
// ErrPowerStatusRead is returned when a power status read query fails
ErrPowerStatusRead = errors.New("error returning power status")
// ErrPowerStatusSet is returned when a power status set query fails
ErrPowerStatusSet = errors.New("error setting power status")
// ErrProviderImplementation is returned when theres an error in the BMC provider implementation
ErrProviderImplementation = errors.New("error in provider implementation")
// ErrCompatibilityCheck is returned when the compatibility probe failed to complete successfully.
ErrCompatibilityCheck = errors.New("compatibility check failed")
)
type ErrUnsupportedHardware struct {
msg string
}
func (e *ErrUnsupportedHardware) Error() string {
return fmt.Sprintf("Hardware not supported: %s", e.msg)
}
func NewErrUnsupportedHardware(s string) error {
return &ErrUnsupportedHardware{s}
}