Remove even more Fatal* calls

This commit is contained in:
Andrew Dunham 2015-04-15 14:14:33 -07:00
parent 1990eba055
commit 7de923d40a
3 changed files with 15 additions and 9 deletions

View file

@ -17,6 +17,7 @@
package main package main
import ( import (
"fmt"
"github.com/barakmich/glog" "github.com/barakmich/glog"
"os" "os"
"time" "time"
@ -45,11 +46,11 @@ var (
timeout = 30 * time.Second timeout = 30 * time.Second
) )
func configFrom(file string) *config.Config { func configFrom(file string) (*config.Config, error) {
// Find the file... // Find the file...
if file != "" { if file != "" {
if _, err := os.Stat(file); os.IsNotExist(err) { if _, err := os.Stat(file); os.IsNotExist(err) {
glog.Fatalln("Cannot find specified configuration file", file, ", aborting.") return nil, fmt.Errorf("Cannot find specified configuration file", file)
} }
} else if _, err := os.Stat("/cayley_appengine.cfg"); err == nil { } else if _, err := os.Stat("/cayley_appengine.cfg"); err == nil {
file = "/cayley_appengine.cfg" file = "/cayley_appengine.cfg"
@ -59,7 +60,7 @@ func configFrom(file string) *config.Config {
} }
cfg, err := config.Load(file) cfg, err := config.Load(file)
if err != nil { if err != nil {
glog.Fatalln(err) return nil, err
} }
if cfg.DatabasePath == "" { if cfg.DatabasePath == "" {
@ -92,15 +93,19 @@ func configFrom(file string) *config.Config {
cfg.ReadOnly = cfg.ReadOnly || readOnly cfg.ReadOnly = cfg.ReadOnly || readOnly
return cfg return cfg, nil
} }
func init() { func init() {
glog.SetToStderr(true) glog.SetToStderr(true)
cfg := configFrom("cayley_appengine.cfg") cfg, err := configFrom("cayley_appengine.cfg")
if err != nil {
glog.Fatalln("Error loading config:", err)
}
handle, err := db.Open(cfg) handle, err := db.Open(cfg)
if err != nil { if err != nil {
glog.Fatal(err) glog.Fatalln("Error opening database:", err)
} }
http.SetupRoutes(handle, cfg) http.SetupRoutes(handle, cfg)
} }

View file

@ -154,7 +154,7 @@ func getContext(opts graph.Options) (appengine.Context, error) {
req := opts["HTTPRequest"].(*http.Request) req := opts["HTTPRequest"].(*http.Request)
if req == nil { if req == nil {
err := errors.New("HTTP Request needed") err := errors.New("HTTP Request needed")
glog.Fatalln(err) glog.Errorln(err)
return nil, err return nil, err
} }
return appengine.NewContext(req), nil return appengine.NewContext(req), nil

View file

@ -84,8 +84,9 @@ func (p *PrimaryKey) Int() int64 {
case sequential: case sequential:
return p.sequentialID return p.sequentialID
case unique: case unique:
glog.Fatal("UUID cannot be cast to an int64") msg := "UUID cannot be cast to an int64"
return -1 glog.Errorln(msg)
panic(msg)
} }
return -1 return -1
} }