@@ -28,23 +28,24 @@ import (
2828 bootstrapschemev1 "sigs.k8s.io/cluster-api-provider-aws/cmd/clusterawsadm/api/bootstrap/v1alpha1/scheme"
2929)
3030
31+ type errEmptyBootstrapConfig string
32+
33+ func (e errEmptyBootstrapConfig ) Error () string {
34+ return fmt .Sprintf ("bootstrap config file %q was empty" , string (e ))
35+ }
36+
3137// LoadConfigFile loads a YAML file representing a bootstrapv1.AWSIAMConfiguration.
3238func LoadConfigFile (name string ) (* bootstrapv1.AWSIAMConfiguration , error ) {
33- const errFmt = "failed to load bootstrap config file %s, error %v"
3439 // compute absolute path based on current working dir
3540 iamConfigFile , err := filepath .Abs (name )
3641 if err != nil {
37- return nil , fmt .Errorf (errFmt , name , err )
42+ return nil , fmt .Errorf ("failed to convert IAM config path into absolute path %s, error: %w" , name , err )
3843 }
3944 loader , err := newFsLoader (iamConfigFile )
4045 if err != nil {
41- return nil , fmt .Errorf (errFmt , name , err )
42- }
43- kc , err := loader .Load ()
44- if err != nil {
45- return nil , fmt .Errorf (errFmt , name , err )
46+ return nil , fmt .Errorf ("failed to initialize filesystem loader: %w" , err )
4647 }
47- return kc , err
48+ return loader . Load ()
4849}
4950
5051// Loader loads configuration from a storage layer.
@@ -83,12 +84,12 @@ func newFsLoader(bootstrapFile string) (loader, error) {
8384func (loader * fsLoader ) Load () (* bootstrapv1.AWSIAMConfiguration , error ) {
8485 data , err := loader .ReadFile (loader .bootstrapFile )
8586 if err != nil {
86- return nil , fmt .Errorf ("failed to read bootstrap config file %q, error: %v " , loader .bootstrapFile , err )
87+ return nil , fmt .Errorf ("failed to read bootstrap config file %q, error: %w " , loader .bootstrapFile , err )
8788 }
8889
8990 // no configuration is an error, some parameters are required
9091 if len (data ) == 0 {
91- return nil , fmt . Errorf ( "bootstrap config file %q was empty" , loader .bootstrapFile )
92+ return nil , errEmptyBootstrapConfig ( loader .bootstrapFile )
9293 }
9394
9495 kc , err := DecodeBootstrapConfiguration (loader .bootstrapCodecs , data )
0 commit comments