@@ -106,27 +106,30 @@ func (p *initSubcommand) InjectConfig(c config.Config) error {
106
106
p .repo = repoPath
107
107
}
108
108
109
- return p .config .SetRepository (p .repo )
109
+ if err := p .config .SetRepository (p .repo ); err != nil {
110
+ return fmt .Errorf ("error setting repository: %w" , err )
111
+ }
112
+
113
+ return nil
110
114
}
111
115
112
116
func (p * initSubcommand ) PreScaffold (machinery.Filesystem ) error {
113
117
// Ensure Go version is in the allowed range if check not turned off.
114
118
if ! p .skipGoVersionCheck {
115
119
if err := golang .ValidateGoVersion (goVerMin , goVerMax ); err != nil {
116
- return err
120
+ return fmt . Errorf ( "error validating go version: %w" , err )
117
121
}
118
122
}
119
123
120
- // Check if the current directory has not files or directories which does not allow to init the project
124
+ // Check if the current directory has no files or directories which does not allow to init the project
121
125
return checkDir ()
122
126
}
123
127
124
128
func (p * initSubcommand ) Scaffold (fs machinery.Filesystem ) error {
125
129
scaffolder := scaffolds .NewInitScaffolder (p .config , p .license , p .owner , p .commandName )
126
130
scaffolder .InjectFS (fs )
127
- err := scaffolder .Scaffold ()
128
- if err != nil {
129
- return err
131
+ if err := scaffolder .Scaffold (); err != nil {
132
+ return fmt .Errorf ("error scaffolding init plugin: %w" , err )
130
133
}
131
134
132
135
if ! p .fetchDeps {
@@ -136,10 +139,10 @@ func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error {
136
139
137
140
// Ensure that we are pinning controller-runtime version
138
141
// xref: https://github.com/kubernetes-sigs/kubebuilder/issues/997
139
- err = util .RunCmd ("Get controller runtime" , "go" , "get" ,
142
+ err : = util .RunCmd ("Get controller runtime" , "go" , "get" ,
140
143
"sigs.k8s.io/controller-runtime@" + scaffolds .ControllerRuntimeVersion )
141
144
if err != nil {
142
- return err
145
+ return fmt . Errorf ( "error getting controller-runtime version: %w" , err )
143
146
}
144
147
145
148
return nil
@@ -148,7 +151,7 @@ func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error {
148
151
func (p * initSubcommand ) PostScaffold () error {
149
152
err := util .RunCmd ("Update dependencies" , "go" , "mod" , "tidy" )
150
153
if err != nil {
151
- return err
154
+ return fmt . Errorf ( "error updating go dependencies: %w" , err )
152
155
}
153
156
154
157
fmt .Printf ("Next: define a resource with:\n $ %s create api\n " , p .commandName )
@@ -162,7 +165,7 @@ func checkDir() error {
162
165
err := filepath .Walk ("." ,
163
166
func (path string , info os.FileInfo , err error ) error {
164
167
if err != nil {
165
- return err
168
+ return fmt . Errorf ( "error walking path %q: %w" , path , err )
166
169
}
167
170
// Allow directory trees starting with '.'
168
171
if info .IsDir () && strings .HasPrefix (info .Name (), "." ) && info .Name () != "." {
@@ -202,11 +205,11 @@ func checkDir() error {
202
205
// Do not allow any other file
203
206
return fmt .Errorf (
204
207
"target directory is not empty and contains a disallowed file %q. " +
205
- "files with the following extensions [%s] are not allowed to avoid conflicts with the tooling. " ,
208
+ "files with the following extensions [%s] are not allowed to avoid conflicts with the tooling" ,
206
209
path , strings .Join (disallowedExtensions , ", " ))
207
210
})
208
211
if err != nil {
209
- return err
212
+ return fmt . Errorf ( "error walking directory: %w" , err )
210
213
}
211
214
return nil
212
215
}
0 commit comments