[PECL-CVS] [pecl-networking-gearman] master: Merge pull request #55 from php/fix-misleading-exception-message

[email protected] (Rasmus Lerdorf via GitHub) Sat, 4 Apr 2026 15:46:14 +0000
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Rasmus Lerdorf (rlerdorf)
Committer: GitHub (web-flow)
Pusher: rlerdorf
Date: 2026-04-04T16:46:12+01:00

Commit: https://github.com/php/pecl-networking-gearman/commit/12a579a4806ae70fab60f33f5fa22407b5a1339d
Raw diff: https://github.com/php/pecl-networking-gearman/commit/12a579a4806ae70fab60f33f5fa22407b5a1339d.diff

Merge pull request #55 from php/fix-misleading-exception-message

fixes #21

Changed paths:
  M  php_gearman_worker.c


Diff:

diff --git a/php_gearman_worker.c b/php_gearman_worker.c
index 1842d80..d90f961 100644
--- a/php_gearman_worker.c
+++ b/php_gearman_worker.c
@@ -554,14 +554,32 @@ static void *_php_worker_function_callback(gearman_job_st *job,
 #endif
 
         if (EG(exception)) {
+                zend_string *exc_msg;
+                zval rv;
+
+                ZVAL_UNDEF(&rv);
                 *ret_ptr = GEARMAN_WORK_EXCEPTION;
 
-                jobj->ret = gearman_job_send_exception(jobj->job, "Unable to add worker function", sizeof("Unable to add worker function") - 1);
+                /* Send the actual exception message to gearmand rather than
+                 * the misleading "Unable to add worker function" string that
+                 * was hardcoded here previously. Use the throwable's own
+                 * class as scope so the protected message property is
+                 * accessible for all Throwable types (Error, TypeError,
+                 * etc.), not just Exception. See issue #21. */
+                exc_msg = zval_get_string(zend_read_property(
+                        EG(exception)->ce, EG(exception), "message", sizeof("message") - 1, 1, &rv));
+
+                jobj->ret = gearman_job_send_exception(jobj->job, ZSTR_VAL(exc_msg), ZSTR_LEN(exc_msg));
 
                 if (jobj->ret != GEARMAN_SUCCESS && jobj->ret != GEARMAN_IO_WAIT) {
-                        php_error_docref(NULL, E_WARNING,  "Unable to add worker function: %s",
-                                        gearman_job_error(jobj->job));
+                        php_error_docref(NULL, E_WARNING,
+                                        "Failed to send worker callback exception to gearmand: "
+                                        "exception=\"%s\", gearman_error=\"%s\", return_code=%d",
+                                        ZSTR_VAL(exc_msg), gearman_job_error(jobj->job), (int)jobj->ret);
                 }
+
+                zend_string_release(exc_msg);
+                zval_ptr_dtor(&rv);
         }
 
         if (Z_ISUNDEF(retval)) {