Don't create Artifact if there were errors

Prevents nil-dereference crash when errors occur
This commit is contained in:
Cheng Sun 2014-12-08 18:18:23 +00:00
parent 50403a3ed6
commit 6071be1572

View File

@ -361,12 +361,20 @@ func (self *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (pa
self.runner = &multistep.BasicRunner{Steps: steps}
self.runner.Run(state)
artifact, _ := NewArtifact(self.config.OutputDir)
if rawErr, ok := state.GetOk("error"); ok {
return nil, rawErr.(error)
}
// If we were interrupted or cancelled, then just exit.
if _, ok := state.GetOk(multistep.StateCancelled); ok {
return nil, errors.New("Build was cancelled.")
}
if _, ok := state.GetOk(multistep.StateHalted); ok {
return nil, errors.New("Build was halted.")
}
artifact, _ := NewArtifact(self.config.OutputDir)
return artifact, nil
}