@@ -393,6 +393,8 @@ func (ctx Context) LoadModuleByID(id string, rawMsg json.RawMessage) (any, error
393
393
return nil , fmt .Errorf ("module value cannot be null" )
394
394
}
395
395
396
+ var err error
397
+
396
398
// if this is an app module, keep a reference to it,
397
399
// since submodules may need to reference it during
398
400
// provisioning (even though the parent app module
@@ -402,12 +404,17 @@ func (ctx Context) LoadModuleByID(id string, rawMsg json.RawMessage) (any, error
402
404
// module has been configured for DNS challenges)
403
405
if appModule , ok := val .(App ); ok {
404
406
ctx .cfg .apps [id ] = appModule
407
+ defer func () {
408
+ if err != nil {
409
+ delete (ctx .cfg .apps , id )
410
+ }
411
+ }()
405
412
}
406
413
407
414
ctx .ancestry = append (ctx .ancestry , val )
408
415
409
416
if prov , ok := val .(Provisioner ); ok {
410
- err : = prov .Provision (ctx )
417
+ err = prov .Provision (ctx )
411
418
if err != nil {
412
419
// incomplete provisioning could have left state
413
420
// dangling, so make sure it gets cleaned up
@@ -417,18 +424,12 @@ func (ctx Context) LoadModuleByID(id string, rawMsg json.RawMessage) (any, error
417
424
err = fmt .Errorf ("%v; additionally, cleanup: %v" , err , err2 )
418
425
}
419
426
}
420
-
421
- // if this was an app module that failed to provision,
422
- // remove it from the apps map to prevent it from being started at all
423
- if _ , ok := val .(App ); ok {
424
- delete (ctx .cfg .apps , id )
425
- }
426
427
return nil , fmt .Errorf ("provision %s: %v" , modInfo , err )
427
428
}
428
429
}
429
430
430
431
if validator , ok := val .(Validator ); ok {
431
- err : = validator .Validate ()
432
+ err = validator .Validate ()
432
433
if err != nil {
433
434
// since the module was already provisioned, make sure we clean up
434
435
if cleanerUpper , ok := val .(CleanerUpper ); ok {
0 commit comments