Skip to content

Commit

Permalink
fix: assume valid json in events output
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Aug 29, 2024
1 parent b433c2f commit 42dec3c
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions features/dapp_develop/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,13 @@ func getEventsFromCliTool(ledgerFrom uint32, deployedContractId string, size uin

status, stdOutLines, err := e2e.RunCommand(envCmd, e2eConfig)
var jsonEvents []map[string]interface{}
var stdOutLinesTrimmed []string

if status != 0 || err != nil {
return jsonEvents, fmt.Errorf("soroban cli get events had error %v, %v", status, err)
}

// put commas between any json event objects if more than one found
stdOutEventsValidJson := strings.ReplaceAll(strings.Join(stdOutLinesTrimmed, "\n"), `\n}\n{\n`, `\n}\n,\n{\n`)
// wrap the json objects in json array brackets
stdOutEventsValidJson = "[" + stdOutEventsValidJson + "]"

// join into one string
stdOutEventsValidJson := strings.Join(stdOutLines, "\n")
err = json.Unmarshal([]byte(stdOutEventsValidJson), &jsonEvents)
if err != nil {
return jsonEvents, fmt.Errorf("soroban cli get events console output %v was not parseable as event json, %e", strings.Join(stdOutLines, "\n"), err)
Expand Down

0 comments on commit 42dec3c

Please sign in to comment.