Skip to content

Commit e8cd9cd

Browse files
committed
Handle not found error in tools.instakll
1 parent 1f51048 commit e8cd9cd

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

design/pkgs.go

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ var _ = Service("tools", func() {
5555
})
5656

5757
Method("install", func() {
58+
Error("not_found", ErrorResult, "tool not found")
59+
HTTP(func() {
60+
Response("not_found", StatusBadRequest)
61+
})
5862
Payload(ToolPayload)
5963
HTTP(func() {
6064
PUT("/pkgs/tools/installed")

gen/tools/client.go

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/tools/service.go

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

v2/pkgs/tools.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ func (c *Tools) Install(ctx context.Context, payload *tools.ToolPayload) error {
116116
}
117117
}
118118

119-
return nil
119+
return tools.MakeNotFound(
120+
fmt.Errorf("tool not found with packager '%s', name '%s', version '%s'",
121+
payload.Packager, payload.Name, payload.Version))
120122
}
121123

122124
func (c *Tools) install(ctx context.Context, tool Tool) error {

v2/pkgs/tools_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io/ioutil"
77
"net/http"
88
"net/http/httptest"
9+
"strings"
910
"testing"
1011

1112
"github.com/arduino/arduino-create-agent/gen/indexes"
@@ -56,6 +57,12 @@ func TestTools(t *testing.T) {
5657
t.Fatalf("expected %d == %d (%s)", len(available), 61, "len(available)")
5758
}
5859

60+
// Try to install a non-existent tool
61+
err = service.Install(ctx, &tools.ToolPayload{})
62+
if err == nil || !strings.Contains(err.Error(), "tool not found with packager '', name '', version ''") {
63+
t.Fatalf("expected '%v' == '%v' (%s)", err, "tool not found with packager '', name '', version ''", "err")
64+
}
65+
5966
// Install a tool
6067
err = service.Install(ctx, &tools.ToolPayload{
6168
Packager: "arduino",

0 commit comments

Comments
 (0)