Skip to content

Commit a124e18

Browse files
Standardize error handling across WASM wrapper functions
- Fix wasm_get_protobuf_len to return -1 for errors instead of 0 - Fix wasm_parse_query_detailed to return struct with has_error flag instead of NULL - Ensures consistent error handling patterns: * String functions: return error message strings * Integer functions: return -1 for errors * Struct functions: set has_error flag and return struct - All 32 tests continue to pass after error handling standardization Co-Authored-By: Dan Lynch <[email protected]>
1 parent 0585f66 commit a124e18

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/wasm_wrapper.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ char* wasm_parse_query_protobuf(const char* input, int* out_len) {
159159
EMSCRIPTEN_KEEPALIVE
160160
int wasm_get_protobuf_len(const char* input) {
161161
if (!validate_input(input)) {
162-
return 0;
162+
return -1;
163163
}
164164

165165
PgQueryProtobufParseResult result = pg_query_parse_protobuf(input);
166166

167167
if (result.error) {
168168
pg_query_free_protobuf_parse_result(result);
169-
return 0;
169+
return -1;
170170
}
171171

172172
int len = (int)result.parse_tree.len;
@@ -216,16 +216,18 @@ typedef struct {
216216

217217
EMSCRIPTEN_KEEPALIVE
218218
WasmDetailedResult* wasm_parse_query_detailed(const char* input) {
219-
if (!validate_input(input)) {
220-
return NULL;
221-
}
222-
223219
WasmDetailedResult* result = safe_malloc(sizeof(WasmDetailedResult));
224220
if (!result) {
225221
return NULL;
226222
}
227223
memset(result, 0, sizeof(WasmDetailedResult));
228224

225+
if (!validate_input(input)) {
226+
result->has_error = 1;
227+
result->message = safe_strdup("Invalid input: query cannot be null or empty");
228+
return result;
229+
}
230+
229231
PgQueryParseResult parse_result = pg_query_parse(input);
230232

231233
if (parse_result.error) {

0 commit comments

Comments
 (0)