Cloud Code Error Handling
This release adds raising variants of Parse.call_function and Parse.trigger_job that surface cloud-code errors instead of silently returning nil, introduces Parse::Error::CloudCodeError, and hardens result extraction against unusual response bodies.
Changes
- NEW:
Parse.call_function!,Parse.call_function_with_session!,Parse.trigger_job!, andParse.trigger_job_with_session!raiseParse::Error::CloudCodeErrorwhen the cloud function or job returns an error response, instead of silently returning nil. The error carriesfunction_name,code,http_status, and the underlyingParse::Responsefor debugging. Use these variants when you want failures to propagate rather than be coerced to nil. - IMPROVED:
Parse.call_functionandParse.trigger_jobnow emit a[Parse:CloudCodeError]warning to stderr when the response indicates an error. Previously both methods coerced any cloud-code error response to a nil return value with no log line, making misconfigured calls (missing session token, failederror!()in cloud code) invisible to callers and tests. The nil return is preserved for backwards compatibility; the warning surfaces the failure. Matches the existing warn-then-raise pattern used by other HTTP error paths inParse::Client#request. - FIXED:
Parse.call_function,Parse.trigger_job, and their!variants no longer raiseTypeErroron unusual successful response bodies. Result extraction now guards against non-Hash response payloads (e.g., a bare string body) by returning the raw result rather than indexing into a non-Hash.
Code Examples
# Raise on error instead of silently returning nil
result = Parse.call_function!(:addUserToTeams, { userId: id }, session_token: token)
# Handle the raise with structured error info
begin
Parse.call_function!(:addUserToTeams, params, session_token: token)
rescue Parse::Error::CloudCodeError => e
Rails.logger.error "Cloud function #{e.function_name} failed: [#{e.code}] HTTP #{e.http_status}"
raise
end
# Non-bang form now warns on error (still returns nil)
Parse.call_function(:broken, {})
# stderr: [Parse:CloudCodeError] broken [141] Missing session token (HTTP 400)
# returns: nilCommit: 7ff4741
Author: Adrian Curtin
Date: April 2026