Skip to content

Commit 46d0d04

Browse files
authored
Merge pull request ethereum#14685 from karalabe/ethdb-metrics-fail-fix
eth: gracefully error if database cannot be opened
2 parents b751cf3 + 01c9cf1 commit 46d0d04

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

eth/backend.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,13 @@ func makeExtraData(extra []byte) []byte {
200200
// CreateDB creates the chain database.
201201
func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Database, error) {
202202
db, err := ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles)
203+
if err != nil {
204+
return nil, err
205+
}
203206
if db, ok := db.(*ethdb.LDBDatabase); ok {
204207
db.Meter("eth/db/chaindata/")
205208
}
206-
return db, err
209+
return db, nil
207210
}
208211

209212
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service

node/service.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func (ctx *ServiceContext) OpenDatabase(name string, cache int, handles int) (et
4343
if ctx.config.DataDir == "" {
4444
return ethdb.NewMemDatabase()
4545
}
46-
return ethdb.NewLDBDatabase(ctx.config.resolvePath(name), cache, handles)
46+
db, err := ethdb.NewLDBDatabase(ctx.config.resolvePath(name), cache, handles)
47+
if err != nil {
48+
return nil, err
49+
}
50+
return db, nil
4751
}
4852

4953
// ResolvePath resolves a user path into the data directory if that was relative

0 commit comments

Comments
 (0)