sm
/
cache
1
0
Fork 0

Modify error on Gob panic

This commit is contained in:
Patrick Mylund Nielsen 2012-02-17 00:22:46 +01:00
parent dfeb3cfa2b
commit 13b338b204
1 changed files with 3 additions and 1 deletions

View File

@ -202,6 +202,7 @@ func (c *cache) DeleteExpired() {
func (c *cache) Save(w io.Writer) error { func (c *cache) Save(w io.Writer) error {
enc := gob.NewEncoder(w) enc := gob.NewEncoder(w)
var err error
defer func() { defer func() {
if x := recover(); x != nil { if x := recover(); x != nil {
fmt.Printf(`The Gob library paniced while registering the cache's item types! 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 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 were stored in cache, at https://github.com/pmylund/go-cache/issues/new
`, x) `, x)
err = fmt.Errorf("Error registering item types with Gob library")
} }
}() }()
for _, v := range c.Items { for _, v := range c.Items {
gob.Register(v.Object) gob.Register(v.Object)
} }
err := enc.Encode(&c.Items) err = enc.Encode(&c.Items)
return err return err
} }