From 89fd0c7ab60d7bffaf4aca63a0e81290c682e491 Mon Sep 17 00:00:00 2001 From: Dhadve Yash <109629956+Exar04@users.noreply.github.com> Date: Thu, 19 Sep 2024 06:10:51 +0000 Subject: [PATCH 1/2] 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 Signed-off-by: yash dhadve yashdhadwe@gmail.com --- pkg/runfileconfig/run_file_config_parser.go | 4 +--- pkg/standalone/publish.go | 2 +- 2 files changed, 2 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..17ba8a3b0 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"] From ddcb306a58e11e4dbb85b97d6ce28a76088c0dc7 Mon Sep 17 00:00:00 2001 From: Dhadve Yash <109629956+Exar04@users.noreply.github.com> Date: Wed, 2 Oct 2024 06:06:07 +0000 Subject: [PATCH 2/2] changes --- pkg/runfileconfig/run_file_config_parser.go | 1 - pkg/standalone/publish.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/runfileconfig/run_file_config_parser.go b/pkg/runfileconfig/run_file_config_parser.go index 7d536a8bb..59533c92a 100644 --- a/pkg/runfileconfig/run_file_config_parser.go +++ b/pkg/runfileconfig/run_file_config_parser.go @@ -212,7 +212,6 @@ func (a *RunFileConfig) resolvePathToAbsAndValidate(baseDir string, paths ...*st return err } absPath := utils.GetAbsPath(baseDir, *path) - *path = absPath if err = utils.ValidateFilePath(*path); err != nil { return err diff --git a/pkg/standalone/publish.go b/pkg/standalone/publish.go index 17ba8a3b0..18d24ef51 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 err := json.Unmarshal(payload, &cloudEvent); err == nil { + if err = json.Unmarshal(payload, &cloudEvent); err == nil { _, hasID := cloudEvent["id"] _, hasSource := cloudEvent["source"] _, hasSpecVersion := cloudEvent["specversion"]