Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128277 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by lists.php.net (Postfix) with ESMTPS id 6FFD41A00BC for ; Mon, 28 Jul 2025 17:53:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753725095; bh=UUPrQM/fVzgdCRYTWGYRm6ih7DL77QTeUzFRmUCDHK4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Yau7zzYiNstx9jckCW+nu82zgL43P3TTp+nGWHETkfDy/Odq66oB2WB2KOgFQhmZV H4fCM7/coaRvQ0pUtsSyQTsLSrctktjyJv6JACuPNBsGuMAsCgmwsMFY44av39vFw7 e/IM74BVHO/IP5X8kxBBoPTlpz2NvXr+2Y9xaPWtNHaZSw0h495Sujv9E7lT4hjQx8 MKKEllkfgryZZkPP2/+N7xAYwoxpIAu0nXlxQ/JA2DCwovcXrhQ5XdNKFAYjn+3iqI U6DXAmKIFUOgAOmmZ8P6+csWdDj18ewVbKi0dpPlmyWvoC90VR126M1BwJD9gc+EUt 30b+SEqxDa61g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 23E141807E4 for ; Mon, 28 Jul 2025 17:51:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 28 Jul 2025 17:51:30 +0000 (UTC) Received: by mail-pj1-f46.google.com with SMTP id 98e67ed59e1d1-31ece02ad92so1231625a91.2 for ; Mon, 28 Jul 2025 10:53:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753725193; x=1754329993; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fgf0WxqzmXsgRzpKr05HWFpGJMPJZGLz2uGdSKC2Mks=; b=cq1htSdxfC/QPl8b39U4EX289mQfslLUy/6SFrZmkTfVtFlt/MYNMSt7eTsjdkjuJt TD7dNdL31Q57aA65df6/KnBlM47q7vA8qE2VfTgJHJzKPtlzaWejZjsdySOr+4kFkl5b jJUZmEcs8Iz1ozjmyYfwhlJhpQ28RG3B+01qG0UwPdZzu9hs7uFe9gMa/ACwG26hx45D 9HPaF7TYPozOQrAy8r16EETvjUN1kI3bRnw6zer3AKohW2pWgkNeb+mfsIv/NJpxNqS+ MqIZrT3cZcyRdKcRfbidtE2FXvCOi/qo4TyE6dWtpHxntcvG1OF4HOCHbQgOBhJcgc7R leRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753725193; x=1754329993; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fgf0WxqzmXsgRzpKr05HWFpGJMPJZGLz2uGdSKC2Mks=; b=xRPlgC7vXex1Gk4BgoH0jbwB2VFLkitnZIZnigcH475DfbR9LQt+x37Hv4duolEZbQ /t4joo91daXr/lDCIze8LCHd89roU0MJKEKXfZA3BvVQwlwle4nBPbu7Z4k/TXhspRqn Lhg9WvwCWnp9pHlbXPwaOTet8wSFvZj9azshjxzWBtSIXhE6N/21zPnrliMBPQUPz58h mZLDPSA2Za4j/uSvWPOLtK1FxJZnAwy4hFW7N50lvWTwDDW1uQS6Hk1gsmm+6ts0+bGc IADITtRxeiFtT6U2lMGEwvLQv1u08My+IzD4XmYqAWJQUPmiKRJEjaPYtSiC1v11iyBx /AvQ== X-Gm-Message-State: AOJu0Yyi4khUmovD8dJe+jgWRXf2hC0KwcX8VC1zv4O8qtRixDxN0myM OBuQpWQ08TET2yqEakQ4fCSTRpFi5x2/IMCpf+3AHgXQYC3L4tR3H5AjrHI8p2+dwpkrblh0qwe 8YDIeykSy3K6uOQ2DkVkjub7aJl3SVdc= X-Gm-Gg: ASbGncvvCHFSW37Mg7DCDAVAL2qhQPTgV99ltxG/PWqKNL0wNGXfRgATclD/YFEhsUN zCh5x21XeCyC9scZxQVXsHGL5UpOTjak9aUGQM8p0E+tv72Jruei598/e6ZX0UU1dhtAJkln3kh DqtceNDmCT7MsY7nkASvsXB7h3tzucNohRm7syHvRatVmaZgJWxhnhHOVHC4EeoCgEn6z/FzBCM 6X5Qs5V X-Google-Smtp-Source: AGHT+IEi/KE2k/SWxKRLrisOfSi8H2a5Xc89P+5FOIjxej/p9t0mzPz1cubUxbTLmmA+6KyhOdxq7p8Mc6BwYlnaf8U= X-Received: by 2002:a17:90a:e707:b0:31f:1739:b541 with SMTP id 98e67ed59e1d1-31f1739b780mr2549214a91.29.1753725192780; Mon, 28 Jul 2025 10:53:12 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <73a35675dff31a1eaf76b67af567194e@bastelstu.be> In-Reply-To: Date: Mon, 28 Jul 2025 20:53:01 +0300 X-Gm-Features: Ac12FXyW0nq3tOZYjCypfCYJx-frzf-Dj7OsfYJkmYzUl974aGkp6dDwBUsFpw0 Message-ID: Subject: Re: [PHP-DEV] [DISCUSSION] User-land Throwable To: =?UTF-8?Q?Rokas_=C5=A0leinius?= Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000264269063b00f705" From: xepozzd@gmail.com (Dmitry Derepko) --000000000000264269063b00f705 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jul 28, 2025 at 3:44=E2=80=AFPM Rokas =C5=A0leinius wrote: > > On Mon, 28 Jul 2025 at 15:16, Lynn wrote: > >> >> >> On Mon, Jul 28, 2025 at 1:50=E2=80=AFPM Rokas =C5=A0leinius wrote: >> >>> >>> On Mon, 28 Jul 2025 at 13:56, Tim D=C3=BCsterhus wro= te: >>> >>>> Hi >>>> >>>> Am 2025-07-28 11:41, schrieb Dmitry Derepko: >>>> > A few years ago I found that a library printed error traces wrong. >>>> > After a little research I found that there was a mix of 3rd party >>>> > integration error + raised error around the current bridge >>>> > implementation >>>> > (http client). >>>> > >>>> > There were several PHP applications with microservices architecture >>>> > which I >>>> > had access to (docker + sources). >>>> > >>>> > So having the message and traces I'd like to have an error chain as >>>> it >>>> > can >>>> > be done chaining several errors through a new Exception(previous: $e= ). >>>> > But PHP does not allow you to manually implement Throwable. Instead >>>> you >>>> > should extend Exception. But after that you still cannot override th= e >>>> > getTrace() method because it's final. >>>> > >>>> > So my proposal is pretty simple: Remove both restrictions. >>>> >>>> I'm afraid I don't quite understand what actual goal you intend to >>>> solve >>>> with the proposal. The description of your use case is very abstract, >>>> can you provide a real-world example of a use-case you want to enable? >>>> >>>> Best regards >>>> Tim D=C3=BCsterhus >>>> >>> >>> | real-world example of a use-case you want to enable >>> >>> Say I am implementing a job runner, I do its error handling, and I want >>> to enrich the caught exception with additional helpful data for debuggi= ng. >>> In this process I create a custom exception MyJobHandlerException, but = the >>> trace of the new exception includes my handler code, which the end user >>> does not care about. I wish to overwrite the trace of the new >>> MyJobHandlerException instance with the trace from the originally caugh= t >>> exception, but I cannot. >>> >>> I was always sure that the reason behind all methods of \Exception bein= g >>> final is Larry-Garfield-blogpost length/depth so I never bothered to as= k >>> and made workarounds. >>> >> >> If I understand you correctly; You rethrow the exception, wrapping it in >> a custom exception class, and you'd like to have a final/composed >> stacktrace of all the exceptions? >> >> https://3v4l.org/m7HIQ#vnull >> > > Yeah you guys come up with nice workarounds, I too, use a custom method o= n > my exception class to get the "actually relevant" trace, but that's not > compatible with the world at large, and previous() or not, you cannot plu= g > in your own trace (which was processed for user convenience). > > Another example: what if I want to implement a userland job method > `failed()`, where "the job system" would create a synthetic exception - b= ut > I want it to have the trace up to the actual line in "userland" code (whe= re > `failed()` was invoked) - and I don't want my "system" calls in the trace= . > > Or another example: how Laravel handles ViewException - at one point the > error handler builds a "fixed" trace where the compiled Blade files are > replaced in the trace with the source `blade.php` files - as that is what > is actually relevant to the user. I'm cloudy on the details of how exact= ly > does it perform the switch to display the desired trace, but you can > imagine it would be much nicer to have this code within the concern of th= e > ViewException itself, but it can't be done now. > Thank you for the cases. I'm not alone here with crazy traces =F0=9F=98=80 Btw, I also have a "system" method which creates an exception and guess what? The first trace line is placed in that file. --=20 Best regards, Dmitrii Derepko. @xepozz --000000000000264269063b00f705 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Jul 28, 2025 at 3:44=E2=80=AFPM R= okas =C5=A0leinius <raveren@gmail.c= om> wrote:

