Error callback instead of terminating error in JSON
mariotoffia opened this issue · 4 comments
Hi and thanks for this greate piece of software! :)
We're using it to do sensor mapping:
- i.e fetch sensor data as a single HTTP request
- map those sensors into our own sensor model.
This works great, except when for some reason we do not get one or more needed sensor data points. In this case it will error out.
Could it be possible to do a callback to an error function instead, and if that error function do return an error, it will fail, otherwise it will remove the json key or set the value to nil (or a value returned by the error function?
func OnError(c context.Context, key, expr string, e error) (val interface{], err error) {}
Example mapping document that we use (partial)
{ "tz": TZ,
"sensors": {
"IDT_O3": float64(datapoint["1!6WHH6DKH3CCVW-"].Value),
"IDT_O5": float64(datapoint["1!6WHH6DKHADPZ1N"].Value),
"AEUPS": float64(datapoint["1!6WHH6DKHICVDSS"].Value * 1000) }
}
The error function may act as a OnErrorResumeNext
or a circuit-breaker
(the latter is how it currently works).
What do you think about this? Is is hard to implement in your library, would it fit?
To maybe do other than current error handling when this or this returns an error?
p.Camouflage("object", ',', '}')
key, err := p.ParseExpression(c)
if err != nil {
return nil, err
}
Cheers,
Mario :)
@generikvault does this make sense?
Hi Mario,
what you probably wanna do is to use a custom JSON Object interpreter. You can do this with myLang := gval.Full(PrefixExtension('{', myParseJSONObjectFunction))
in your own lib.
Implement the myParseJSONObjectFunction
based on the original function with your error handling (line 291) directly in your project.
Cheers,
GeneriK :-)
Thanks for your guidande! :)
You're welcome :-)