#Structuring consecutive error handling as part of json parser

5 messages · Page 1 of 1 (latest)

mental hull
#

Hi everyone, I am trying to manually parse a json object..The problem is : with every function call to parse one field I receive a possible error as a return value.
Since I am parsing about 10 fields, I receive about 10 errors.
Is there a proper way to deal with this?

    jsonparser.ArrayEach(results, func(b []byte, dataType, jsonparser.ValueType, offset int, err error) {
        listName, err := jsonparser.GetString(b, "list_name")
        displayName, err := jsonparser.GetString(b, "display_name")
        listNameEncoded, err := jsonparser.GetString(b, "list_name_encoded")
        // other fields getting parsed
    })

ashen rover
#

if errors are fatal for the function, then if err != nil them

mental hull
ashen rover
#

but i would write lots of if err != nil