On Mon, 28 Jul 2025 at 15:16, Lynn <kjarli@gmail.com> wrote:


On Mon, Jul 28, 2025 at 1:50=E2=80=AFPM Rokas =C5=A0leinius= <raveren@gmail.c= om> wrote:

On Mon, 28 Jul 2025 at 13:56, Tim D=C3=BCster= hus <tim@bastelstu= .be> wrote:
Hi

Am 2025-07-28 11:41, schrieb Dmitry Derepko:
> A few years ago I found that a library printed error traces wrong.
> After a little research I found that there was a mix of 3rd party
> integration error + raised error around the current bridge
> implementation
> (http client).
>
> There were several PHP applications with microservices architecture > which I
> had access to (docker + sources).
>
> So having the message and traces I'd like to have an error chain a= s it
> can
> be done chaining several errors through a new Exception(previous: $e).=
> But PHP does not allow you to manually implement Throwable. Instead yo= u
> should extend Exception. But after that you still cannot override the<= br> > getTrace() method because it's final.
>
> So my proposal is pretty simple: Remove both restrictions.

I'm afraid I don't quite understand what actual goal you intend to = solve
with the proposal. The description of your use case is very abstract,
can you provide a real-world example of a use-case you want to enable?

Best regards
Tim D=C3=BCsterhus

