Skip to content

Commit e1b4674

Browse files
committed
hmm
1 parent edd2cf3 commit e1b4674

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

site/site.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func New(opts *Options) *Handler {
162162

163163
handler.installScript, err = parseInstallScript(opts.SiteFS, opts.BuildInfo)
164164
if err != nil {
165-
panic("failed to parse install script")
165+
_ = fmt.Errorf("install.sh will be unavailabe: %w", err)
166166
}
167167

168168
return handler
@@ -225,6 +225,10 @@ func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
225225
// If requesting the install.sh script, fill in the template with the
226226
// appropriate hostname and version info.
227227
case reqFile == "install.sh":
228+
if h.installScript == nil {
229+
http.NotFound(rw, r)
230+
return
231+
}
228232
rw.Header().Add("Content-Type", "text/plain; charset=utf-8")
229233
http.ServeContent(rw, r, reqFile, time.Time{}, bytes.NewReader(h.installScript))
230234
return
@@ -552,22 +556,22 @@ type installScriptState struct {
552556
func parseInstallScript(files fs.FS, buildInfo codersdk.BuildInfoResponse) ([]byte, error) {
553557
scriptFile, err := fs.ReadFile(files, "install.sh")
554558
if err != nil {
555-
return []byte{}, err
559+
return nil, err
556560
}
557561

558562
script, err := template.New("install.sh").Parse(string(scriptFile))
559563
if err != nil {
560-
return []byte{}, err
564+
return nil, err
561565
}
562566

563567
var buf bytes.Buffer
564568
state := installScriptState{Origin: buildInfo.DashboardURL, Version: buildInfo.Version}
565569
err = script.Execute(&buf, state)
566570
if err != nil {
567-
return []byte{}, err
571+
return nil, err
568572
}
569573

570-
return buf.Bytes(), err
574+
return buf.Bytes(), nil
571575
}
572576

573577
// ExtractOrReadBinFS checks the provided fs for compressed coder binaries and

site/site_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ func TestInjection(t *testing.T) {
4141
"index.html": &fstest.MapFile{
4242
Data: []byte("{{ .User }}"),
4343
},
44-
"install.sh": &fstest.MapFile{
45-
Data: []byte{},
46-
},
4744
}
4845
binFs := http.FS(fstest.MapFS{})
4946
db := dbmem.New()
@@ -102,9 +99,6 @@ func TestInjectionFailureProducesCleanHTML(t *testing.T) {
10299
"index.html": &fstest.MapFile{
103100
Data: []byte("<html>{{ .User }}</html>"),
104101
},
105-
"install.sh": &fstest.MapFile{
106-
Data: []byte{},
107-
},
108102
}
109103
handler := site.New(&site.Options{
110104
BinFS: binFs,
@@ -150,9 +144,6 @@ func TestCaching(t *testing.T) {
150144
"terminal.html": &fstest.MapFile{
151145
Data: []byte("folderFile"),
152146
},
153-
"install.sh": &fstest.MapFile{
154-
Data: []byte{},
155-
},
156147
}
157148
binFS := http.FS(fstest.MapFS{})
158149

@@ -363,9 +354,6 @@ func TestServingBin(t *testing.T) {
363354
"dashboard.css": &fstest.MapFile{
364355
Data: []byte("dashboard-css-bytes"),
365356
},
366-
"install.sh": &fstest.MapFile{
367-
Data: []byte{},
368-
},
369357
}
370358

371359
sampleBinFSCorrupted := sampleBinFS()

0 commit comments

Comments
 (0)