/** * Send failure notification of general UDF execution, but check for special * LDT errors and return specific Wire Protocol error codes for these cases: * (1) Record not found (2) * (2) LDT Collection item not found (125) * * All other errors get the generic 100 (UDF FAIL) code. */ static inline int send_udf_failure(udf_call *call, const as_string *s) { char *val = as_string_tostring(s); size_t vlen = as_string_len((as_string *)s); // TODO - make as_string_len() take const long error_code = ldt_get_error_code(val, vlen); if (error_code) { if (error_code == AS_PROTO_RESULT_FAIL_NOTFOUND || error_code == AS_PROTO_RESULT_FAIL_COLLECTION_ITEM_NOT_FOUND) { call->tr->result_code = error_code; // Send an "empty" response, with no failure bin. as_transaction * tr = call->tr; single_transaction_response(tr, tr->rsv.ns, NULL/*ops*/, NULL /*bin*/, 0 /*nbins*/, 0, 0, NULL, NULL); return 0; } } cf_debug(AS_UDF, "Non-special LDT or General UDF Error(%s)", (char *) val); call->tr->result_code = AS_PROTO_RESULT_FAIL_UDF_EXECUTION; return send_failure(call, as_string_toval(s)); }
/** * Send failure notification of general UDF execution, but check for special * LDT errors and return specific Wire Protocol error codes for these cases: * (1) Record not found (2) * (2) LDT Collection item not found (125) * * All other errors get the generic 100 (UDF FAIL) code. */ static inline int process_udf_failure(udf_call *call, const as_string *s, cf_dyn_buf *db) { char *val = as_string_tostring(s); size_t vlen = as_string_len((as_string *)s); // TODO - make as_string_len() take const long error_code = ldt_get_error_code(val, vlen); if (error_code) { if (error_code == AS_PROTO_RESULT_FAIL_NOTFOUND || error_code == AS_PROTO_RESULT_FAIL_COLLECTION_ITEM_NOT_FOUND) { call->tr->result_code = (uint8_t)error_code; // Send an "empty" response, with no failure bin. as_transaction * tr = call->tr; if (db) { size_t msg_sz = 0; uint8_t *msgp = (uint8_t *)as_msg_make_response_msg( tr->result_code, 0, 0, NULL, NULL, 0, tr->rsv.ns, NULL, &msg_sz, as_transaction_trid(tr), NULL); if (! msgp) { cf_warning_digest(AS_RW, &tr->keyd, "{%s} LDT UDF failed to make response msg ", tr->rsv.ns->name); return -1; } // Stash the message, to be sent later. db->buf = msgp; db->is_stack = false; db->alloc_sz = msg_sz; db->used_sz = msg_sz; } else { single_transaction_response(tr, tr->rsv.ns, NULL/*ops*/, NULL /*bin*/, 0 /*nbins*/, 0, 0, NULL, NULL); } return 0; } } cf_debug(AS_UDF, "Non-special LDT or General UDF Error(%s)", (char *) val); call->tr->result_code = AS_PROTO_RESULT_FAIL_UDF_EXECUTION; return process_failure(call, as_string_toval(s), db); }