@@ -85,18 +85,30 @@ public function renderReportsUsing(Closure $renderReportCallable): static
8585 }
8686
8787 /**
88+ * @param Throwable|ReportFactory $throwable A throwable to build a report
89+ * for, or an already built report
90+ * (from the uncaught handler) to
91+ * render and send. When a report is
92+ * passed it is rendered first, then
93+ * the ignore and filter gating runs.
8894 * @param Closure(ReportFactory $report):void|null $callback
89- * @param ReportFactory|null $report An already built report to send instead
90- * of building a fresh one. Lets the caller
91- * build (and render) the report first while
92- * the ignore and filter gating still runs.
9395 */
9496 public function report (
95- Throwable $ throwable ,
97+ Throwable | ReportFactory $ throwable ,
9698 ?Closure $ callback = null ,
97- ?bool $ handled = null ,
98- ?ReportFactory $ report = null
99+ ?bool $ handled = null
99100 ): ?ReportFactory {
101+ $ report = null ;
102+
103+ if ($ throwable instanceof ReportFactory) {
104+ $ report = $ throwable ;
105+ $ throwable = $ report ->throwable ;
106+
107+ if ($ this ->renderReportCallable !== null ) {
108+ ($ this ->renderReportCallable )($ report );
109+ }
110+ }
111+
100112 if (! $ this ->shouldReport ($ throwable )) {
101113 $ this ->tracer ->gracefullyEndSpans ();
102114
@@ -217,7 +229,12 @@ protected function shouldReport(Throwable $throwable): bool
217229
218230 public function handleException (Throwable $ throwable ): void
219231 {
220- $ this ->renderAndReport ($ throwable );
232+ // When a renderer is registered, build the report first so it can be
233+ // rendered even for exceptions that are ignored or filtered from being
234+ // sent. report() renders the passed report, then applies the gating.
235+ $ this ->report (
236+ $ this ->renderReportCallable !== null ? $ this ->createReport ($ throwable ) : $ throwable
237+ );
221238
222239 if ($ this ->previousExceptionHandler && is_callable ($ this ->previousExceptionHandler )) {
223240 call_user_func ($ this ->previousExceptionHandler , $ throwable );
@@ -228,7 +245,9 @@ public function handleError(mixed $code, string $message, string $file = '', int
228245 {
229246 $ exception = new ErrorException ($ message , 0 , $ code , $ file , $ line );
230247
231- $ this ->renderAndReport ($ exception );
248+ $ this ->report (
249+ $ this ->renderReportCallable !== null ? $ this ->createReport ($ exception ) : $ exception
250+ );
232251
233252 if ($ this ->previousErrorHandler ) {
234253 call_user_func (
@@ -241,24 +260,6 @@ public function handleError(mixed $code, string $message, string $file = '', int
241260 }
242261 }
243262
244- protected function renderAndReport (Throwable $ throwable ): void
245- {
246- if ($ this ->renderReportCallable === null ) {
247- $ this ->report ($ throwable );
248-
249- return ;
250- }
251-
252- // Build the report once so it can be rendered locally even when the
253- // exception is ignored or filtered from being sent to Flare. report()
254- // still runs the ignore and filter gating before sending.
255- $ report = $ this ->createReport ($ throwable );
256-
257- ($ this ->renderReportCallable )($ report );
258-
259- $ this ->report ($ throwable , report: $ report );
260- }
261-
262263 protected function addReportToTrace (Throwable $ throwable , ?bool $ handled , ReportFactory $ report ): void
263264 {
264265 if ($ this ->addReportsToTraces === false || $ this ->tracer ->isSampling () === false ) {
0 commit comments