cleanup: replace common.Exit with log.Crit or log.Fatal

Later we can pick another logger that has fatal, like zap?
This commit is contained in:
Tzu-Jung Lee 2017-01-16 23:09:33 -08:00
parent 1150bbfe36
commit 9134905f42
10 changed files with 28 additions and 21 deletions

View File

@ -6,12 +6,12 @@ import (
"errors"
"fmt"
"io"
"log"
"os"
"strings"
"github.com/tendermint/abci/client"
"github.com/tendermint/abci/types"
common "github.com/tendermint/go-common"
"github.com/urfave/cli"
)
@ -135,7 +135,7 @@ func main() {
app.Before = before
err := app.Run(os.Args)
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
}
@ -145,7 +145,7 @@ func before(c *cli.Context) error {
var err error
client, err = abcicli.NewClient(c.GlobalString("address"), c.GlobalString("abci"), false)
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
}
return nil

View File

@ -2,6 +2,7 @@ package main
import (
"flag"
"log"
"github.com/tendermint/abci/example/counter"
"github.com/tendermint/abci/server"
@ -19,7 +20,7 @@ func main() {
// Start the listener
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
// Wait forever

View File

@ -2,6 +2,7 @@ package main
import (
"flag"
"log"
"github.com/tendermint/abci/example/dummy"
"github.com/tendermint/abci/server"
@ -27,7 +28,7 @@ func main() {
// Start the listener
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
// Wait forever

View File

@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"log"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
@ -18,7 +19,7 @@ func main() {
// Start the listener
srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
// Wait forever

View File

@ -1,6 +1,8 @@
package main
import (
"fmt"
"log"
"strconv"
"strings"
"testing"
@ -8,7 +10,6 @@ import (
"github.com/tendermint/abci/client"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
common "github.com/tendermint/go-common"
)
func TestChainAware(t *testing.T) {
@ -25,7 +26,7 @@ func TestChainAware(t *testing.T) {
// Connect to the socket
client, err := abcicli.NewSocketClient("unix://test.sock", false)
if err != nil {
common.Exit(Fmt("Error starting socket client: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error starting socket client: %v", err.Error()))
}
client.Start()
defer client.Stop()

View File

@ -136,7 +136,7 @@ func LoadLastBlock(db dbm.DB) (lastBlock LastBlockInfo) {
wire.ReadBinaryPtr(&lastBlock, r, 0, n, err)
if *err != nil {
// DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED
common.Exit(fmt.Sprintf("Data has been corrupted or its spec has changed: %v\n", *err))
log.Crit(fmt.Sprintf("Data has been corrupted or its spec has changed: %v\n", *err))
}
// TODO: ensure that buf is completely read.
}

View File

@ -2,6 +2,7 @@ package example
import (
"fmt"
"log"
"net"
"reflect"
"testing"
@ -41,14 +42,14 @@ func testStream(t *testing.T, app types.Application) {
// Start the listener
server, err := server.NewSocketServer("unix://test.sock", app)
if err != nil {
common.Exit(fmt.Sprintf("Error starting socket server: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error starting socket server: %v", err.Error()))
}
defer server.Stop()
// Connect to the socket
client, err := abcicli.NewSocketClient("unix://test.sock", false)
if err != nil {
common.Exit(fmt.Sprintf("Error starting socket client: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error starting socket client: %v", err.Error()))
}
client.Start()
defer client.Stop()
@ -104,7 +105,7 @@ func testStream(t *testing.T, app types.Application) {
// test grpc
func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) {
return Connect(addr)
return common.Connect(addr)
}
func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
@ -114,14 +115,14 @@ func testGRPCSync(t *testing.T, app *types.GRPCApplication) {
// Start the listener
server, err := server.NewGRPCServer("unix://test.sock", app)
if err != nil {
common.Exit(fmt.Sprintf("Error starting GRPC server: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error starting GRPC server: %v", err.Error()))
}
defer server.Stop()
// Connect to the socket
conn, err := grpc.Dial("unix://test.sock", grpc.WithInsecure(), grpc.WithDialer(dialerFunc))
if err != nil {
common.Exit(fmt.Sprintf("Error dialing GRPC server: %v", err.Error()))
log.Fatal(fmt.Sprintf("Error dialing GRPC server: %v", err.Error()))
}
defer conn.Close()

View File

@ -100,7 +100,7 @@ func (s *SocketServer) acceptConnectionsRoutine() {
if !s.IsRunning() {
return // Ignore error from listener closing.
}
common.Exit("Failed to accept connection: " + err.Error())
log.Crit("Failed to accept connection: " + err.Error())
} else {
log.Notice("Accepted a new connection")
}

View File

@ -3,6 +3,7 @@ package main
import (
"bufio"
"fmt"
"log"
"github.com/tendermint/abci/types"
common "github.com/tendermint/go-common"
@ -12,7 +13,7 @@ func main() {
conn, err := common.Connect("unix://test.sock")
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
// Read a bunch of responses
@ -22,7 +23,7 @@ func main() {
var res = &types.Response{}
err := types.ReadMessage(conn, res)
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
counter += 1
if counter%1000 == 0 {
@ -39,11 +40,11 @@ func main() {
err := types.WriteMessage(req, bufWriter)
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
err = bufWriter.Flush()
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
counter += 1

View File

@ -4,6 +4,7 @@ import (
"bufio"
"errors"
"fmt"
"log"
"net"
"reflect"
@ -15,7 +16,7 @@ func main() {
conn, err := common.Connect("unix://test.sock")
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
// Make a bunch of requests
@ -24,7 +25,7 @@ func main() {
req := types.ToRequestEcho("foobar")
_, err := makeRequest(conn, req)
if err != nil {
common.Exit(err.Error())
log.Fatal(err.Error())
}
counter += 1
if counter%1000 == 0 {