From 695abd35ca1eac529d168baac6b587d572581194 Mon Sep 17 00:00:00 2001 From: Dhadve Yash <109629956+Exar04@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:42:23 +0000 Subject: [PATCH] removed redundent nil error checking in pkg/runfileconfig/run_file_config_parser.go and added proper error handling while unmarshalling json in pkg/runfileconfig/standalone/publish.go --- pkg/runfileconfig/run_file_config_parser.go | 4 +--- pkg/standalone/publish.go | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/runfileconfig/run_file_config_parser.go b/pkg/runfileconfig/run_file_config_parser.go index 207bfd2fa..7d536a8bb 100644 --- a/pkg/runfileconfig/run_file_config_parser.go +++ b/pkg/runfileconfig/run_file_config_parser.go @@ -212,9 +212,7 @@ func (a *RunFileConfig) resolvePathToAbsAndValidate(baseDir string, paths ...*st return err } absPath := utils.GetAbsPath(baseDir, *path) - if err != nil { - return err - } + *path = absPath if err = utils.ValidateFilePath(*path); err != nil { return err diff --git a/pkg/standalone/publish.go b/pkg/standalone/publish.go index 30ae646fe..024d2f1ce 100644 --- a/pkg/standalone/publish.go +++ b/pkg/standalone/publish.go @@ -69,7 +69,7 @@ func (s *Standalone) Publish(publishAppID, pubsubName, topic string, payload []b // Detect publishing with CloudEvents envelope. var cloudEvent map[string]interface{} - if json.Unmarshal(payload, &cloudEvent); err == nil { + if err := json.Unmarshal(payload, &cloudEvent); err == nil { _, hasID := cloudEvent["id"] _, hasSource := cloudEvent["source"] _, hasSpecVersion := cloudEvent["specversion"] @@ -78,6 +78,8 @@ func (s *Standalone) Publish(publishAppID, pubsubName, topic string, payload []b if hasID && hasSource && hasSpecVersion && hasType && hasData { contentType = "application/cloudevents+json" } + } else { + return err } r, err := httpc.Post(url, contentType, bytes.NewBuffer(payload))