Skip to content

Commit 88e0a38

Browse files
authored
Return error with CodeUnimplemented for missing procedures (#6)
1 parent e06cc8d commit 88e0a38

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (c *client) Call(
161161
}
162162
procedure := spec.ProcedureForPath(procedurePath)
163163
if procedure == nil {
164-
return fmt.Errorf("no procedure for path %q", procedurePath)
164+
return NewErrorf(CodeUnimplemented, "procedure unimplemented: %q", procedurePath)
165165
}
166166
data, err := marshalRequest(c.format, request)
167167
if err != nil {

pluginrpc_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,25 @@ func TestEchoError(t *testing.T) {
108108
)
109109
}
110110

111+
func TestUnimplemented(t *testing.T) {
112+
t.Parallel()
113+
forEachDimension(
114+
t,
115+
func(t *testing.T, client pluginrpc.Client) {
116+
err := client.Call(
117+
context.Background(),
118+
"/foo/bar",
119+
nil,
120+
nil,
121+
)
122+
pluginrpcError := &pluginrpc.Error{}
123+
require.Error(t, err)
124+
require.ErrorAs(t, err, &pluginrpcError)
125+
require.Equal(t, pluginrpc.CodeUnimplemented, pluginrpcError.Code())
126+
},
127+
)
128+
}
129+
111130
func forEachDimension(t *testing.T, f func(*testing.T, pluginrpc.Client)) {
112131
for _, format := range allTestFormats {
113132
for j, newClient := range []func(...pluginrpc.ClientOption) (pluginrpc.Client, error){newExecRunnerClient, newServerRunnerClient} {

0 commit comments

Comments
 (0)