Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
cc4970d4
Commit
cc4970d4
authored
May 21, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer/rpc: Allow "error" interfaces to be sent over RPC
parent
8dfe78dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
2 deletions
+27
-2
packer/rpc/ui.go
packer/rpc/ui.go
+21
-2
packer/rpc/ui_test.go
packer/rpc/ui_test.go
+6
-0
No files found.
packer/rpc/ui.go
View file @
cc4970d4
...
...
@@ -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
{
...
...
packer/rpc/ui_test.go
View file @
cc4970d4
...
...
@@ -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"
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment