From 8024a8420bde4d881cf4f4027d29f9256b74a1c8 Mon Sep 17 00:00:00 2001 From: Vikram Rangnekar Date: Fri, 22 Nov 2019 00:58:03 -0500 Subject: [PATCH] Use logger error instead of panic in goja handlers --- serv/cmd_seed.go | 20 ++++++++++---------- tmpl/dev.yml | 2 +- tmpl/prod.yml | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/serv/cmd_seed.go b/serv/cmd_seed.go index db5a202..95ba3fb 100644 --- a/serv/cmd_seed.go +++ b/serv/cmd_seed.go @@ -62,7 +62,7 @@ func cmdDBSeed(cmd *cobra.Command, args []string) { func graphQLFunc(query string, data interface{}, opt map[string]string) map[string]interface{} { b, err := json.Marshal(data) if err != nil { - panic(err) + logger.Fatal().Err(err).Send() } ctx := context.Background() @@ -85,7 +85,7 @@ func graphQLFunc(query string, data interface{}, opt map[string]string) map[stri st, err := c.buildStmtByRole(role) if err != nil { - panic(fmt.Errorf("graphql query failed: %s", err)) + logger.Fatal().Err(err).Msg("graphql query failed") } buf := &bytes.Buffer{} @@ -94,47 +94,47 @@ func graphQLFunc(query string, data interface{}, opt map[string]string) map[stri _, err = t.ExecuteFunc(buf, argMap(c)) if err == errNoUserID { - panic(fmt.Errorf("query requires a user_id")) + logger.Fatal().Err(err).Msg("query requires a user_id") } if err != nil { - panic(err) + logger.Fatal().Err(err).Send() } finalSQL := buf.String() tx, err := db.Begin(c) if err != nil { - panic(err) + logger.Fatal().Err(err).Send() } defer tx.Rollback(c) if conf.DB.SetUserID { if err := c.setLocalUserID(tx); err != nil { - panic(err) + logger.Fatal().Err(err).Send() } } var root []byte if err = tx.QueryRow(c, finalSQL).Scan(&root); err != nil { - panic(fmt.Errorf("sql query failed: %s", err)) + logger.Fatal().Err(err).Msg("sql query failed") } if err := tx.Commit(c); err != nil { - panic(err) + logger.Fatal().Err(err).Send() } res, err := c.execRemoteJoin(st.qc, st.skipped, root) if err != nil { - panic(err) + logger.Fatal().Err(err).Send() } val := make(map[string]interface{}) err = json.Unmarshal(res, &val) if err != nil { - panic(fmt.Errorf("failed to deserialize json: %s", err)) + logger.Fatal().Err(err).Send() } return val diff --git a/tmpl/dev.yml b/tmpl/dev.yml index 0f20b0e..ba63cd5 100644 --- a/tmpl/dev.yml +++ b/tmpl/dev.yml @@ -3,7 +3,7 @@ host_port: 0.0.0.0:8080 web_ui: true # debug, info, warn, error, fatal, panic -log_level: "info" +log_level: "warn" # When production mode is 'true' only queries # from the allow list are permitted. diff --git a/tmpl/prod.yml b/tmpl/prod.yml index 1542554..47b3bdb 100644 --- a/tmpl/prod.yml +++ b/tmpl/prod.yml @@ -7,7 +7,7 @@ host_port: 0.0.0.0:8080 web_ui: false # debug, info, warn, error, fatal, panic, disable -log_level: "info" +log_level: "warn" # When production mode is 'true' only queries # from the allow list are permitted. # When it's 'false' all queries are saved to the