Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127260 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 E1F961A00BC for ; Thu, 1 May 2025 12:47:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1746103539; bh=3012M081DY0gjea364gKgtiPHGsmUG3unZ5wvnDRPew=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ZHbTEe+WcevNX02c711GYnD+CaJEnsFSn+NAqAiJBNUBv7FJ7WkkF3VCKU/X/k/+8 /WeyGOCEaYWxUqwCeDrHfKS0Btj+sjyfs97UF3ZEYpiWLNw4znDnqL9hL33tBvIecd M4Uqj1HUwTbG9gSEiFCfN8cVbiNeYiNNm8D0UK17rzO9JSdcUgdKbICb0g4GaqohUU GHATykOqb02z/c/32/LBmNtWqrjwD9TNmAdKNtiu/HK9BxR34yAc/kYjyEJGMy6i+K wLqbe0HCGnyjI5ysDe7kFE7uo7cj+Os6zuVucAoegD9WNyaFKi9uMMj3L1mCGR6/JJ lU+S+zOdDFYQQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5738A180081 for ; Thu, 1 May 2025 12:45:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_PDS_PRO_TLD autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from hamster.birch.relay.mailchannels.net (hamster.birch.relay.mailchannels.net [23.83.209.80]) (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 ; Thu, 1 May 2025 12:45:37 +0000 (UTC) X-Sender-Id: yszpovajlk|x-authuser|juris@glaive.pro Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 9321E2C192D; Thu, 1 May 2025 12:47:52 +0000 (UTC) Received: from server52.areait.lv (100-106-214-82.trex-nlb.outbound.svc.cluster.local [100.106.214.82]) (Authenticated sender: yszpovajlk) by relay.mailchannels.net (Postfix) with ESMTPA id 9C8C42C0668; Thu, 1 May 2025 12:47:51 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1746103672; a=rsa-sha256; cv=none; b=Z/OZ6bYOpK2rlv7rmrlyicuXlPdTEFjFYnPYywuzC6s6Cypn/HfBhtzmXmenj0OGhh3ap0 G5Af3zq48RLx4ApQgQNmBqDcc7I8FblCDizJgT2OudKMr1CIi2F6HPKb74bvQF7KOL95hQ Is2RecbBb38wfJjHZlvCEhiismgdndlJsZ6dqcRB/LCIS1rvL6Q4l6wT2dccqQ84dYuITv H7pKifM9Y3tME01nBis2ERN3zFGdfL2LaCNZwWYgcdZOI9XgxE+wrWaMcY0iBvio8G2IIM 34r7R93Q1l9XgTKSkfCgGCgpPuWUvThZpj5jzmCtQTKoItc2jzrKBfAPBcPBuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1746103672; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references:dkim-signature; bh=qt4wolqbQGOj5rL4YXWjqcI3+CvKb9JYjD8uYe4YqyQ=; b=pNdbHFpMQHlHiueg4wO/kurYxtOEQE0AI3IEej/RxFaxBg4huaGSLuZCONCZzXPeTe9ciB vtbb+YrL/HGTHg5cPCLnaznaknATrMkQBohdgPbK/9azJgOiRkMhFI5mwFecRqXsOHHMKL 0NzW++c4I+7Hu3v3tj6TDeONL7CP1IZgozO95uIwHz51h+Utv9Xap0wUpW2NvxhB+ybdrh tilklSUevsvJWd7inTd5CTJC2Y/JIdn8/oV25zCmEyEtILODvMxRc9/sI5i4aD5dB9vFwV vlJsge6K2+YbSZ+BmfWjw3UaX+ueMKeKYT5tT3rvpc70sFljM62Iyqzp0bH4NA== ARC-Authentication-Results: i=1; rspamd-56c68c6fd9-tjnhh; auth=pass smtp.auth=yszpovajlk smtp.mailfrom=juris@glaive.pro X-Sender-Id: yszpovajlk|x-authuser|juris@glaive.pro X-MC-Relay: Neutral X-MailChannels-SenderId: yszpovajlk|x-authuser|juris@glaive.pro X-MailChannels-Auth-Id: yszpovajlk X-Duck-Snatch: 2debb6cb70bdd07e_1746103672323_699473936 X-MC-Loop-Signature: 1746103672323:3026790079 X-MC-Ingress-Time: 1746103672323 Received: from server52.areait.lv (server52.areait.lv [83.149.95.205]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.106.214.82 (trex/7.0.3); Thu, 01 May 2025 12:47:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=glaive.pro; s=default; h=Content-Type:Message-ID:References:In-Reply-To:Subject:Cc:To: From:Date:MIME-Version:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=qt4wolqbQGOj5rL4YXWjqcI3+CvKb9JYjD8uYe4YqyQ=; b=M/q0NqPcdn/LB7WAxv2DlZypRl YNJmQbT/gM3PDTawEVO4hsVvfQ8hMuuK3p9z3QLUrx5w1nnF7xxs6BylyUz3NPxyTiszNquh/Ca+I SA17no4bSgtP61C/Szu45B2SRcDc2OTt1G+1kE4gjfDR5YFIBsRruh66lTqqyi772rEufNaRV6wOO v9T42pEuPboT0peUfClSVCS1yOPQMgHCFGmaeDLiCJm42gYRUwJ3PVEw04zke/LgadOnlgGK5HVo0 9DGJT+cLzVpA8nIBTAnHg2JtPPtX8xZWEy7eSdu5DkC1K+OZmsVpjAJYy2zK1Yln8R5VGES4McCFL sA7vc7qQ==; Received: from [::1] (port=56636 helo=glaive.pro) by server52.areait.lv with esmtpa (Exim 4.98.1) (envelope-from ) id 1uATKQ-00000008mSC-1pRJ; Thu, 01 May 2025 15:47:49 +0300 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 Date: Thu, 01 May 2025 15:47:49 +0300 To: Matthew Weier O'Phinney Cc: php internals Subject: Re: [PHP-DEV] Concept: Lightweight error channels In-Reply-To: References: <39597a9c-6854-40c6-a529-32b2b178cb27@app.fastmail.com> <150fb4df-47a4-4ab3-8edb-13e446b122cc@app.fastmail.com> <8ba39427-bc2d-4c2a-90d8-648371e4f576@app.fastmail.com> User-Agent: Roundcube Webmail/1.4.8 Message-ID: X-Sender: juris@glaive.pro Organization: SIA "Glaive.pro" Content-Type: multipart/alternative; boundary="=_3f50c65619d872364229b98f7d9c50b7" X-AuthUser: juris@glaive.pro From: juris@glaive.pro (Juris Evertovskis) --=_3f50c65619d872364229b98f7d9c50b7 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; format=flowed On 2025-04-29 17:29, Matthew Weier O'Phinney wrote: > * Exceptions should not be used for normal application logic flow. If > the "error" is recoverable and/or expected, use a different mechanism > so you can use standard conditional branching. > > As such, there are a lot of situations where I may not want to use > exceptions. Two common ones: > > * Input validation. In most cases, _invalid input is expected_, and a > condition you will handle in your code. Exceptions are a really poor > mechanism for this. > * "Not found" conditions, such as not finding a matching row in a > database or a cache. Again, this is expected, and something you should > handle via conditionals. I don't want to make this into a quarrel, please consider this to be a genuine question -- I'm trying to understand the viewpoint behind the need for such "failed result" channel. I'm considering this scenario: An update request comes into a controller and passes a superficial validation of field types. The 'troller invokes an action which in turn invokes a service or whatever the chain is. Somewhere along the call stack once all the data is loaded we realize that the request was invalid all along, e.g. the status can't be changed to X because that's not applicable for objects of kind B that have previously been in status Z. In such situations I have found (according to my experience) the following solution to be a good, robust and maintainable pattern: Once I find the request was invalid, I throw a ValidationException. No matter how deep in the stack I am. No matter that the callers don't know I might've thrown that. The exception will be caught and handled by some boundary layer (controller, middleware, error handler or whatever), formatted properly and returned to the user in a request-appropriate form. I currently have no urge to return an indication of invalidity manually and pass it up the call stack layer by layer. Should I want that? In my experience such patterns (requiring each layer to do an `if` for the possible issue and return up the stack instead of continuing the execution) get very clumsy for complex actions. Or have I misunderstood the usecase that you had in mind? BR, Juris --=_3f50c65619d872364229b98f7d9c50b7 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8

On 2025-04-29 17:29, Matthew Weier O'Phinney wrote:

 
* Exceptions should not be used for normal application logic flow. If = the "error" is recoverable and/or expected, use a different mechanism so yo= u can use standard conditional branching.
 
As such, there are a lot of situations where I may not want to use exc= eptions. Two common ones:
 
* Input validation. In most cases, _invalid input is expected_, and a = condition you will handle in your code. Exceptions are a really poor mechan= ism for this.
* "Not found" conditions, such as not finding a matching row in a data= base or a cache. Again, this is expected, and something you should handle v= ia conditionals.

I don't want to make this into a quarrel, please consider this to be a g= enuine question — I'm trying to understand the viewpoint behind the n= eed for such "failed result" channel.

I'm considering this scenario: An update request comes into a controller= and passes a superficial validation of field types. The 'troller invokes a= n action which in turn invokes a service or whatever the chain is. Somewher= e along the call stack once all the data is loaded we realize that the requ= est was invalid all along, e.g. the status can't be changed to X because th= at's not applicable for objects of kind B that have previously been in stat= us Z.

In such situations I have found (according to my experience) the followi= ng solution to be a good, robust and maintainable pattern:

Once I find the request was invalid, I throw a ValidationException. No m= atter how deep in the stack I am. No matter that the callers don't know I m= ight've thrown that. The exception will be caught and handled by some bound= ary layer (controller, middleware, error handler or whatever), formatted pr= operly and returned to the user in a request-appropriate form.

I currently have no urge to return an indication of invalidity manually = and pass it up the call stack layer by layer. Should I want that? In my exp= erience such patterns (requiring each layer to do an `if` for the possible = issue and return up the stack instead of continuing the execution) get very= clumsy for complex actions. Or have I misunderstood the usecase that you h= ad in mind?

BR,
Juris

--=_3f50c65619d872364229b98f7d9c50b7--