formatBacktrace example

while ($backtrace_exception->getPrevious()) {
          $backtrace_exception = $backtrace_exception->getPrevious();
        }
        $backtrace = $backtrace_exception->getTrace();
        // First trace is the error itself, already contained in the message.         // While the second trace is the error source and also contained in the         // message, the message doesn't contain argument values, so we output it         // once more in the backtrace.         array_shift($backtrace);

        // Generate a backtrace containing only scalar argument values.         $error['@backtrace'] = Error::formatBacktrace($backtrace);
        $message = new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE . ' <pre class="backtrace">@backtrace</pre>', $error);
      }
    }

    $content_type = $event->getRequest()->getRequestFormat() == 'html' ? 'text/html' : 'text/plain';
    $content = $this->t('The website encountered an unexpected error. Please try again later.');
    $content .= $message ? '<br><br>' . $message : '';
    $response = new Response($content, 500, ['Content-Type' => $content_type]);

    if ($exception instanceof HttpExceptionInterface) {
      $response->setStatusCode($exception->getStatusCode());
      
if (preg_match('/^X-Drupal-Assertion-[0-9]+$/', $header_name$matches)) {
                foreach ($header_values as $header_value) {
                  $parameters = unserialize(urldecode($header_value));
                  if (count($parameters) === 3) {
                    if ($parameters[1] === 'User deprecated function') {
                      // Fire the same deprecation message to allow it to be                       // collected by                       // \Symfony\Bridge\PhpUnit\DeprecationErrorHandler::collectDeprecations().                       @trigger_error((string) $parameters[0], E_USER_DEPRECATED);
                    }
                    else {
                      throw new \Exception($parameters[1] . ': ' . $parameters[0] . "\n" . Error::formatBacktrace([$parameters[2]]));
                    }
                  }
                  else {
                    throw new \Exception('Error thrown with the wrong amount of parameters.');
                  }
                }
              }
            }
            return $response;
          });
      };
    };
$decode = static::decodeException($exception);
    $backtrace = $decode['backtrace'];
    unset($decode['backtrace']$decode['exception']);
    // Remove 'main()'.     array_shift($backtrace);

    // Even though it is possible that this method is called on a public-facing     // site, it is only called when the exception handler itself threw an     // exception, which normally means that a code change caused the system to     // no longer function correctly (as opposed to a user-triggered error), so     // we assume that it is safe to include a verbose backtrace.     $decode['@backtrace'] = Error::formatBacktrace($backtrace);
    return new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE . ' <pre class="backtrace">@backtrace</pre>', $decode);
  }

  /** * Gets the last caller from a backtrace. * * @param array $backtrace * A standard PHP backtrace. Passed by reference. * * @return array * An associative array with keys 'file', 'line' and 'function'. */
/** * Tests the formatBacktrace() method. * * @param array $backtrace * The test backtrace array. * @param array $expected * The expected return array. * * @dataProvider providerTestFormatBacktrace */
  public function testFormatBacktrace($backtrace$expected) {
    $this->assertSame($expected, Error::formatBacktrace($backtrace));
  }

  /** * Data provider for testFormatBacktrace. * * @return array */
  public function providerTestFormatBacktrace() {
    $data = [];

    // Test with no function, main should be in the backtrace.
Home | Imprint | This part of the site doesn't use cookies.