github.com/hashicorp/packer@v1.14.3/packer/cmd_post_processor.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: BUSL-1.1 3 4 package packer 5 6 import ( 7 "context" 8 "log" 9 10 "github.com/hashicorp/hcl/v2/hcldec" 11 packersdk "github.com/hashicorp/packer-plugin-sdk/packer" 12 ) 13 14 type cmdPostProcessor struct { 15 p packersdk.PostProcessor 16 client *PluginClient 17 } 18 19 func (b *cmdPostProcessor) ConfigSpec() hcldec.ObjectSpec { 20 defer func() { 21 r := recover() 22 b.checkExit(r, nil) 23 }() 24 25 return b.p.ConfigSpec() 26 } 27 28 func (c *cmdPostProcessor) Configure(config ...interface{}) error { 29 defer func() { 30 r := recover() 31 c.checkExit(r, nil) 32 }() 33 34 return c.p.Configure(config...) 35 } 36 37 func (c *cmdPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui, a packersdk.Artifact) (packersdk.Artifact, bool, bool, error) { 38 defer func() { 39 r := recover() 40 c.checkExit(r, nil) 41 }() 42 43 return c.p.PostProcess(ctx, ui, a) 44 } 45 46 func (c *cmdPostProcessor) checkExit(p interface{}, cb func()) { 47 if c.client.Exited() && cb != nil { 48 cb() 49 } else if p != nil && !Killed { 50 log.Panic(p) 51 } 52 }