[PECL-CVS] [pecl-networking-gearman] fix-misleading-exception-message: fixes #21

[email protected] (Rasmus Lerdorf) Sat, 4 Apr 2026 15:09:31 +0000
Newsgroups php.pecl.cvs
Message-ID <[email protected]>
Author: Rasmus Lerdorf (rlerdorf)
Date: 2026-04-04T11:09:18-04:00

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

fixes #21

Changed paths:
  M  php_gearman_worker.c


Diff:

diff --git a/php_gearman_worker.c b/php_gearman_worker.c
index 1842d80..d9287be 100644
--- a/php_gearman_worker.c
+++ b/php_gearman_worker.c
@@ -554,14 +554,25 @@ static void *_php_worker_function_callback(gearman_job_st *job,
 #endif
 
         if (EG(exception)) {
+                zend_string *exc_msg;
+                zval 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. See issue #21. */
+                exc_msg = zval_get_string(zend_read_property(
+                        zend_ce_exception, 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,
+                                        "Worker callback exception: %s", ZSTR_VAL(exc_msg));
                 }
+
+                zend_string_release(exc_msg);
         }
 
         if (Z_ISUNDEF(retval)) {