Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:128257 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 757C01A00BC for ; Mon, 28 Jul 2025 12:42:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1753706467; bh=X//TvqTEPdPOMljydgsiDrTGVUn4D0SGY5RQX8qzwEA=; h=References:In-Reply-To:From:Date:Subject:Cc:From; b=FPUfeECwEeWOPK136KaVLKLCaeiFzhXSMFx6h119H/U/7trKar6h4UuflKqyHSQo6 UZp/tfETt5uRPkASJHaoVSZS6q6+jtvIP7Judjab6c1BlkVLXWPVO9vU6ihvCYw0hc NJdXvZ1JsQoHPqGyr3AYbDasLRTlT8tiQgE5eYhyBjt8T3zzGhFy5GIxELTc1nhJUz 7ImZ/LDcj040Qkjc4cqCtEP5slVuGbyDS+jWo/nGCdVLBwlb9n5sOK9nMaS/9r0Vo6 9k5kMVgp23QPnNXHVSmTSg1NrW/f/Z8bt6P7jpxVBuN5LpBTC9gewCIz2OGg3gNC2E qhfq1q5cQ32TA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3D7C41804E1 for ; Mon, 28 Jul 2025 12:41:07 +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.8 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,MALFORMED_FREEMAIL,MISSING_HEADERS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 12:41:07 +0000 (UTC) Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4561ca74829so46474675e9.0 for ; Mon, 28 Jul 2025 05:42:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1753706568; x=1754311368; darn=lists.php.net; h=cc:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=NFc4BrCFKFBU5+ocv9hY9tz/Jdsbh1t2TzCKO5MTqC0=; b=mXb2K6om8RLuHI0Olnga5tVvhY8sw7gfOYzm5yWSOTQgfyJ6dyMYQl980TfZH61fu5 /ymlQaYh7e5/H3vnKJyjtFQ70MQrd6AEu2uDd5d5XTk7EEl52mKnRnEiX3jzIfnRkEhW SU0AkNMK9PQP+AZV4d1UFr2ObjNAJwjRvpysrIea1hpZaEaExsvzIX39IWW0vOj0iaZX PLykigIjMYOvbnLGActZD8oLZnODvNZ/kQVARh0cnndXa5+1jhV4/CE4TgsCQAqVkcW9 vGCkLPi0eBH+JWeQb7YqPWuc6iaDS5qB6gxxuGI+BvEv5KPTtkSy17J3N2c9cUIeP2hG R9FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1753706568; x=1754311368; h=cc: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=NFc4BrCFKFBU5+ocv9hY9tz/Jdsbh1t2TzCKO5MTqC0=; b=YPxIx4p1cqNFYuvjkoN/iaX/BbbDYm4U4btljlQgSsWw240zcCE8rsJYPzLKAcoVW0 HRRMexeg57mM+9exsiMw5ZtW1PE8DzoxJQZ61k8moL1vZ20/4t4yx3euCzKuqiUTYt5I RxwuqHCxB0XpeVgtgAaK5EiSXjPMgyRm2wBh2B9rFWZRp4onoVw6TnMsiXGek5iZSyHT 96GJB07uQWdSEWw1F/RK/wHEEfpZnjd1bhj18XzYc8mAmgyfCRDE09VpDm6kJz/GLCtU HBQevwXZ7U4R2b4mZQplJMEL68b54SIgHm+yIgmQAxyCPor72KmMe9ZSwpSdMTZpRhKb 3GuA== X-Gm-Message-State: AOJu0YzIxLyrYXtyKqcC6DBjWBk1jUeWT6vVrBsRLnbu7Q4FV1HfmfSj qwYV54DW8yvO2RLLeyQtIea+VOi1JKnJvFdpas2ctnZCRtj4j09GE2GXoQexsGloKxZy8Ed9TuU jPfzeuC2wN9UG6fuOi2ZXTvTk/jBj75YINpgI X-Gm-Gg: ASbGncvPUmYfjiArxmGXNUyud8mb5sMS63vuhKTft35P+VRTfSDz0QcCn5U5MUH+tgr SLXTCByYKd+w6OJL7f1A+BJuPSU2l9wsseltDhT87Wr3px7Yu7VdKNuFPwaRMHp+YRkUzRa0Q4i NBAd2JfYioT3K72xoV1ipHeJxISWh9QH2angJdeCssyhH+HTnXgjxtTyw6zYN7S5ydcREdpDX0p 4fZLQ== X-Google-Smtp-Source: AGHT+IHQjRCsJ1zfaxOzDmGXF1P96Iqa8mSI76NBQzGKUQJtn+z3hQgLopYRm4DlL843i3Ms1VBWxR7Mj2iH4oc8zCs= X-Received: by 2002:a05:6000:4027:b0:3b7:899c:e887 with SMTP id ffacd0b85a97d-3b7899cec65mr1684300f8f.24.1753706568418; Mon, 28 Jul 2025 05:42:48 -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 15:42:32 +0300 X-Gm-Features: Ac12FXwjKoTEaUp5ol5dzZIVUj4prEvHmwk5jO9mABRoAPDgwtqHyMEKdtidzqE Message-ID: Subject: Re: [PHP-DEV] [DISCUSSION] User-land Throwable Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000000d09d0063afca1ff" From: raveren@gmail.com (=?UTF-8?Q?Rokas_=C5=A0leinius?=) --0000000000000d09d0063afca1ff Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 wrot= e: >> >>> 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 i= t >>> > can >>> > be done chaining several errors through a new Exception(previous: $e)= . >>> > But PHP does not allow you to manually implement Throwable. Instead y= ou >>> > should extend Exception. But after that you still cannot override the >>> > 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 solv= e >>> 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 debuggin= g. >> In this process I create a custom exception MyJobHandlerException, but t= he >> 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 caught >> exception, but I cannot. >> >> I was always sure that the reason behind all methods of \Exception being >> final is Larry-Garfield-blogpost length/depth so I never bothered to ask >> 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 stacktrac= e > of all the exceptions? > > https://3v4l.org/m7HIQ#vnull > Yeah you guys come up with nice workarounds, I too, use a custom method on 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 plug 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 - but 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. 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 exactly 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 the ViewException itself, but it can't be done now. --0000000000000d09d0063afca1ff Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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.com> wrote:

On Mon, 28 Jul 20= 25 at 13:56, Tim D=C3=BCsterhus <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?


--0000000000000d09d0063afca1ff--