mirror of
https://github.com/zyedidia/micro.git
synced 2024-09-11 12:15:52 +03:00
Adding timeout when fetching plugin & more clear plugin error message
This commit is contained in:
parent
1f71667616
commit
61ec1c30ac
@ -12,6 +12,7 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/blang/semver"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
@ -126,7 +127,10 @@ func (pc PluginChannels) Fetch(out io.Writer) PluginPackages {
|
||||
|
||||
// Fetch retrieves all available PluginPackages from the given channel
|
||||
func (pc PluginChannel) Fetch(out io.Writer) PluginPackages {
|
||||
resp, err := http.Get(string(pc))
|
||||
client := http.Client {
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
resp, err := client.Get(string(pc))
|
||||
if err != nil {
|
||||
fmt.Fprintln(out, "Failed to query plugin channel:\n", err)
|
||||
return PluginPackages{}
|
||||
@ -136,7 +140,7 @@ func (pc PluginChannel) Fetch(out io.Writer) PluginPackages {
|
||||
|
||||
var repositories []PluginRepository
|
||||
if err := decoder.Decode(&repositories); err != nil {
|
||||
fmt.Fprintln(out, "Failed to decode channel data:\n", err)
|
||||
fmt.Fprintln(out, "Failed to decode channel data", pc, ":\n", err)
|
||||
return PluginPackages{}
|
||||
}
|
||||
return fetchAllSources(len(repositories), func(i int) PluginPackages {
|
||||
@ -146,7 +150,10 @@ func (pc PluginChannel) Fetch(out io.Writer) PluginPackages {
|
||||
|
||||
// Fetch retrieves all available PluginPackages from the given repository
|
||||
func (pr PluginRepository) Fetch(out io.Writer) PluginPackages {
|
||||
resp, err := http.Get(string(pr))
|
||||
client := http.Client {
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
resp, err := client.Get(string(pr))
|
||||
if err != nil {
|
||||
fmt.Fprintln(out, "Failed to query plugin repository:\n", err)
|
||||
return PluginPackages{}
|
||||
@ -156,7 +163,7 @@ func (pr PluginRepository) Fetch(out io.Writer) PluginPackages {
|
||||
|
||||
var plugins PluginPackages
|
||||
if err := decoder.Decode(&plugins); err != nil {
|
||||
fmt.Fprintln(out, "Failed to decode repository data:\n", err)
|
||||
fmt.Fprintln(out, "Failed to decode repository data", pr, ":\n", err)
|
||||
return PluginPackages{}
|
||||
}
|
||||
if len(plugins) > 0 {
|
||||
@ -391,7 +398,10 @@ func GetInstalledPluginVersion(name string) string {
|
||||
// DownloadAndInstall downloads and installs the given plugin and version
|
||||
func (pv *PluginVersion) DownloadAndInstall(out io.Writer) error {
|
||||
fmt.Fprintf(out, "Downloading %q (%s) from %q\n", pv.pack.Name, pv.Version, pv.Url)
|
||||
resp, err := http.Get(pv.Url)
|
||||
client := http.Client {
|
||||
Timeout: 10 * time.Second,
|
||||
}
|
||||
resp, err := client.Get(pv.Url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user