Skip to content

Commit 5ad4d7e

Browse files
committed
Removed the log.Fatal(s) from the app/
1 parent 57e853b commit 5ad4d7e

File tree

2 files changed

+34
-24
lines changed

2 files changed

+34
-24
lines changed

app/client.go

+30-21
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ func startQuery(el *onet.Roster, proofs bool, sum []string, count bool, whereQue
2727

2828
surveyID, err := client.SendSurveyCreationQuery(el, servicesunlynx.SurveyID(""), nil, nbrDPs, proofs, true, sum, count, whereQueryValues, predicate, groupBy)
2929
if err != nil {
30-
log.Fatal("Service did not start.", err)
30+
log.Error("Service did not start.", err)
31+
return
3132
}
3233

3334
grp, aggr, err := client.SendSurveyResultsQuery(*surveyID)
3435
if err != nil {
35-
log.Fatal("Service could not output the results.", err)
36+
log.Error("Service could not output the results.", err)
37+
return
3638
}
3739

3840
// Print Output
@@ -44,7 +46,7 @@ func startQuery(el *onet.Roster, proofs bool, sum []string, count bool, whereQue
4446
}
4547
}
4648

47-
func runUnLynx(c *cli.Context) error {
49+
func runUnLynx(c *cli.Context) {
4850
tomlFileName := c.String("file")
4951

5052
proofs := c.Bool("proofs")
@@ -58,13 +60,19 @@ func runUnLynx(c *cli.Context) error {
5860

5961
el, err := openGroupToml(tomlFileName)
6062
if err != nil {
61-
return err
63+
log.Error("Could not open group toml:", err)
64+
return
65+
}
66+
67+
sumFinal, countFinal, whereFinal, predicateFinal, groupByFinal, err := parseQuery(el, sum, count, whereQueryValues, predicate, groupBy)
68+
if err != nil {
69+
log.Error(err)
70+
return
6271
}
6372

64-
sumFinal, countFinal, whereFinal, predicateFinal, groupByFinal := parseQuery(el, sum, count, whereQueryValues, predicate, groupBy)
6573
startQuery(el, proofs, sumFinal, countFinal, whereFinal, predicateFinal, groupByFinal)
6674

67-
return nil
75+
return
6876
}
6977

7078
func openGroupToml(tomlFileName string) (*onet.Roster, error) {
@@ -84,27 +92,24 @@ func openGroupToml(tomlFileName string) (*onet.Roster, error) {
8492
return el.Roster, nil
8593
}
8694

87-
func checkRegex(input, expression, errorMessage string) {
95+
func checkRegex(input, expression string) bool{
8896
var aux = regexp.MustCompile(expression)
89-
90-
correct := aux.MatchString(input)
91-
92-
if !correct {
93-
log.Fatal(errorMessage)
94-
}
97+
return aux.MatchString(input)
9598
}
9699

97-
func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, groupBy string) ([]string, bool, []libunlynx.WhereQueryAttribute, string, []string) {
100+
func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, groupBy string) ([]string, bool, []libunlynx.WhereQueryAttribute, string, []string, error) {
98101

99102
if sum == "" || (where != "" && predicate == "") || (where == "" && predicate != "") {
100-
log.Fatal("Wrong query! Please check the sum, where and the predicate parameters")
103+
return nil, false, nil, "", nil, errors.New("Wrong query! Please check the sum, where and the predicate parameters")
101104
}
102105

103106
sumRegex := "{s[0-9]+(,\\s*s[0-9]+)*}"
104107
whereRegex := "{(w[0-9]+(,\\s*[0-9]+))*(,\\s*w[0-9]+(,\\s*[0-9]+))*}"
105108
groupByRegex := "{g[0-9]+(,\\s*g[0-9]+)*}"
106109

107-
checkRegex(sum, sumRegex, "Error parsing the sum parameter(s)")
110+
if !checkRegex(sum, sumRegex) {
111+
return nil, false, nil, "", nil, errors.New("Error parsing the sum parameter(s)")
112+
}
108113
sum = strings.Replace(sum, " ", "", -1)
109114
sum = strings.Replace(sum, "{", "", -1)
110115
sum = strings.Replace(sum, "}", "", -1)
@@ -119,11 +124,13 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
119124
}
120125

121126
if !check {
122-
log.Fatal("No 'count' attribute in the sum variables")
127+
return nil, false, nil, "", nil, errors.New("No 'count' attribute in the sum variables")
123128
}
124129
}
125130

126-
checkRegex(where, whereRegex, "Error parsing the where parameter(s)")
131+
if !checkRegex(where, whereRegex) {
132+
return nil, false, nil, "", nil, errors.New("Error parsing the where parameter(s)")
133+
}
127134
where = strings.Replace(where, " ", "", -1)
128135
where = strings.Replace(where, "{", "", -1)
129136
where = strings.Replace(where, "}", "", -1)
@@ -139,20 +146,22 @@ func parseQuery(el *onet.Roster, sum string, count bool, where, predicate, group
139146
} else { // if it is a value
140147
value, err := strconv.Atoi(tmp[i])
141148
if err != nil {
142-
log.Fatal(err)
149+
return nil, false, nil, "", nil, err
143150
}
144151

145152
whereFinal = append(whereFinal, libunlynx.WhereQueryAttribute{Name: variable, Value: *libunlynx.EncryptInt(el.Aggregate, int64(value))})
146153
}
147154
}
148155

149-
checkRegex(groupBy, groupByRegex, "Error parsing the groupBy parameter(s)")
156+
if !checkRegex(groupBy, groupByRegex) {
157+
return nil, false, nil, "", nil, errors.New("Error parsing the groupBy parameter(s)")
158+
}
150159
groupBy = strings.Replace(groupBy, " ", "", -1)
151160
groupBy = strings.Replace(groupBy, "{", "", -1)
152161
groupBy = strings.Replace(groupBy, "}", "", -1)
153162
groupByFinal := strings.Split(groupBy, ",")
154163

155-
return sumFinal, count, whereFinal, predicate, groupByFinal
164+
return sumFinal, count, whereFinal, predicate, groupByFinal, nil
156165
}
157166

158167
// CLIENT END: QUERIER ----------

app/unlynx.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package appunlynx
33
import (
44
"os"
55

6+
"github.com/btcsuite/goleveldb/leveldb/errors"
67
"github.com/lca1/unlynx/lib"
78
"go.dedis.ch/onet/v3/app"
89
"go.dedis.ch/onet/v3/log"
@@ -122,7 +123,7 @@ func main() {
122123
Usage: "Start unlynx server",
123124
Action: func(c *cli.Context) error {
124125
if err := runServer(c); err != nil {
125-
log.Fatal("Error during runServer():", err)
126+
return errors.New("Error during runServer():" + err.Error())
126127
}
127128
return nil
128129
},
@@ -134,10 +135,10 @@ func main() {
134135
Usage: "Setup server configuration (interactive)",
135136
Action: func(c *cli.Context) error {
136137
if c.String(optionConfig) != "" {
137-
log.Fatal("[-] Configuration file option cannot be used for the 'setup' command")
138+
return errors.New("[-] Configuration file option cannot be used for the 'setup' command")
138139
}
139140
if c.GlobalIsSet("debug") {
140-
log.Fatal("[-] Debug option cannot be used for the 'setup' command")
141+
return errors.New("[-] Debug option cannot be used for the 'setup' command")
141142
}
142143
app.InteractiveConfig(libunlynx.SuiTe, BinaryName)
143144
return nil

0 commit comments

Comments
 (0)