Stop calling glog.Fatal* in a bunch of places

This commit is contained in:
Andrew Dunham 2015-04-15 14:07:45 -07:00
parent cacdb74e41
commit 1990eba055
7 changed files with 44 additions and 25 deletions

View file

@ -92,7 +92,10 @@ func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
}
qs.db = db
// BoolKey returns false on non-existence. IE, Sync by default.
qs.db.NoSync, _ = options.BoolKey("nosync")
qs.db.NoSync, _, err = options.BoolKey("nosync")
if err != nil {
return nil, err
}
err = qs.getMetadata()
if err != nil {
return nil, err

View file

@ -27,7 +27,6 @@ package iterator
// In MQL terms, this is the [{"age>=": 21}] concept.
import (
"log"
"strconv"
"github.com/google/cayley/graph"
@ -107,8 +106,7 @@ func RunIntOp(a int64, op Operator, b int64) bool {
case compareGTE:
return a >= b
default:
log.Fatal("Unknown operator type")
return false
panic("Unknown operator type")
}
}

View file

@ -90,7 +90,10 @@ func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
var err error
qs.path = path
cacheSize := DefaultCacheSize
if val, ok := options.IntKey("cache_size_mb"); ok {
val, ok, err := options.IntKey("cache_size_mb")
if err != nil {
return nil, err
} else if ok {
cacheSize = val
}
qs.dbOpts = &opt.Options{
@ -99,7 +102,10 @@ func newQuadStore(path string, options graph.Options) (graph.QuadStore, error) {
qs.dbOpts.ErrorIfMissing = true
writeBufferSize := DefaultWriteBufferSize
if val, ok := options.IntKey("writeBufferSize"); ok {
val, ok, err = options.IntKey("writeBufferSize")
if err != nil {
return nil, err
} else if ok {
writeBufferSize = val
}
qs.dbOpts.WriteBuffer = writeBufferSize * opt.MiB

View file

@ -57,7 +57,10 @@ func createNewMongoGraph(addr string, options graph.Options) error {
}
conn.SetSafe(&mgo.Safe{})
dbName := DefaultDBName
if val, ok := options.StringKey("database_name"); ok {
val, ok, err := options.StringKey("database_name")
if err != nil {
return err
} else if ok {
dbName = val
}
db := conn.DB(dbName)
@ -94,7 +97,10 @@ func newQuadStore(addr string, options graph.Options) (graph.QuadStore, error) {
}
conn.SetSafe(&mgo.Safe{})
dbName := DefaultDBName
if val, ok := options.StringKey("database_name"); ok {
val, ok, err := options.StringKey("database_name")
if err != nil {
return nil, err
} else if ok {
dbName = val
}
qs.db = conn.DB(dbName)

View file

@ -23,8 +23,8 @@ package graph
import (
"errors"
"fmt"
"github.com/barakmich/glog"
"github.com/google/cayley/quad"
)
@ -103,40 +103,40 @@ type QuadStore interface {
type Options map[string]interface{}
func (d Options) IntKey(key string) (int, bool) {
func (d Options) IntKey(key string) (int, bool, error) {
if val, ok := d[key]; ok {
switch vv := val.(type) {
case float64:
return int(vv), true
return int(vv), true, nil
default:
glog.Fatalln("Invalid", key, "parameter type from config.")
return 0, false, fmt.Errorf("Invalid %s parameter type from config: %T", key, val)
}
}
return 0, false
return 0, false, nil
}
func (d Options) StringKey(key string) (string, bool) {
func (d Options) StringKey(key string) (string, bool, error) {
if val, ok := d[key]; ok {
switch vv := val.(type) {
case string:
return vv, true
return vv, true, nil
default:
glog.Fatalln("Invalid", key, "parameter type from config.")
return "", false, fmt.Errorf("Invalid %s parameter type from config: %T", key, val)
}
}
return "", false
return "", false, nil
}
func (d Options) BoolKey(key string) (bool, bool) {
func (d Options) BoolKey(key string) (bool, bool, error) {
if val, ok := d[key]; ok {
switch vv := val.(type) {
case bool:
return vv, true
return vv, true, nil
default:
glog.Fatalln("Invalid", key, "parameter type from config.")
return false, false, fmt.Errorf("Invalid %s parameter type from config: %T", key, val)
}
}
return false, false
return false, false, nil
}
var ErrCannotBulkLoad = errors.New("quadstore: cannot bulk load")

View file

@ -17,7 +17,6 @@ package mql
import (
"errors"
"fmt"
"log"
"math"
"strings"
@ -93,7 +92,7 @@ func (q *Query) buildIteratorTreeInternal(query interface{}, path Path) (it grap
it = q.buildResultIterator(path)
optional = true
default:
log.Fatal("Unknown JSON type?", query)
err = fmt.Errorf("Unknown JSON type: %T")
}
if err != nil {
return nil, false, err

View file

@ -33,17 +33,24 @@ type Single struct {
func NewSingleReplication(qs graph.QuadStore, opts graph.Options) (graph.QuadWriter, error) {
var ignoreMissing, ignoreDuplicate bool
var err error
if *graph.IgnoreMissing {
ignoreMissing = true
} else {
ignoreMissing, _ = opts.BoolKey("ignore_missing")
ignoreMissing, _, err = opts.BoolKey("ignore_missing")
if err != nil {
return nil, err
}
}
if *graph.IgnoreDup {
ignoreDuplicate = true
} else {
ignoreDuplicate, _ = opts.BoolKey("ignore_duplicate")
ignoreDuplicate, _, err = opts.BoolKey("ignore_duplicate")
if err != nil {
return nil, err
}
}
return &Single{