1
0
Fork 0
forked from forks/go-ethereum

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
This commit is contained in:
Ocenka 2025-04-08 15:44:13 +03:00 committed by GitHub
parent 21b035eb29
commit ec6d104404
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -34,7 +34,7 @@ type Database struct {
func (db *Database) Has(key []byte) (bool, error) {
if _, err := db.Get(key); err != nil {
return false, nil
return false, err
}
return true, nil
}
@ -50,7 +50,7 @@ func (db *Database) Get(key []byte) ([]byte, error) {
func (db *Database) HasAncient(kind string, number uint64) (bool, error) {
if _, err := db.Ancient(kind, number); err != nil {
return false, nil
return false, err
}
return true, nil
}
@ -144,7 +144,8 @@ func (db *Database) Close() error {
}
func New(client *rpc.Client) ethdb.Database {
return &Database{
remote: client,
if client == nil {
return nil
}
return &Database{remote: client}
}