A Deluge function with no error handling is a function that fails silently. You’ll find out when a customer complains, not when the failure happens. Three patterns prevent this.
Pattern 1: Wrap Every API Call
Every zoho.crm.* and invokeurl call can fail. Wrap them and check the response shape:
response = zoho.crm.updateRecord("Deals", deal_id, update_map);
if(response.containsKey("status") && response.get("status") == "error")
{
info "Update failed for " + deal_id + ": " + response.get("message");
sendmail
[
from: zoho.adminuserid
to: "ops@example.com"
subject: "Deal update failed"
message: "ID " + deal_id + " - " + response.get("message")
]
return;
}
The info log is for the function execution log; the email is for the human who needs to know.
Pattern 2: Log a Correlation ID
When debugging, you need to trace a single execution end-to-end. Generate a correlation ID at function entry and include it in every log line:
correlation_id = zoho.currenttime.toString() + "_" + lead_id;
info "[" + correlation_id + "] starting lead enrichment";
// ... work ...
info "[" + correlation_id + "] completed in " + elapsed + "ms";
Search the function execution log for the correlation ID and you have the full trail.
Pattern 3: Fail Loudly for Critical Paths
For revenue-critical functions (payment processing, contract generation), don’t just log — break the user flow:
if(critical_operation_failed)
{
return {"status": "error", "message": "Payment validation failed - contact support"};
}
The user sees a real error and contacts you. A silent failure means lost revenue you’ll never trace.
Pattern 4: Defensive Default Values
Every map.get() can return null. Defend at the read site, not after:
amount = ifnull(rec.get("Amount"), 0);
stage = ifnull(rec.get("Stage"), "Unknown");
A null comparison silently passes through Deluge logic and produces wrong outputs. Defaulting at read time is cheap insurance.
Pattern 5: Rate-Limit Aware Retries
API calls can fail with rate-limit errors. Don’t retry immediately — back off:
attempts = 0;
while(attempts < 3)
{
response = zoho.crm.getRecordById("Deals", id);
if(!response.containsKey("status") || response.get("status") != "error") break;
attempts = attempts + 1;
sleep(attempts * 2);
}
Three retries with linear backoff handles transient failures without infinite loops.
Surface Failures to a Dashboard
Don’t let errors disappear into the email inbox. Create a custom module “Function_Errors” with fields for function name, timestamp, correlation ID, and message. Write to it from your error path. A dashboard over this module gives you operational visibility.
What to Do This Week
- Pick your most critical Deluge function and add response checks to every API call.
- Add a correlation ID pattern to your most-debugged function.
- Create the Function_Errors module.
- Wire one nightly report aggregating errors by function name.