Merge pull request #66 from prometheus/fix-meta-error-handling

Fix closing of meta file if meta encoding failed
This commit is contained in:
Fabian Reinartz 2017-04-28 16:06:42 +02:00 committed by GitHub
commit 2c46815adb

View file

@ -137,8 +137,10 @@ func writeMetaFile(dir string, meta *BlockMeta) error {
enc := json.NewEncoder(f)
enc.SetIndent("", "\t")
if err := enc.Encode(&blockMeta{Version: 1, BlockMeta: meta}); err != nil {
return err
var merr MultiError
if merr.Add(enc.Encode(&blockMeta{Version: 1, BlockMeta: meta})); merr.Err() != nil {
merr.Add(f.Close())
return merr
}
if err := f.Close(); err != nil {
return err