From 25730575ee18a365276826a25bdf080c3f1b76ad Mon Sep 17 00:00:00 2001 From: DanB Date: Tue, 29 May 2018 19:16:03 +0200 Subject: [PATCH] InterfaceAsString using ToJSON to convert unknown fields --- engine/cdr.go | 2 ++ utils/reflect.go | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/engine/cdr.go b/engine/cdr.go index 44eec854c..ba0e5832b 100644 --- a/engine/cdr.go +++ b/engine/cdr.go @@ -558,6 +558,8 @@ func (cdr *CDR) AsExportRecord(exportFields []*config.CfgCdrField, httpSkipTlsCh if err == utils.ErrFilterNotPassingNoCaps { continue // not exporting this field value } + utils.Logger.Warning(fmt.Sprintf(" error: %s exporting field: %s, CDR: %s\n", + err.Error(), utils.ToJSON(cfgFld), utils.ToJSON(cdr))) return nil, err } else { expRecord = append(expRecord, fmtOut) diff --git a/utils/reflect.go b/utils/reflect.go index 4ee7e819f..d1b3587d9 100644 --- a/utils/reflect.go +++ b/utils/reflect.go @@ -50,8 +50,12 @@ func CastFieldIfToString(fld interface{}) (string, bool) { case time.Duration: strVal = fld.(time.Duration).String() converted = true + case string: + strVal = fld.(string) + converted = true default: // Maybe we are lucky and the value converts to string - strVal, converted = fld.(string) + strVal = ToJSON(fld) + converted = true } return strVal, converted } @@ -245,12 +249,10 @@ func IfaceAsString(fld interface{}) (out string, err error) { return fld.(time.Duration).String(), nil case time.Time: return fld.(time.Time).Format(time.RFC3339), nil + case string: + return fld.(string), nil default: // Maybe we are lucky and the value converts to string - if out, canCast := fld.(string); !canCast { - return "", ErrNotConvertibleNoCaps - } else { - return out, nil - } + return ToJSON(fld), nil } }