Skip to content

Commit e327dd6

Browse files
committed
Fix edge case where update check has never succeeded
1 parent 043f227 commit e327dd6

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

coderd/updatecheck.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package coderd
22

33
import (
4+
"database/sql"
45
"net/http"
56

67
"golang.org/x/mod/semver"
8+
"golang.org/x/xerrors"
79

810
"github.com/coder/coder/buildinfo"
911
"github.com/coder/coder/coderd/httpapi"
@@ -13,19 +15,28 @@ import (
1315
func (api *API) updateCheck(rw http.ResponseWriter, r *http.Request) {
1416
ctx := r.Context()
1517

18+
currentVersion := codersdk.UpdateCheckResponse{
19+
Current: true,
20+
Version: buildinfo.Version(),
21+
URL: buildinfo.ExternalURL(),
22+
}
23+
1624
if api.updateChecker == nil {
1725
// If update checking is disabled, echo the current
1826
// version.
19-
httpapi.Write(ctx, rw, http.StatusOK, codersdk.UpdateCheckResponse{
20-
Current: true,
21-
Version: buildinfo.Version(),
22-
URL: buildinfo.ExternalURL(),
23-
})
27+
httpapi.Write(ctx, rw, http.StatusOK, currentVersion)
2428
return
2529
}
2630

2731
uc, err := api.updateChecker.Latest(ctx)
2832
if err != nil {
33+
if xerrors.Is(err, sql.ErrNoRows) {
34+
// Update checking is enabled, but has never
35+
// succeeded, reproduce behavior as if disabled.
36+
httpapi.Write(ctx, rw, http.StatusOK, currentVersion)
37+
return
38+
}
39+
2940
httpapi.InternalServerError(rw, err)
3041
return
3142
}

0 commit comments

Comments
 (0)