Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:110315 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 8939 invoked from network); 30 May 2020 18:55:23 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 May 2020 18:55:23 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BD0AC1804C8 for ; Sat, 30 May 2020 10:36:33 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE, SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-vk1-f173.google.com (mail-vk1-f173.google.com [209.85.221.173]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 30 May 2020 10:36:32 -0700 (PDT) Received: by mail-vk1-f173.google.com with SMTP id s192so1460223vkh.3 for ; Sat, 30 May 2020 10:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=basereality-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=op9zdonmTyIsBbBn8V7aisebGrkkRpHESW6hDcipLu0=; b=EDlTCIygG1bNuIRWmMBAOwrq9Sw1lRtIW/1NKvDmKRFZL2yulIRPxomoCCt2fbSeyz KQsqay3f4VIL6TQLlszBWzktEuHEyD25ZcGmzHWFBnuTfVLMfS+o9r0NXThlzaH3SQd+ 1TFo3iJhJFfkU2RRtX7oypvy6gJECXX/lbv8F5rLn8w5NLs3zRrD7+MzGKqch2Igmeoo 0hBEAFbBBfRlQnXEHN9xa81ct4s5hl9xwyH99m7kyBsuKAlaAA5qVxri+hCMrEv2vRmd e5qJbOsZL6sbA7txcTx851tX6Xjb34zgnRqJDLYdwQbyMu3+dIShokyCBjA4y4wdvc+8 SHrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=op9zdonmTyIsBbBn8V7aisebGrkkRpHESW6hDcipLu0=; b=YFHmG0USAT3PJaTkjjNEKTI1a70VPTH0O+m0WtVEtWboPGaYXrAc7xc0M7SiNbcoco zzCH9VnLs2kCv37EEJEqDOfKml/WoBIiCvd3w7LR67fLSK5jDmCv4/vSIZqpUzrNzeTT zI3QPN2eIHf5Nvf8VoM5har7ztUD5hByS3qjGIakIMFw/oug9TkxM11v0Nl5OnLIsd7v Cx2MO4Ww9hHRfLcEnlbu8GHV9LL5hCBF46XviOoUKH3/RlgUY6/k82oB+XRGFsn1+yhm YWZ8Zrk/gVy8AP+fQR3+Vt5CfqOD31GDC4RV33feD0Q+Ije2uhzjzV6QGRUlPzRG9Htw krqQ== X-Gm-Message-State: AOAM530cwclg+w8usaTv87a85PQkrKodW3Z7S4IgQ0OrlQozMbkUhdqH dgazb7FpZk59qYy3nx9fkK1D07rCCue6OIYDqrQbOg== X-Google-Smtp-Source: ABdhPJxtdxblmleZfgLs47xgpEnxDDBlSklRoGPKg7rnYfJw/swIMiZ8bC8umeWTh8Txacu22z0cVN6Bwyh0HbUwGik= X-Received: by 2002:a1f:8cc3:: with SMTP id o186mr9600706vkd.18.1590860189074; Sat, 30 May 2020 10:36:29 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 30 May 2020 18:36:18 +0100 Message-ID: To: Max Semenik Cc: Internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] RFC: Error backtraces From: Danack@basereality.com (Dan Ackroyd) On Fri, 29 May 2020 at 19:23, Max Semenik wrote: > > Hi, I'd like to present a new RFC for your consideration: > https://wiki.php.net/rfc/error_backtraces > Hi Max, I've also been thinking about how errors + warnings can be improved also. For my own code, I convert all non-silenced errors and warnings into an exception through the error handler*. That works pretty well, but has one big downside - it only throws one type of exception. I wrote some words about what we could do: https://gist.github.com/Danack/6b5a86414ab9e9d9ac7e0a906216f1c5 The TL:DR of that is, we could add specific exceptions that should be thrown if the error handler setup by the user decided to throw an exception. I would be interested in hearing if that idea achieves the benefits you're trying to get, in a less controversial way. To give some feedback on your RFC. "traces will be formatted exactly like for exceptions, and appended to error messages," This has security implications as it would be possible for app secrets to be included in the error message. That is less of a problem for exceptions as you can write your own code for logging exceptions that doesn't expose the variables if you don't want them exposed. "..., traces are always generated for exceptions" That depends on what callback function has been set for 'set_exception_handler'. Also....maybe use more formal language for RFCs. Even minor swear words should be avoided imo. "error_get_last() output will have another element added to it if a trace is available:" I strongly suspect that is a very bad idea. As the variables in the stack trace are kept alive while that stack trace is kept alive, that means the lifetime of those variables would depend on how long until another error occurs. That sounds like code that is hard to reason about. "In the current proposed implementation, a new error flag E_UNHANDLED_EXCEPTION is introduced," The RFC doesn't say what this is meant to do precisely.....but my gut instinct doesn't like it. cheers Dan Ack * an error handler that converts all unsilenced errors that we care about into an exception function standardErrorHandler($errorNumber, $errorMessage, $errorFile, $errorLine): bool { if (error_reporting() === 0) { // Error reporting has been silenced if ($errorNumber !== E_USER_DEPRECATED) { return true; } } if ($errorNumber === E_DEPRECATED) { return false; } if ($errorNumber === E_CORE_ERROR || $errorNumber === E_ERROR) { // For these two types, PHP is shutting down anyway. Return false // to allow shutdown to continue return false; } $message = "Error: [$errorNumber] $errorMessage in file $errorFile on line $errorLine."; throw new \Exception($message); }