Skip to content

Commit ec6d104

Browse files
authored
eth/remotedb: improve error handling (#31331)
This PR improves error handling in the remotedb package by fixing two issues: 1. In the `Has` method, we now properly propagate errors instead of silently returning false. This makes the behavior more predictable and helps clients better understand when there are connection issues. 2. In the `New` constructor, we add a nil check for the client parameter to prevent potential panics. This follows Go best practices for constructor functions. These changes make the code more robust and follow Go's error handling idioms without requiring any changes to other parts of the codebase. Changes: - Modified `Has` method to return errors instead of silently returning false - Added nil check in `New` constructor - Fixed field name in constructor to match struct definition
1 parent 21b035e commit ec6d104

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

ethdb/remotedb/remotedb.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type Database struct {
3434

3535
func (db *Database) Has(key []byte) (bool, error) {
3636
if _, err := db.Get(key); err != nil {
37-
return false, nil
37+
return false, err
3838
}
3939
return true, nil
4040
}
@@ -50,7 +50,7 @@ func (db *Database) Get(key []byte) ([]byte, error) {
5050

5151
func (db *Database) HasAncient(kind string, number uint64) (bool, error) {
5252
if _, err := db.Ancient(kind, number); err != nil {
53-
return false, nil
53+
return false, err
5454
}
5555
return true, nil
5656
}
@@ -144,7 +144,8 @@ func (db *Database) Close() error {
144144
}
145145

146146
func New(client *rpc.Client) ethdb.Database {
147-
return &Database{
148-
remote: client,
147+
if client == nil {
148+
return nil
149149
}
150+
return &Database{remote: client}
150151
}

0 commit comments

Comments
 (0)