diff --git a/packer/rpc/ui.go b/packer/rpc/ui.go index 9d564f533..e196c2fdf 100644 --- a/packer/rpc/ui.go +++ b/packer/rpc/ui.go @@ -23,13 +23,32 @@ type UiSayArgs struct { } func (u *Ui) Error(format string, a ...interface{}) { + u.processArgs(a) + args := &UiSayArgs{format, a} - u.client.Call("Ui.Error", args, new(interface{})) + if err := u.client.Call("Ui.Error", args, new(interface{})); err != nil { + panic(err) + } } func (u *Ui) Say(format string, a ...interface{}) { + u.processArgs(a) + args := &UiSayArgs{format, a} - u.client.Call("Ui.Say", args, new(interface{})) + if err := u.client.Call("Ui.Say", args, new(interface{})); err != nil { + panic(err) + } +} + +func (u *Ui) processArgs(a []interface{}) { + // We do some processing to turn certain types into more gob-friendly + // types so that some things that users expect to do just work. + for i, v := range a { + // Turn errors into strings + if err, ok := v.(error); ok { + a[i] = err.Error() + } + } } func (u *UiServer) Error(args *UiSayArgs, reply *interface{}) error { diff --git a/packer/rpc/ui_test.go b/packer/rpc/ui_test.go index bec8a4adc..306b1dc40 100644 --- a/packer/rpc/ui_test.go +++ b/packer/rpc/ui_test.go @@ -2,6 +2,7 @@ package rpc import ( "cgl.tideland.biz/asserts" + "errors" "net/rpc" "testing" ) @@ -46,9 +47,14 @@ func TestUiRPC(t *testing.T) { uiClient := &Ui{client} + // Basic error and say tests uiClient.Error("format", "arg0", 42) assert.Equal(ui.errorFormat, "format", "format should be correct") uiClient.Say("format", "arg0", 42) assert.Equal(ui.sayFormat, "format", "format should be correct") + + // Test that errors are properly converted to strings + uiClient.Say("format", errors.New("foo")) + assert.Equal(ui.sayVars, []interface{}{"foo"}, "should have correct vars") }