diff --git a/generate/generate_bindings.go b/generate/generate_bindings.go index 1723074..970c1db 100644 --- a/generate/generate_bindings.go +++ b/generate/generate_bindings.go @@ -96,7 +96,9 @@ func main() { case "profile": generatedBindings = generateProfileFunction(generatedBindings, fName, args) case "(json)profile": - generatedBindings = generateJsonProfileFunction(generatedBindings, fName, args) + generatedBindings = generateJsonProfileFunction(generatedBindings, fName, args, false) + case "(json-err)profile": + generatedBindings = generateJsonProfileFunction(generatedBindings, fName, args, true) case "@profile-experiment": experiment := args[0] generatedBindings = generateExperimentalProfileFunction(generatedBindings, experiment, fName, args[1:]) @@ -382,7 +384,7 @@ func {{FNAME}}({{GO_ARGS_SPEC}}) { return bindings } -func generateJsonProfileFunction(bindings string, name string, argsTypes []string) string { +func generateJsonProfileFunction(bindings string, name string, argsTypes []string, handleErr bool) string { appPrototype := ` //export c_{{FNAME}} func c_{{FNAME}}({{C_ARGS}}) *C.char { @@ -392,14 +394,26 @@ func c_{{FNAME}}({{C_ARGS}}) *C.char { func {{FNAME}}({{GO_ARGS_SPEC}}) string { cwtchProfile := application.GetPeer(profile) if cwtchProfile != nil { - return cwtchProfile.{{LIBNAME}}({{GO_ARG}}) + {{HANDLE_FUNC}} } return "" } ` + noErrorPrototype := `return cwtchProfile.{{LIBNAME}}({{GO_ARG}})` + withErrorPrototype := `res,err := cwtchProfile.{{LIBNAME}}({{GO_ARG}}) + if err != nil { + log.Errorf("could not {{FNAME}} %v", err) + } + return res` + functionPrototype := noErrorPrototype + if handleErr { + functionPrototype = withErrorPrototype + } + cArgs, c2GoArgs, goSpec, gUse := mapArgs(argsTypes) + appPrototype = strings.ReplaceAll(appPrototype, "{{HANDLE_FUNC}}", functionPrototype) appPrototype = strings.ReplaceAll(appPrototype, "{{FNAME}}", strings.TrimPrefix(name, "Enhanced")) appPrototype = strings.ReplaceAll(appPrototype, "{{LIBNAME}}", name) // We need to prepend a set of profile handle arguments... diff --git a/quality.sh b/quality.sh index 7e48c66..48b1c0f 100755 --- a/quality.sh +++ b/quality.sh @@ -20,6 +20,7 @@ nilaway -include-pkgs="git.openprivacy.ca/cwtch.im/cwtch-autobindings,cwtch.im/c echo "Time to format" gofmt -l -s -w ./utils/* +gofmt -l -s -w ./generate/* # ineffassign (https://github.com/gordonklaus/ineffassign) # echo "Checking for ineffectual assignment of errors (unchecked errors...)" diff --git a/spec b/spec index 5c2a54b..538a12b 100644 --- a/spec +++ b/spec @@ -22,6 +22,8 @@ profile UnblockConversation conversation profile DeleteConversation conversation profile PeerWithOnion string:handle profile DisconnectFromPeer string:handle +(json-err)profile EnhancedGetConversationAccessControlList conversation +profile EnhancedUpdateConversationAccessControlList conversation string:json # Search (json)profile SearchConversations string:pattern