detached 6507981

fix(cli): normalize remote route not found errors

commit
6507981d664c4c8152d60152919bf182af4f814c
author
brice · · 2026-05-22 07:07 UTC
parent
e8ee147
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
3 files · +53 -0
M internal/adapters/in/cli/remote/client.go +4 -0
@@ -504,6 +504,10 @@ func (c *Client) GetRoute(ctx context.Context, routeDomain string) (*domain.Rout
504504
505505 var route domain.Route
506506 if err := parseResponse(resp, &route); err != nil {
507+ var httpErr *HTTPError
508+ if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound {
509+ return nil, domain.ErrRouteNotFound
510+ }
507511 return nil, err
508512 }
509513
@@ -504,6 +504,10 @@ func (c *Client) GetRoute(ctx context.Context, routeDomain string) (*domain.Rout
504 504
505 var route domain.Route505 var route domain.Route
506 if err := parseResponse(resp, &route); err != nil {506 if err := parseResponse(resp, &route); err != nil {
507+ var httpErr *HTTPError
508+ if errors.As(err, &httpErr) && httpErr.StatusCode == http.StatusNotFound {
509+ return nil, domain.ErrRouteNotFound
510+ }
507 return nil, err511 return nil, err
508 }512 }
509 513
M internal/adapters/in/cli/remote/client_test.go +17 -0
@@ -13,6 +13,7 @@ import (
1313 "testing"
1414 "time"
1515
16+ "github.com/bnema/gordon/internal/domain"
1617 "github.com/stretchr/testify/assert"
1718 "github.com/stretchr/testify/require"
1819
@@ -200,6 +201,22 @@ func TestClientFindAttachmentTargetsByImage(t *testing.T) {
200201 assert.Equal(t, []string{"app.example.com", "workers"}, targets)
201202 }
202203
204+func TestClientGetRoute_Maps404ToDomainErrRouteNotFound(t *testing.T) {
205+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
206+ require.Equal(t, "/admin/routes/missing.example.test", r.URL.Path)
207+ require.Equal(t, http.MethodGet, r.Method)
208+ w.WriteHeader(http.StatusNotFound)
209+ _, _ = w.Write([]byte(`{"error":"route not found"}`))
210+ }))
211+ defer srv.Close()
212+
213+ client := NewClient(srv.URL)
214+ route, err := client.GetRoute(context.Background(), "missing.example.test")
215+ require.Nil(t, route)
216+ require.Error(t, err)
217+ assert.ErrorIs(t, err, domain.ErrRouteNotFound)
218+}
219+
203220 func TestClientFindAttachmentTargetsByImage_WithSlashContainingImage(t *testing.T) {
204221 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
205222 require.Equal(t, "/admin/attachments/by-image/registry/org/image:tag", r.URL.Path)
@@ -13,6 +13,7 @@ import (
13 "testing"13 "testing"
14 "time"14 "time"
15 15
16+ "github.com/bnema/gordon/internal/domain"
16 "github.com/stretchr/testify/assert"17 "github.com/stretchr/testify/assert"
17 "github.com/stretchr/testify/require"18 "github.com/stretchr/testify/require"
18 19
@@ -200,6 +201,22 @@ func TestClientFindAttachmentTargetsByImage(t *testing.T) {
200 assert.Equal(t, []string{"app.example.com", "workers"}, targets)201 assert.Equal(t, []string{"app.example.com", "workers"}, targets)
201 }202 }
202 203
204+func TestClientGetRoute_Maps404ToDomainErrRouteNotFound(t *testing.T) {
205+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
206+ require.Equal(t, "/admin/routes/missing.example.test", r.URL.Path)
207+ require.Equal(t, http.MethodGet, r.Method)
208+ w.WriteHeader(http.StatusNotFound)
209+ _, _ = w.Write([]byte(`{"error":"route not found"}`))
210+ }))
211+ defer srv.Close()
212+
213+ client := NewClient(srv.URL)
214+ route, err := client.GetRoute(context.Background(), "missing.example.test")
215+ require.Nil(t, route)
216+ require.Error(t, err)
217+ assert.ErrorIs(t, err, domain.ErrRouteNotFound)
218+}
219+
203 func TestClientFindAttachmentTargetsByImage_WithSlashContainingImage(t *testing.T) {220 func TestClientFindAttachmentTargetsByImage_WithSlashContainingImage(t *testing.T) {
204 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {221 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
205 require.Equal(t, "/admin/attachments/by-image/registry/org/image:tag", r.URL.Path)222 require.Equal(t, "/admin/attachments/by-image/registry/org/image:tag", r.URL.Path)
M internal/adapters/in/cli/routes_test.go +32 -0
@@ -6,6 +6,8 @@ import (
66 "encoding/json"
77 "errors"
88 "io"
9+ "net/http"
10+ "net/http/httptest"
911 "os"
1012 "path/filepath"
1113 "strconv"
@@ -948,6 +950,36 @@ func TestBuildRouteDiagnosis_IncludesAttachmentVolumesWithDoubleUnderscoreOwnerE
948950 assert.Equal(t, "gordon-gordon-app__example__test-postgres-var-lib-postgresql", diag.Volumes[0].Name)
949951 }
950952
953+func TestBuildRouteDiagnosis_RemoteMissingRouteDoesNotWarnOnExpectedNotFound(t *testing.T) {
954+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
955+ w.Header().Set("Content-Type", "application/json")
956+ switch r.URL.Path {
957+ case "/admin/routes/missing.example.test":
958+ w.WriteHeader(http.StatusNotFound)
959+ _, _ = w.Write([]byte(`{"error":"route not found"}`))
960+ case "/admin/routes":
961+ require.Equal(t, "detailed=true", r.URL.RawQuery)
962+ _, _ = w.Write([]byte(`{"routes":[]}`))
963+ case "/admin/health":
964+ _, _ = w.Write([]byte(`{"health":{}}`))
965+ case "/admin/volumes":
966+ _, _ = w.Write([]byte(`[]`))
967+ case "/admin/attachments/orphans":
968+ _, _ = w.Write([]byte(`{"attachments":[]}`))
969+ default:
970+ t.Fatalf("unexpected path: %s", r.URL.Path)
971+ }
972+ }))
973+ defer srv.Close()
974+
975+ cp := NewRemoteControlPlane(remote.NewClient(srv.URL))
976+ diag, err := buildRouteDiagnosis(context.Background(), cp, "missing.example.test")
977+
978+ require.NoError(t, err)
979+ assert.False(t, diag.Configured)
980+ assert.Empty(t, diag.Warnings)
981+}
982+
951983 func TestWriteRouteDiagnosisText_ShowsActiveAttachmentsSeparatelyFromOrphans(t *testing.T) {
952984 var out bytes.Buffer
953985 diag := &routeDiagnosis{
@@ -6,6 +6,8 @@ import (
6 "encoding/json"6 "encoding/json"
7 "errors"7 "errors"
8 "io"8 "io"
9+ "net/http"
10+ "net/http/httptest"
9 "os"11 "os"
10 "path/filepath"12 "path/filepath"
11 "strconv"13 "strconv"
@@ -948,6 +950,36 @@ func TestBuildRouteDiagnosis_IncludesAttachmentVolumesWithDoubleUnderscoreOwnerE
948 assert.Equal(t, "gordon-gordon-app__example__test-postgres-var-lib-postgresql", diag.Volumes[0].Name)950 assert.Equal(t, "gordon-gordon-app__example__test-postgres-var-lib-postgresql", diag.Volumes[0].Name)
949 }951 }
950 952
953+func TestBuildRouteDiagnosis_RemoteMissingRouteDoesNotWarnOnExpectedNotFound(t *testing.T) {
954+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
955+ w.Header().Set("Content-Type", "application/json")
956+ switch r.URL.Path {
957+ case "/admin/routes/missing.example.test":
958+ w.WriteHeader(http.StatusNotFound)
959+ _, _ = w.Write([]byte(`{"error":"route not found"}`))
960+ case "/admin/routes":
961+ require.Equal(t, "detailed=true", r.URL.RawQuery)
962+ _, _ = w.Write([]byte(`{"routes":[]}`))
963+ case "/admin/health":
964+ _, _ = w.Write([]byte(`{"health":{}}`))
965+ case "/admin/volumes":
966+ _, _ = w.Write([]byte(`[]`))
967+ case "/admin/attachments/orphans":
968+ _, _ = w.Write([]byte(`{"attachments":[]}`))
969+ default:
970+ t.Fatalf("unexpected path: %s", r.URL.Path)
971+ }
972+ }))
973+ defer srv.Close()
974+
975+ cp := NewRemoteControlPlane(remote.NewClient(srv.URL))
976+ diag, err := buildRouteDiagnosis(context.Background(), cp, "missing.example.test")
977+
978+ require.NoError(t, err)
979+ assert.False(t, diag.Configured)
980+ assert.Empty(t, diag.Warnings)
981+}
982+
951 func TestWriteRouteDiagnosisText_ShowsActiveAttachmentsSeparatelyFromOrphans(t *testing.T) {983 func TestWriteRouteDiagnosisText_ShowsActiveAttachmentsSeparatelyFromOrphans(t *testing.T) {
952 var out bytes.Buffer984 var out bytes.Buffer
953 diag := &routeDiagnosis{985 diag := &routeDiagnosis{

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close