From 849f23b5071411e03dd9ddf01fb9549d185af6e6 Mon Sep 17 00:00:00 2001 From: Fred Boniface Date: Fri, 21 Jul 2023 09:36:23 +0100 Subject: [PATCH] Fix parsing errors where 'CIF_speed' is not defined --- src/go.mod | 2 +- src/go.sum | 4 ++++ src/vstp/parser.go | 9 +++++++-- src/vstp/subscribe.go | 4 ++-- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/go.mod b/src/go.mod index 26824c4..8e94012 100644 --- a/src/go.mod +++ b/src/go.mod @@ -3,7 +3,7 @@ module git.fjla.uk/owlboard/mq-client go 1.19 require ( - git.fjla.uk/owlboard/go-types v0.0.0-20230720203835-cf2b2d98e86a + git.fjla.uk/owlboard/go-types v0.0.0-20230721082911-9a574276d572 github.com/go-stomp/stomp/v3 v3.0.5 go.mongodb.org/mongo-driver v1.12.0 go.uber.org/zap v1.24.0 diff --git a/src/go.sum b/src/go.sum index c388078..cf38e19 100644 --- a/src/go.sum +++ b/src/go.sum @@ -28,6 +28,10 @@ git.fjla.uk/owlboard/go-types v0.0.0-20230720202112-4df6f0456ea4 h1:HeHukiRnDzXN git.fjla.uk/owlboard/go-types v0.0.0-20230720202112-4df6f0456ea4/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY= git.fjla.uk/owlboard/go-types v0.0.0-20230720203835-cf2b2d98e86a h1:JvDUM2sIawyyLKhIOgciAj0PpVWziYlXb+RA2IgphMg= git.fjla.uk/owlboard/go-types v0.0.0-20230720203835-cf2b2d98e86a/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY= +git.fjla.uk/owlboard/go-types v0.0.0-20230721082815-634948b5448c h1:KGxtm/m+uPo2xmZIKebUxmMQnb72hY6+GQ7ZRez/iy8= +git.fjla.uk/owlboard/go-types v0.0.0-20230721082815-634948b5448c/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY= +git.fjla.uk/owlboard/go-types v0.0.0-20230721082911-9a574276d572 h1:shnlNyIV1jG+xQsg5zCt2fEjiDzCQQeDTjTFuKZa97c= +git.fjla.uk/owlboard/go-types v0.0.0-20230721082911-9a574276d572/go.mod h1:kG+BX9UF+yJaAVnln/QSKlTdrtKRRReezMeSk1ZLMzY= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= diff --git a/src/vstp/parser.go b/src/vstp/parser.go index 0a7ac85..fcb52a8 100644 --- a/src/vstp/parser.go +++ b/src/vstp/parser.go @@ -41,6 +41,7 @@ func formatData(dataInput *upstreamApi.Schedule) database.Service { service := database.Service{ TransactionType: dataInput.TransactionType, StpIndicator: dataInput.CIFSTPIndicator, + Vstp: true, Operator: dataInput.ScheduleSegment[0].ATOCCode, TrainUid: dataInput.CIFTrainUID, Headcode: dataInput.ScheduleSegment[0].SignallingID, @@ -56,7 +57,11 @@ func formatData(dataInput *upstreamApi.Schedule) database.Service { // Uses the map provided in 'helpers' to translate incorrect CIF speeds to their correct equivalent func parseSpeed(CIFSpeed string) int32 { - log.Msg.Debug("CIFSpeed Input: " + CIFSpeed) + log.Msg.Debug("CIFSpeed Input: '" + CIFSpeed + "'") + if CIFSpeed == "" { + log.Msg.Debug("Speed data not provided") + return int32(0) + } actualSpeed, exists := helpers.SpeedMap[CIFSpeed] if !exists { actualSpeed = CIFSpeed @@ -65,7 +70,7 @@ func parseSpeed(CIFSpeed string) int32 { speed, err := strconv.ParseInt(actualSpeed, 10, 32) if err != nil { - log.Msg.Warn("Unable to parse speed: " + CIFSpeed + ", returning nil") + log.Msg.Warn("Unable to parse speed: " + CIFSpeed + ", returning 0") return int32(0) } return int32(speed) diff --git a/src/vstp/subscribe.go b/src/vstp/subscribe.go index e53fcbd..7f68826 100644 --- a/src/vstp/subscribe.go +++ b/src/vstp/subscribe.go @@ -19,9 +19,9 @@ func Subscribe() { for { msg := <-sub.C if msg.Err != nil { - log.Msg.Error("STOMP Message Error: " + msg.Err.Error()) + log.Msg.Error("\nSTOMP Message Error: " + msg.Err.Error()) } else { - log.Msg.Debug("STOMP Message Received") + log.Msg.Debug("\nSTOMP Message Received") saveToFile(string(msg.Body), "msgBody") handle(msg) }