Skip to content

Commit 0db8152

Browse files
Merge branch 'PluginTimeout' into dev
2 parents f793085 + df316f2 commit 0db8152

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

internal/config/plugin_installer.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"sort"
1313
"strings"
1414
"sync"
15+
"time"
1516

1617
"github.com/blang/semver"
1718
lua "github.com/yuin/gopher-lua"
@@ -126,9 +127,12 @@ func (pc PluginChannels) Fetch(out io.Writer) PluginPackages {
126127

127128
// Fetch retrieves all available PluginPackages from the given channel
128129
func (pc PluginChannel) Fetch(out io.Writer) PluginPackages {
129-
resp, err := http.Get(string(pc))
130+
client := http.Client {
131+
Timeout: 10 * time.Second,
132+
}
133+
resp, err := client.Get(string(pc))
130134
if err != nil {
131-
fmt.Fprintln(out, "Failed to query plugin channel:\n", err)
135+
fmt.Fprintln(out, "Failed to query plugin channel ", pc, " with error:\n", err)
132136
return PluginPackages{}
133137
}
134138
defer resp.Body.Close()
@@ -146,17 +150,20 @@ func (pc PluginChannel) Fetch(out io.Writer) PluginPackages {
146150

147151
// Fetch retrieves all available PluginPackages from the given repository
148152
func (pr PluginRepository) Fetch(out io.Writer) PluginPackages {
149-
resp, err := http.Get(string(pr))
153+
client := http.Client {
154+
Timeout: 10 * time.Second,
155+
}
156+
resp, err := client.Get(string(pr))
150157
if err != nil {
151-
fmt.Fprintln(out, "Failed to query plugin repository:\n", err)
158+
fmt.Fprintln(out, "Failed to query plugin repository", pr)
152159
return PluginPackages{}
153160
}
154161
defer resp.Body.Close()
155162
decoder := json5.NewDecoder(resp.Body)
156163

157164
var plugins PluginPackages
158165
if err := decoder.Decode(&plugins); err != nil {
159-
fmt.Fprintln(out, "Failed to decode repository data:\n", err)
166+
fmt.Fprintln(out, "Failed to decode repository data for", pr, "with error:\n", err)
160167
return PluginPackages{}
161168
}
162169
if len(plugins) > 0 {
@@ -391,7 +398,10 @@ func GetInstalledPluginVersion(name string) string {
391398
// DownloadAndInstall downloads and installs the given plugin and version
392399
func (pv *PluginVersion) DownloadAndInstall(out io.Writer) error {
393400
fmt.Fprintf(out, "Downloading %q (%s) from %q\n", pv.pack.Name, pv.Version, pv.Url)
394-
resp, err := http.Get(pv.Url)
401+
client := http.Client {
402+
Timeout: 10 * time.Second,
403+
}
404+
resp, err := client.Get(pv.Url)
395405
if err != nil {
396406
return err
397407
}

0 commit comments

Comments
 (0)