github.com/ByteTerrace/packer@v1.3.2/packer/plugin/hook.go (about) 1 package plugin 2 3 import ( 4 "log" 5 6 "github.com/hashicorp/packer/packer" 7 ) 8 9 type cmdHook struct { 10 hook packer.Hook 11 client *Client 12 } 13 14 func (c *cmdHook) Run(name string, ui packer.Ui, comm packer.Communicator, data interface{}) error { 15 defer func() { 16 r := recover() 17 c.checkExit(r, nil) 18 }() 19 20 return c.hook.Run(name, ui, comm, data) 21 } 22 23 func (c *cmdHook) Cancel() { 24 defer func() { 25 r := recover() 26 c.checkExit(r, nil) 27 }() 28 29 c.hook.Cancel() 30 } 31 32 func (c *cmdHook) checkExit(p interface{}, cb func()) { 33 if c.client.Exited() && cb != nil { 34 cb() 35 } else if p != nil && !Killed { 36 log.Panic(p) 37 } 38 }