[PECL-CVS] [pecl-networking-gearman] fix-misleading-exception-message: address reviews

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

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

address reviews

Changed paths:
  M  php_gearman_worker.c


Diff:

diff --git a/php_gearman_worker.c b/php_gearman_worker.c
index d9287be..d90f961 100644
--- a/php_gearman_worker.c
+++ b/php_gearman_worker.c
@@ -557,22 +557,29 @@ static void *_php_worker_function_callback(gearman_job_st *job,
                 zend_string *exc_msg;
                 zval rv;
 
+                ZVAL_UNDEF(&rv);
                 *ret_ptr = GEARMAN_WORK_EXCEPTION;
 
                 /* 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. */
+                 * 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(
-                        zend_ce_exception, EG(exception), "message", sizeof("message") - 1, 1, &rv));
+                        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,
-                                        "Worker callback exception: %s", ZSTR_VAL(exc_msg));
+                                        "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)) {