sigs.k8s.io/cluster-api@v1.7.1/errors/machines.go (about) 1 /* 2 Copyright 2017 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package errors 18 19 import ( 20 "fmt" 21 ) 22 23 // MachineError is a more descriptive kind of error that represents an error condition that 24 // should be set in the Machine.Status. The "Reason" field is meant for short, 25 // enum-style constants meant to be interpreted by machines. The "Message" 26 // field is meant to be read by humans. 27 type MachineError struct { 28 Reason MachineStatusError 29 Message string 30 } 31 32 func (e *MachineError) Error() string { 33 return e.Message 34 } 35 36 // Some error builders for ease of use. They set the appropriate "Reason" 37 // value, and all arguments are Printf-style varargs fed into Sprintf to 38 // construct the Message. 39 40 // InvalidMachineConfiguration creates a new error when a Machine has invalid configuration. 41 func InvalidMachineConfiguration(msg string, args ...interface{}) *MachineError { 42 return &MachineError{ 43 Reason: InvalidConfigurationMachineError, 44 Message: fmt.Sprintf(msg, args...), 45 } 46 } 47 48 // CreateMachine creates a new error for when creating a Machine. 49 func CreateMachine(msg string, args ...interface{}) *MachineError { 50 return &MachineError{ 51 Reason: CreateMachineError, 52 Message: fmt.Sprintf(msg, args...), 53 } 54 } 55 56 // UpdateMachine creates a new error for when updating a Machine. 57 func UpdateMachine(msg string, args ...interface{}) *MachineError { 58 return &MachineError{ 59 Reason: UpdateMachineError, 60 Message: fmt.Sprintf(msg, args...), 61 } 62 } 63 64 // DeleteMachine creates a new error for when deleting a Machine. 65 func DeleteMachine(msg string, args ...interface{}) *MachineError { 66 return &MachineError{ 67 Reason: DeleteMachineError, 68 Message: fmt.Sprintf(msg, args...), 69 } 70 }