Skip to content

Commit

Permalink
removed redundent nil error checking in pkg/runfileconfig/run_file_co…
Browse files Browse the repository at this point in the history
…nfig_parser.go and added proper error handling while unmarshalling json in pkg/runfileconfig/standalone/publish.go
  • Loading branch information
Exar04 committed Sep 18, 2024
1 parent aa0436e commit 695abd3
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 1 addition & 3 deletions pkg/runfileconfig/run_file_config_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,7 @@ func (a *RunFileConfig) resolvePathToAbsAndValidate(baseDir string, paths ...*st
return err
}
absPath := utils.GetAbsPath(baseDir, *path)
if err != nil {
return err
}

Check failure on line 215 in pkg/runfileconfig/run_file_config_parser.go

View workflow job for this annotation

GitHub Actions / Build linux_amd64 binaries

File is not `gofmt`-ed with `-s` (gofmt)
*path = absPath
if err = utils.ValidateFilePath(*path); err != nil {
return err
Expand Down
4 changes: 3 additions & 1 deletion pkg/standalone/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 72 in pkg/standalone/publish.go

View workflow job for this annotation

GitHub Actions / Build linux_amd64 binaries

shadow: declaration of "err" shadows declaration at line 45 (govet)
_, hasID := cloudEvent["id"]
_, hasSource := cloudEvent["source"]
_, hasSpecVersion := cloudEvent["specversion"]
Expand All @@ -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))
Expand Down

0 comments on commit 695abd3

Please sign in to comment.