|=C2=A0real-world example of a use-case you want to ena= ble

Say I am implementing a job runner, I do its error handling, and I want to=20 enrich the caught exception with additional helpful data for debugging.=20 In this process I create a custom exception MyJobHandlerException, but=20 the trace of the new exception includes my handler code, which the end=20 user does not care about. I wish to overwrite the trace of the new=20 MyJobHandlerException instance with the trace from the originally caught exception, but I cannot.

I was always sure that the reason behind all methods of \Exception being=20 final is Larry-Garfield-blogpost length/depth so I never bothered to ask and made workarounds.

<= /div>
If I understand you correctly; You rethrow the exception, wrappin= g it in a custom exception class, and you'd like to have a final/compos= ed stacktrace of all the exceptions?


Yeah you guys come=C2=A0up with nice work= arounds, I too, use a custom method on my exception class to get the "= actually relevant" trace,=C2=A0but that's not compatible with the = world at large,=C2=A0and previous() or not, you cannot plug in your own tra= ce (which was processed for user convenience).

A= nother example: what if I want to implement a userland job method `failed()= `, where "the job system" would create a synthetic exception - bu= t I want it to have the trace up to the actual line in "userland"= code (where `failed()` was invoked) - and I don't want my "system= " calls in the trace.=C2=A0

Or another exam= ple: how Laravel handles ViewException - at one point the error handler bui= lds a "fixed" trace where the compiled Blade files are replaced i= n the trace with the source `blade.php` files - as that is what is actually= relevant to the user.=C2=A0 I'm cloudy on the details of how exactly does it perform the switch to = display the desired trace, but you can imagine it would be much nicer to ha= ve this code within the concern of the ViewException itself, but it can'= ;t be done now.

=

--
--000000000000264269063b00f705--