Browse Source

cleanup: remove redundant error plumbing (#6778)

This is a mostly-automated fixup using Comby (https://comby.dev) to remove 
lexically-obvious redundant error checks. No functional changes are intended.

To reproduce the core change:

    # Collapse redundant error check conditionals
    % comby -in-place 'if err != nil {
       return err
    }
    return nil' 'return err' .go

    # Fold out unnecessary error temporaries
    % comby -in-place ':[spc~^\s*]err :[~:?]= :[any]
       return err' ':[spc]return :[any]' .go

Fixes #6479 and related cases.
pull/6781/head
M. J. Fromberger 3 years ago
committed by GitHub
parent
commit
8f06e0c9e7
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 10 additions and 51 deletions
  1. +1
    -5
      abci/types/messages.go
  2. +1
    -6
      privval/signer_listener_endpoint.go
  3. +1
    -6
      state/indexer/sink/psql/psql_test.go
  4. +1
    -6
      state/store.go
  5. +3
    -17
      test/e2e/runner/cleanup.go
  6. +1
    -4
      test/e2e/runner/wait.go
  7. +1
    -2
      test/fuzz/rpc/jsonrpc/server/handler.go
  8. +1
    -5
      types/node_key.go

+ 1
- 5
abci/types/messages.go View File

@ -15,11 +15,7 @@ const (
func WriteMessage(msg proto.Message, w io.Writer) error { func WriteMessage(msg proto.Message, w io.Writer) error {
protoWriter := protoio.NewDelimitedWriter(w) protoWriter := protoio.NewDelimitedWriter(w)
_, err := protoWriter.WriteMsg(msg) _, err := protoWriter.WriteMsg(msg)
if err != nil {
return err
}
return nil
return err
} }
// ReadMessage reads a varint length-delimited protobuf message. // ReadMessage reads a varint length-delimited protobuf message.


+ 1
- 6
privval/signer_listener_endpoint.go View File

@ -142,12 +142,7 @@ func (sl *SignerListenerEndpoint) ensureConnection(maxWait time.Duration) error
// block until connected or timeout // block until connected or timeout
sl.Logger.Info("SignerListener: Blocking for connection") sl.Logger.Info("SignerListener: Blocking for connection")
sl.triggerConnect() sl.triggerConnect()
err := sl.WaitConnection(sl.connectionAvailableCh, maxWait)
if err != nil {
return err
}
return nil
return sl.WaitConnection(sl.connectionAvailableCh, maxWait)
} }
func (sl *SignerListenerEndpoint) acceptNewConnection() (net.Conn, error) { func (sl *SignerListenerEndpoint) acceptNewConnection() (net.Conn, error) {


+ 1
- 6
state/indexer/sink/psql/psql_test.go View File

@ -255,12 +255,7 @@ func verifyTimeStamp(tb string) error {
if rows.Next() { if rows.Next() {
var ts string var ts string
err = rows.Scan(&ts)
if err != nil {
return err
}
return nil
return rows.Scan(&ts)
} }
return errors.New("no result") return errors.New("no result")


+ 1
- 6
state/store.go View File

@ -661,10 +661,5 @@ func (store dbStore) saveConsensusParamsInfo(
return err return err
} }
err = batch.Set(consensusParamsKey(nextHeight), bz)
if err != nil {
return err
}
return nil
return batch.Set(consensusParamsKey(nextHeight), bz)
} }

+ 3
- 17
test/e2e/runner/cleanup.go View File

@ -15,11 +15,7 @@ func Cleanup(testnet *e2e.Testnet) error {
if err != nil { if err != nil {
return err return err
} }
err = cleanupDir(testnet.Dir)
if err != nil {
return err
}
return nil
return cleanupDir(testnet.Dir)
} }
// cleanupDocker removes all E2E resources (with label e2e=True), regardless // cleanupDocker removes all E2E resources (with label e2e=True), regardless
@ -37,13 +33,8 @@ func cleanupDocker() error {
return err return err
} }
err = exec("bash", "-c", fmt.Sprintf(
return exec("bash", "-c", fmt.Sprintf(
"docker network ls -q --filter label=e2e | xargs %v docker network rm", xargsR)) "docker network ls -q --filter label=e2e | xargs %v docker network rm", xargsR))
if err != nil {
return err
}
return nil
} }
// cleanupDir cleans up a testnet directory // cleanupDir cleans up a testnet directory
@ -74,10 +65,5 @@ func cleanupDir(dir string) error {
return err return err
} }
err = os.RemoveAll(dir)
if err != nil {
return err
}
return nil
return os.RemoveAll(dir)
} }

+ 1
- 4
test/e2e/runner/wait.go View File

@ -21,10 +21,7 @@ func Wait(testnet *e2e.Testnet, blocks int64) error {
func WaitUntil(testnet *e2e.Testnet, height int64) error { func WaitUntil(testnet *e2e.Testnet, height int64) error {
logger.Info(fmt.Sprintf("Waiting for all nodes to reach height %v...", height)) logger.Info(fmt.Sprintf("Waiting for all nodes to reach height %v...", height))
_, err := waitForAllNodes(testnet, height, waitingTime(len(testnet.Nodes))) _, err := waitForAllNodes(testnet, height, waitingTime(len(testnet.Nodes)))
if err != nil {
return err
}
return nil
return err
} }
// waitingTime estimates how long it should take for a node to reach the height. // waitingTime estimates how long it should take for a node to reach the height.


+ 1
- 2
test/fuzz/rpc/jsonrpc/server/handler.go View File

@ -59,6 +59,5 @@ func Fuzz(data []byte) int {
func outputJSONIsSlice(input []byte) bool { func outputJSONIsSlice(input []byte) bool {
slice := []interface{}{} slice := []interface{}{}
err := json.Unmarshal(input, &slice)
return err == nil
return json.Unmarshal(input, &slice) == nil
} }

+ 1
- 5
types/node_key.go View File

@ -33,11 +33,7 @@ func (nodeKey NodeKey) SaveAs(filePath string) error {
if err != nil { if err != nil {
return err return err
} }
err = ioutil.WriteFile(filePath, jsonBytes, 0600)
if err != nil {
return err
}
return nil
return ioutil.WriteFile(filePath, jsonBytes, 0600)
} }
// LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If // LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If


Loading…
Cancel
Save