@@ -403,6 +403,7 @@ get_task(int *idx, char *relschema, char *relname)
403403 namestrcpy (& task -> relname , relname );
404404
405405 task -> msg [0 ] = '\0' ;
406+ task -> msg_detail [0 ] = '\0' ;
406407
407408 * idx = i ;
408409 return task ;
@@ -440,6 +441,7 @@ run_worker(BackgroundWorker *worker, WorkerTask *task)
440441 BgwHandleStatus status ;
441442 pid_t pid ;
442443 char * msg = NULL ;
444+ char * msg_detail = NULL ;
443445
444446 /*
445447 * Start the worker. Avoid leaking the task if the function ends due to
@@ -521,12 +523,20 @@ run_worker(BackgroundWorker *worker, WorkerTask *task)
521523done :
522524 if (strlen (task -> msg ) > 0 )
523525 msg = pstrdup (task -> msg );
526+ if (strlen (task -> msg_detail ) > 0 )
527+ msg_detail = pstrdup (task -> msg_detail );
524528
525529 release_task (task );
526530
527531 /* Report the worker's ERROR in the backend. */
528532 if (msg )
529- ereport (ERROR , (errmsg ("%s" , msg )));
533+ {
534+ if (msg_detail )
535+ ereport (ERROR , (errmsg ("%s" , msg ),
536+ errdetail ("%s" , msg_detail )));
537+ else
538+ ereport (ERROR , (errmsg ("%s" , msg )));
539+ }
530540
531541}
532542
@@ -714,12 +724,14 @@ rewrite_worker_main(Datum main_arg)
714724 AbortOutOfAnyTransaction ();
715725
716726 /*
717- * Currently we only copy the error message, more fields, more
718- * information can be added if needed. (Ideally we'd use the message
719- * queue like parallel workers do, but the related PG core functions
720- * have some parallel worker specific arguments.)
727+ * Currently we only copy ' message' and 'detail.More information can
728+ * be added if needed. (Ideally we'd use the message queue like
729+ * parallel workers do, but the related PG core functions have some
730+ * parallel worker specific arguments.)
721731 */
722732 strlcpy (task -> msg , edata -> message , MAX_ERR_MSG_LEN );
733+ if (edata -> detail && strlen (edata -> detail ) > 0 )
734+ strlcpy (task -> msg_detail , edata -> detail , MAX_ERR_MSG_LEN );
723735
724736 FreeErrorData (edata );
725737 }
0 commit comments