From fff50da2b40e9a81bd880904ebaa027d7c26690f Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Wed, 7 Jan 2026 18:49:14 -0500 Subject: [PATCH] refactor(build): add c-shared buildmode to wasm plugin compilation --- Makefile | 2 +- main.go | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 6836929..609b830 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ deps: build: @echo "Building WASM plugin..." - @GOOS=wasip1 GOARCH=wasm go build -o $(BUILD_DIR)/$(BINARY) . + @GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o $(BUILD_DIR)/$(BINARY) . @echo "Built $(BUILD_DIR)/$(BINARY)" sdk: diff --git a/main.go b/main.go index 220fd6b..c222bd8 100644 --- a/main.go +++ b/main.go @@ -205,25 +205,29 @@ func exec() int32 { pdk.Log(pdk.LogInfo, "exec: executing action") if !enclave.initialized { - pdk.SetError(errors.New("exec: database not initialized, call generate or load first")) - return 1 + output := ExecOutput{Success: false, Error: "database not initialized, call generate or load first"} + pdk.OutputJSON(output) + return 0 } var input ExecInput if err := pdk.InputJSON(&input); err != nil { - pdk.SetError(fmt.Errorf("exec: failed to parse input: %w", err)) - return 1 + output := ExecOutput{Success: false, Error: fmt.Sprintf("failed to parse input: %s", err)} + pdk.OutputJSON(output) + return 0 } if input.Filter == "" { - pdk.SetError(errors.New("exec: filter is required")) - return 1 + output := ExecOutput{Success: false, Error: "filter is required"} + pdk.OutputJSON(output) + return 0 } params, err := parseFilter(input.Filter) if err != nil { - pdk.SetError(fmt.Errorf("exec: invalid filter: %w", err)) - return 1 + output := ExecOutput{Success: false, Error: fmt.Sprintf("invalid filter: %s", err)} + pdk.OutputJSON(output) + return 0 } if input.Token != "" { @@ -252,11 +256,7 @@ func exec() int32 { Result: result, } - if err := pdk.OutputJSON(output); err != nil { - pdk.SetError(fmt.Errorf("exec: failed to output result: %w", err)) - return 1 - } - + pdk.OutputJSON(output) pdk.Log(pdk.LogInfo, fmt.Sprintf("exec: completed %s on %s", params.Action, params.Resource)) return 0 } @@ -266,7 +266,7 @@ func query() int32 { pdk.Log(pdk.LogInfo, "query: resolving DID document") if !enclave.initialized { - pdk.SetError(errors.New("query: database not initialized, call generate or load first")) + pdk.SetError(errors.New("database not initialized, call generate or load first")) return 1 }