From 6820c0a5d7f85016d0e7ebf685e683d90f5a7672 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Tue, 28 Oct 2014 20:40:04 +0100 Subject: [PATCH] Don't crash on nil discoverer (fixes #917) --- cmd/syncthing/gui.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index ed219db9e..1408ee1b0 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -453,13 +453,15 @@ func restPostDiscoveryHint(w http.ResponseWriter, r *http.Request) { func restGetDiscovery(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json; charset=utf-8") - registry := discoverer.All() + devices := map[string][]discover.CacheEntry{} - // Device ids can't be marshalled as keys so we need to manually - // rebuild this map using strings. - devices := make(map[string][]discover.CacheEntry, len(registry)) - for device, _ := range registry { - devices[device.String()] = registry[device] + if discoverer != nil { + // Device ids can't be marshalled as keys so we need to manually + // rebuild this map using strings. Discoverer may be nil if discovery + // has not started yet. + for device, entries := range discoverer.All() { + devices[device.String()] = entries + } } json.NewEncoder(w).Encode(devices)