Skip to content

Commit cace224

Browse files
committed
removed os.Exit outside main
1 parent 237602f commit cace224

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

examples/storage/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"google.golang.org/grpc/credentials/insecure"
1010
)
1111

12-
func runClient(addresses []string) {
12+
func runClient(addresses []string) error {
1313
if len(addresses) < 1 {
1414
log.Fatalln("No addresses provided!")
1515
}
@@ -26,7 +26,7 @@ func runClient(addresses []string) {
2626
log.Fatal(err)
2727
}
2828

29-
Repl(mgr, cfg)
29+
return Repl(mgr, cfg)
3030
}
3131

3232
type qspec struct {

examples/storage/main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"flag"
55
"log"
6+
"os"
67
"strings"
78

89
"github.com/relab/gorums"
@@ -36,5 +37,7 @@ func main() {
3637
}()
3738
}
3839

39-
runClient(addrs)
40+
if runClient(addrs) != nil {
41+
os.Exit(1)
42+
}
4043
}

examples/storage/repl.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,23 +90,23 @@ func (r repl) ReadLine() (string, error) {
9090

9191
// Repl runs an interactive Read-eval-print loop, that allows users to run commands that perform
9292
// RPCs and quorum calls using the manager and configuration.
93-
func Repl(mgr *pb.Manager, defaultCfg *pb.Configuration) {
93+
func Repl(mgr *pb.Manager, defaultCfg *pb.Configuration) error {
9494
r := newRepl(mgr, defaultCfg)
9595

9696
fmt.Println(help)
9797
for {
9898
l, err := r.ReadLine()
9999
if errors.Is(err, io.EOF) {
100-
return
100+
return nil
101101
}
102102
if err != nil {
103103
fmt.Fprintf(os.Stderr, "Failed to read line: %v\n", err)
104-
os.Exit(1)
104+
return err
105105
}
106106
args, err := shlex.Split(l)
107107
if err != nil {
108108
fmt.Fprintf(os.Stderr, "Failed to split command: %v\n", err)
109-
os.Exit(1)
109+
return err
110110
}
111111
if len(args) < 1 {
112112
continue
@@ -116,7 +116,7 @@ func Repl(mgr *pb.Manager, defaultCfg *pb.Configuration) {
116116
case "exit":
117117
fallthrough
118118
case "quit":
119-
return
119+
return nil
120120
case "help":
121121
fmt.Println(help)
122122
case "rpc":

0 commit comments

Comments
 (0)