mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-02-26 15:47:21 +00:00
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:
parent
21b035eb29
commit
ec6d104404
1 changed files with 5 additions and 4 deletions
|
|
@ -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}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue