github.com/askholme/packer@v0.7.2-0.20140924152349-70d9566a6852/packer/plugin/builder.go (about) 1 package plugin 2 3 import ( 4 "github.com/mitchellh/packer/packer" 5 "log" 6 ) 7 8 type cmdBuilder struct { 9 builder packer.Builder 10 client *Client 11 } 12 13 func (b *cmdBuilder) Prepare(config ...interface{}) ([]string, error) { 14 defer func() { 15 r := recover() 16 b.checkExit(r, nil) 17 }() 18 19 return b.builder.Prepare(config...) 20 } 21 22 func (b *cmdBuilder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) { 23 defer func() { 24 r := recover() 25 b.checkExit(r, nil) 26 }() 27 28 return b.builder.Run(ui, hook, cache) 29 } 30 31 func (b *cmdBuilder) Cancel() { 32 defer func() { 33 r := recover() 34 b.checkExit(r, nil) 35 }() 36 37 b.builder.Cancel() 38 } 39 40 func (c *cmdBuilder) checkExit(p interface{}, cb func()) { 41 if c.client.Exited() && cb != nil { 42 cb() 43 } else if p != nil && !Killed { 44 log.Panic(p) 45 } 46 }