Skip to content

Commit acf0e30

Browse files
committed
Log and fail if db init fails
1 parent 9c4bfd8 commit acf0e30

File tree

4 files changed

+6
-4
lines changed

4 files changed

+6
-4
lines changed

balance/balance.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ func SetServices(services []core.Service) error {
106106
tab.RenameChain("filter", "portal-old", "portal")
107107
}
108108
if err == nil && tab != nil {
109-
cleanup := func(error) error {
109+
cleanup := func(err2 error) error {
110110
tab.ClearChain("filter", "portal")
111111
tab.DeleteChain("filter", "portal")
112112
tab.RenameChain("filter", "portal-old", "portal")
113-
return fmt.Errorf("Failed to tab.Insert() - %s", err)
113+
return fmt.Errorf("Failed to tab.Insert() - %s", err2)
114114
}
115115

116116
tab.NewChain("filter", "portal")

commands/commands.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var (
3131

3232
Portal = &cobra.Command{
3333
Use: "portal",
34-
Short: "portal - load balancer/proxy",
34+
Short: "load balancer/proxy",
3535
Long: ``,
3636
PersistentPreRunE: readConfig,
3737
PreRunE: preFlight,

database/database.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func Init() error {
4646
}
4747
err = Backend.Init()
4848
if err != nil {
49-
Backend = nil
49+
return fmt.Errorf("Failed to init database - %s", err)
5050
}
5151
return nil
5252
}

database/scribble.go

+2
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func (s ScribbleDatabase) GetRoutes() ([]core.Route, error) {
164164
routes := make([]core.Route, 0, 0)
165165
values, err := s.scribbleDb.ReadAll("routes")
166166
if err != nil {
167+
// todo: need to ensure db doesn't get cleared with new scribble (shared mutex) (previously if err finding .tmp file, db could be dropped)
167168
if strings.Contains(err.Error(), "no such file or directory") {
168169
// if error is about a missing db, return empty array
169170
return routes, nil
@@ -211,6 +212,7 @@ func (s ScribbleDatabase) SetRoute(route core.Route) error {
211212

212213
func (s ScribbleDatabase) DeleteRoute(route core.Route) error {
213214
routes, err := s.GetRoutes()
215+
// todo: need to ensure db doesn't get cleared with new scribble (shared mutex) (previously if err finding .tmp file, db could be dropped)
214216
if err != nil {
215217
return err
216218
}

0 commit comments

Comments
 (0)