From 0dbb594276e2f8c8dd4802301047f65883412181 Mon Sep 17 00:00:00 2001 From: Mark Newman Date: Fri, 16 Jun 2017 18:11:29 +0100 Subject: [PATCH] Clean up error handling --- component.go | 9 ++++++--- event.go | 9 --------- service.go | 12 ++++++------ 3 files changed, 12 insertions(+), 18 deletions(-) delete mode 100644 event.go diff --git a/component.go b/component.go index 8c616db..aa5db03 100644 --- a/component.go +++ b/component.go @@ -6,6 +6,7 @@ package main import ( "encoding/json" + "log" "strings" "github.com/nats-io/nats" @@ -29,17 +30,19 @@ func processComponent(msg *nats.Msg) { c.Subject = msg.Subject if err := json.Unmarshal(msg.Data, &c); err != nil { - panic(err) + log.Println(err) + return } id := c.getID() data, err := json.Marshal(c) if err != nil { - panic(err) + log.Println(err) + return } - publishEvent(id, data) + ss.Publish(id, data) } func (c *Component) getID() string { diff --git a/event.go b/event.go deleted file mode 100644 index 3fd9e46..0000000 --- a/event.go +++ /dev/null @@ -1,9 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -package main - -func publishEvent(id string, data []byte) { - ss.Publish(id, data) -} diff --git a/service.go b/service.go index 510c22c..59512b8 100644 --- a/service.go +++ b/service.go @@ -26,14 +26,16 @@ func processService(msg *nats.Msg) { s.Subject = msg.Subject if err := json.Unmarshal(msg.Data, &s); err != nil { - panic(err) + log.Println(err) + return } id := s.getID() data, err := json.Marshal(s) if err != nil { - panic(err) + log.Println(err) + return } switch msg.Subject { @@ -41,11 +43,9 @@ func processService(msg *nats.Msg) { // Create new stream log.Println("Creating stream: ", id) ss.CreateStream(id) - publishEvent(id, data) + ss.Publish(id, data) case "service.create.done", "service.create.error", "service.delete.done", "service.delete.error", "service.import.done", "service.import.error": - publishEvent(id, data) - // publishEvent(id, cliHangup) - + ss.Publish(id, data) time.Sleep(10 * time.Millisecond) // Remove stream when the build completes log.Println("Closing stream: ", id)