1
1
package coderd
2
2
3
3
import (
4
+ "database/sql"
4
5
"net/http"
5
6
6
7
"golang.org/x/mod/semver"
8
+ "golang.org/x/xerrors"
7
9
8
10
"github.com/coder/coder/buildinfo"
9
11
"github.com/coder/coder/coderd/httpapi"
@@ -13,19 +15,28 @@ import (
13
15
func (api * API )updateCheck (rw http.ResponseWriter ,r * http.Request ) {
14
16
ctx := r .Context ()
15
17
18
+ currentVersion := codersdk.UpdateCheckResponse {
19
+ Current :true ,
20
+ Version :buildinfo .Version (),
21
+ URL :buildinfo .ExternalURL (),
22
+ }
23
+
16
24
if api .updateChecker == nil {
17
25
// If update checking is disabled, echo the current
18
26
// 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 )
24
28
return
25
29
}
26
30
27
31
uc ,err := api .updateChecker .Latest (ctx )
28
32
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
+
29
40
httpapi .InternalServerError (rw ,err )
30
41
return
31
42
}