@@ -192,6 +192,7 @@ func Run(ctx context.Context, options Options) error {
192
192
}
193
193
}
194
194
195
+ var fallbackErr error
195
196
var cloned bool
196
197
if options .GitURL != "" {
197
198
endStage := startStage ("📦 Cloning %s to %s..." ,
@@ -228,8 +229,7 @@ func Run(ctx context.Context, options Options) error {
228
229
options .GitURL = gitURL .String ()
229
230
}
230
231
231
- var err error
232
- cloned , err = CloneRepo (ctx , CloneRepoOptions {
232
+ cloned , fallbackErr = CloneRepo (ctx , CloneRepoOptions {
233
233
Path : options .WorkspaceFolder ,
234
234
Storage : options .Filesystem ,
235
235
RepoURL : options .GitURL ,
@@ -243,14 +243,14 @@ func Run(ctx context.Context, options Options) error {
243
243
Depth : options .GitCloneDepth ,
244
244
CABundle : caBundle ,
245
245
})
246
- if err == nil {
246
+ if fallbackErr == nil {
247
247
if cloned {
248
248
endStage ("📦 Cloned repository!" )
249
249
} else {
250
250
endStage ("📦 The repository already exists!" )
251
251
}
252
252
} else {
253
- logf (codersdk .LogLevelError , "Failed to clone repository: %s" , err .Error ())
253
+ logf (codersdk .LogLevelError , "Failed to clone repository: %s" , fallbackErr .Error ())
254
254
logf (codersdk .LogLevelError , "Falling back to the default image..." )
255
255
}
256
256
}
@@ -265,6 +265,11 @@ func Run(ctx context.Context, options Options) error {
265
265
}
266
266
defer file .Close ()
267
267
if options .FallbackImage == "" {
268
+ if fallbackErr != nil {
269
+ return xerrors .Errorf ("%s: %w" , fallbackErr .Error (), ErrNoFallbackImage )
270
+ }
271
+ // We can't use errors.Join here because our tests
272
+ // don't support parsing a multiline error.
268
273
return ErrNoFallbackImage
269
274
}
270
275
_ , err = file .Write ([]byte ("FROM " + options .FallbackImage ))
@@ -377,8 +382,10 @@ func Run(ctx context.Context, options Options) error {
377
382
switch {
378
383
case strings .Contains (err .Error (), "parsing dockerfile" ):
379
384
fallback = true
385
+ fallbackErr = err
380
386
case strings .Contains (err .Error (), "error building stage" ):
381
387
fallback = true
388
+ fallbackErr = err
382
389
case strings .Contains (err .Error (), "unexpected status code 401 Unauthorized" ):
383
390
logf (codersdk .LogLevelError , "Unable to pull the provided image. Ensure your registry credentials are correct!" )
384
391
}
@@ -539,8 +546,6 @@ func Run(ctx context.Context, options Options) error {
539
546
540
547
err = cmd .Run ()
541
548
if err != nil {
542
- fmt .Printf ("FAILED! %s\n " , err )
543
- time .Sleep (time .Hour )
544
549
return fmt .Errorf ("run init script: %w" , err )
545
550
}
546
551
return nil
0 commit comments