diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-08-19 11:58:39 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-08-19 11:58:39 +0200 |
| commit | f37216b1647d1960dac8fe4fefe43f343019ba30 (patch) | |
| tree | 2056f2e2755d88be921870ca983bdde61b36b36e | |
| parent | de8b2adbcc4a39c359f3dd30249ac4ee225d4b9c (diff) | |
Exports: Ensure valid JSON when encountering a marshal error
| -rw-r--r-- | exports/exports.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/exports/exports.go b/exports/exports.go index 7f842ec..e0e8464 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -34,8 +34,15 @@ func StateCallback(name string, old_state eduvpn.VPNStateID, new_state eduvpn.VP name_c := C.CString(name) oldState_c := C.int(old_state) newState_c := C.int(new_state) - data_json, _ := json.Marshal(data) - data_c := C.CString(string(data_json)) + data_json, jsonErr := json.Marshal(data) + var dataJsonString string + if jsonErr != nil { + // TODO: How to handle error further? Log? + dataJsonString = "{}" + } else { + dataJsonString = string(data_json) + } + data_c := C.CString(dataJsonString) C.call_callback(P_StateCallback, name_c, oldState_c, newState_c, data_c) C.free(unsafe.Pointer(name_c)) C.free(unsafe.Pointer(data_c)) |
