From 13b338b204582601b0c51e3cd45ab7efb5dc445f Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Fri, 17 Feb 2012 00:22:46 +0100 Subject: [PATCH] Modify error on Gob panic --- cache.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cache.go b/cache.go index e33de24..e4e394d 100644 --- a/cache.go +++ b/cache.go @@ -202,6 +202,7 @@ func (c *cache) DeleteExpired() { func (c *cache) Save(w io.Writer) error { enc := gob.NewEncoder(w) + var err error defer func() { if x := recover(); x != nil { fmt.Printf(`The Gob library paniced while registering the cache's item types! @@ -211,12 +212,13 @@ The cache will not be saved. Please report under what conditions this happened, and particularly what special type of objects were stored in cache, at https://github.com/pmylund/go-cache/issues/new `, x) + err = fmt.Errorf("Error registering item types with Gob library") } }() for _, v := range c.Items { gob.Register(v.Object) } - err := enc.Encode(&c.Items) + err = enc.Encode(&c.Items) return err }