Skip to content

v3.3.4 - Cloud Code Error Handling

Latest

Choose a tag to compare

@AdrianCurtin AdrianCurtin released this 21 Apr 17:11
· 20 commits to master since this release

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!, and Parse.trigger_job_with_session! raise Parse::Error::CloudCodeError when the cloud function or job returns an error response, instead of silently returning nil. The error carries function_name, code, http_status, and the underlying Parse::Response for debugging. Use these variants when you want failures to propagate rather than be coerced to nil.
  • IMPROVED: Parse.call_function and Parse.trigger_job now 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, failed error!() 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 in Parse::Client#request.
  • FIXED: Parse.call_function, Parse.trigger_job, and their ! variants no longer raise TypeError on 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: nil

Commit: 7ff4741
Author: Adrian Curtin
Date: April 2026