diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-21 11:37:32 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-21 11:37:32 +0200 |
| commit | 448c51d2142c186f0490b9d51c0d73beb3c76863 (patch) | |
| tree | 4553269be84b58072a11645221649bcccd85c73f /exports | |
| parent | 7dbc3bbe2ca65fb7ec200ab7aa713855b0bdc11d (diff) | |
Exports + Python: Do not panic on error for getting disco + servers
Diffstat (limited to 'exports')
| -rw-r--r-- | exports/disco.go | 20 | ||||
| -rw-r--r-- | exports/servers.go | 8 |
2 files changed, 12 insertions, 16 deletions
diff --git a/exports/disco.go b/exports/disco.go index e28fb01..73bc1ac 100644 --- a/exports/disco.go +++ b/exports/disco.go @@ -168,17 +168,15 @@ func FreeDiscoOrganizations(cOrganizations *C.discoveryOrganizations) { } //export GetDiscoServers -func GetDiscoServers(name *C.char) *C.discoveryServers { +func GetDiscoServers(name *C.char) (*C.discoveryServers, *C.char) { nameStr := C.GoString(name) state, stateErr := GetVPNState(nameStr) - // TODO if stateErr != nil { - panic(stateErr) + return nil, C.CString(ErrorToString(stateErr)) } servers, serversErr := state.GetDiscoServers() - // TODO if serversErr != nil { - panic(serversErr) + return nil, C.CString(ErrorToString(serversErr)) } returnedStruct := (*C.discoveryServers)( @@ -189,21 +187,19 @@ func GetDiscoServers(name *C.char) *C.discoveryServers { state, servers, ) - return returnedStruct + return returnedStruct, nil } //export GetDiscoOrganizations -func GetDiscoOrganizations(name *C.char) *C.discoveryOrganizations { +func GetDiscoOrganizations(name *C.char) (*C.discoveryOrganizations, *C.char) { nameStr := C.GoString(name) state, stateErr := GetVPNState(nameStr) - // TODO if stateErr != nil { - panic(stateErr) + return nil, C.CString(ErrorToString(stateErr)) } organizations, organizationsErr := state.GetDiscoOrganizations() - // TODO if organizationsErr != nil { - panic(organizationsErr) + return nil, C.CString(ErrorToString(organizationsErr)) } returnedStruct := (*C.discoveryOrganizations)( @@ -216,5 +212,5 @@ func GetDiscoOrganizations(name *C.char) *C.discoveryOrganizations { organizations, ) - return returnedStruct + return returnedStruct, nil } diff --git a/exports/servers.go b/exports/servers.go index e5c9301..a487176 100644 --- a/exports/servers.go +++ b/exports/servers.go @@ -293,14 +293,14 @@ func getSavedServersWithOptions(state *eduvpn.VPNState, servers *server.Servers) //export GetSavedServers // This function takes the name as input which is the name of the client // It gets the state by name and then returns the saved servers as a c struct belonging to it -func GetSavedServers(name *C.char) *C.servers { +func GetSavedServers(name *C.char) (*C.servers, *C.char) { nameStr := C.GoString(name) state, stateErr := GetVPNState(nameStr) if stateErr != nil { - // TODO: Remove this panic - panic(stateErr) + return nil, C.CString(ErrorToString(stateErr)) } - return getSavedServersWithOptions(state, &state.Servers) + servers := getSavedServersWithOptions(state, &state.Servers) + return servers, nil } // This function takes the state as input which is the main state |
