From 5e7fe0383b2bb26af9e3a2eedfcf0af028545768 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 29 Jun 2014 18:56:19 +1000 Subject: [PATCH] Fix crash printing client status when a torrent info isn't available --- client.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 2e60d9b6..ad1afff6 100644 --- a/client.go +++ b/client.go @@ -118,7 +118,13 @@ func (cl *Client) WriteStatus(w io.Writer) { cl.mu.Lock() defer cl.mu.Unlock() for _, t := range cl.torrents { - fmt.Fprintf(w, "%s: %f%%\n", t.Name(), 100*(1-float32(t.BytesLeft())/float32(t.Length()))) + fmt.Fprintf(w, "%s: %f%%\n", t.Name(), func() float32 { + if !t.haveInfo() { + return 0 + } else { + return 100 * (1 - float32(t.BytesLeft())/float32(t.Length())) + } + }()) t.WriteStatus(w) } } -- 2.48.1