getMessage example

public function handleExecutionException(\Exception $exception, StatementInterface $statement, array $arguments = [], array $options = []): void {
    if ($exception instanceof \PDOException) {
      // Wrap the exception in another exception, because PHP does not allow       // overriding Exception::getMessage(). Its message is the extra database       // debug information.       $code = is_int($exception->getCode()) ? $exception->getCode() : 0;

      // If a max_allowed_packet error occurs the message length is truncated.       // This should prevent the error from recurring if the exception is logged       // to the database using dblog or the like.       if (($exception->errorInfo[1] ?? NULL) === 1153) {
        $message = Unicode::truncateBytes($exception->getMessage(), Connection::MIN_MAX_ALLOWED_PACKET);
        throw new DatabaseExceptionWrapper($message$code$exception);
      }

      $message = $exception->getMessage() . ": " . $statement->getQueryString() . "; " . print_r($arguments, TRUE);

      // SQLSTATE 23xxx errors indicate an integrity constraint violation. Also,       // in case of attempted INSERT of a record with an undefined column and no       // default value indicated in schema, MySql returns a 1364 error code.       if (
        substr($exception->getCode(), -6, -3) == '23' ||
        ($exception->errorInfo[1] ?? NULL) === 1364
      )
sleep('\\' === \DIRECTORY_SEPARATOR ? 10 : 1);

        if (!$process->isRunning()) {
            if ('\\' !== \DIRECTORY_SEPARATOR && 127 === $process->getExitCode()) {
                throw new SkippedTestSuiteError('vulcain binary is missing');
            }

            if ('\\' !== \DIRECTORY_SEPARATOR && 126 === $process->getExitCode()) {
                throw new SkippedTestSuiteError('vulcain binary is not executable');
            }

            throw new SkippedTestSuiteError((new ProcessFailedException($process))->getMessage());
        }

        self::$vulcainStarted = true;
    }

    public function testHandleIsRemovedOnException()
    {
        $client = $this->getHttpClient(__FUNCTION__);

        try {
            $client->request('GET', 'http://localhost:8057/304');
            
/** * @internal * * @covers \Shopware\Elasticsearch\Exception\NoIndexedDocumentsException */
class NoIndexedDocumentsExceptionTest extends TestCase
{
    public function testException(): void
    {
        $exception = new NoIndexedDocumentsException('product');

        static::assertStringContainsString('No indexed documents found for entity product', $exception->getMessage());
        static::assertSame('ELASTICSEARCH_NO_INDEXED_DOCUMENTS', $exception->getErrorCode());
    }
}

class Exception extends \Exception
{
    /** * Prettify error message output. * * @return string */
    public function errorMessage()
    {
        return '<strong>' . htmlspecialchars($this->getMessage(), ENT_COMPAT | ENT_HTML401) . "</strong><br />\n";
    }
}
$prev = $matches[1];
      }
      $value = $prev . ' -> ' . ($entity->getLoadedRevisionId() + 1);
      $entity->set('non_mul_field', $value);
      $previous_untranslatable_field_value = $value;
    }

    $violations = $entity->validate();
    $messages = [];
    foreach ($violations as $violation) {
      /** \Symfony\Component\Validator\ConstraintViolationInterface */
      $messages[] = $violation->getMessage();
    }
    $this->assertEquals($valid, !$violations->count()$this->formatMessage('Validation does not match the expected result: %s', implode(', ', $messages)));

    if ($valid) {
      $entity->save();

      // Reload the current revision translation and the default revision to       // make sure data was stored correctly.       /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
      $entity = $this->storage->loadRevision($entity->getRevisionId());
      $entity = $entity->getTranslation($active_langcode);
      
$plugins = [];

        if (isset($this->plugins[$o->type][$trigger])) {
            $plugins = $this->plugins[$o->type][$trigger];
        }

        foreach ($plugins as $plugin) {
            try {
                $plugin->parse($var$o$trigger);
            } catch (Exception $e) {
                \trigger_error(
                    'An exception ('.\get_class($e).') was thrown in '.$e->getFile().' on line '.$e->getLine().' while executing Kint Parser Plugin "'.\get_class($plugin).'". Error message: '.$e->getMessage(),
                    E_USER_WARNING
                );
            }

            if ($this->parse_break) {
                $this->parse_break = $break_stash;

                return false;
            }
        }

        
private HandlersLocatorInterface $handlersLocator,
        private bool $allowNoHandlers = false,
    ) {
    }

    /** * @throws NoHandlerForMessageException When no handler is found and $allowNoHandlers is false */
    public function handle(Envelope $envelope, StackInterface $stack): Envelope
    {
        $handler = null;
        $message = $envelope->getMessage();

        $context = [
            'class' => $message::class,
        ];

        $exceptions = [];
        $alreadyHandled = false;
        foreach ($this->handlersLocator->getHandlers($envelope) as $handlerDescriptor) {
            if ($this->messageHasAlreadyBeenHandled($envelope$handlerDescriptor)) {
                $alreadyHandled = true;
                continue;
            }
try {
      $pdo = new \PDO($dsn$connection_options['username']$connection_options['password']$connection_options['pdo']);
    }
    catch (\PDOException $e) {
      switch ($e->getCode()) {
        case static::CONNECTION_REFUSED:
          if (isset($connection_options['unix_socket'])) {
            // Show message for socket connection via 'unix_socket' option.             $message = 'Drupal is configured to connect to the database server via a socket, but the socket file could not be found.';
            $message .= ' This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.';
            throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode()$e);
          }
          if (isset($connection_options['host']) && in_array(strtolower($connection_options['host'])['', 'localhost'], TRUE)) {
            // Show message for socket connection via 'host' option.             $message = 'Drupal was attempting to connect to the database server via a socket, but the socket file could not be found.';
            $message .= ' A Unix socket file is used if you do not specify a host name or if you specify the special host name localhost.';
            $message .= ' To connect via TPC/IP use an IP address (127.0.0.1 for IPv4) instead of "localhost".';
            $message .= ' This message normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name when trying to connect to the server.';
            throw new DatabaseConnectionRefusedException($e->getMessage() . ' [Tip: ' . $message . '] ', $e->getCode()$e);
          }
          // Show message for TCP/IP connection.           $message = 'This message normally means that there is no MySQL server running on the system or that you are using an incorrect host name or port number when trying to connect to the server.';
          


  /** * Tests the BrowserTestBase tests can use strict schema checking. */
  public function test() {
    try {
      $this->configFactory->getEditable('config_schema_test.schemaless')->set('foo', 'bar')->save();
    }
    catch (SchemaIncompleteException $e) {
      return [
        '#markup' => $e->getMessage(),
      ];
    }
  }

}
$encodedIds = array_map([__CLASS__, 'encodeKey']$ids);

            $encodedResult = $this->checkResultCode($this->getClient()->getMulti($encodedIds));

            $result = [];
            foreach ($encodedResult as $key => $value) {
                $result[self::decodeKey($key)] = $this->marshaller->unmarshall($value);
            }

            return $result;
        } catch (\Error $e) {
            throw new \ErrorException($e->getMessage()$e->getCode(), \E_ERROR, $e->getFile()$e->getLine());
        }
    }

    protected function doHave(string $id): bool
    {
        return false !== $this->getClient()->get(self::encodeKey($id)) || $this->checkResultCode(\Memcached::RES_SUCCESS === $this->client->getResultCode());
    }

    protected function doDelete(array $ids): bool
    {
        $ok = true;
        

  public function onError(ExceptionEvent $event) {
    $exception = $event->getThrowable();
    $error = Error::decodeException($exception);
    $this->logger->get('php')->log($error['severity_level'], Error::DEFAULT_ERROR_MESSAGE, $error);

    $is_critical = !$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500;
    if ($is_critical) {
      error_log(sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception)$exception->getMessage()$exception->getFile()$exception->getLine()));
    }
  }

  /** * Log all exceptions. * * @param \Symfony\Component\HttpKernel\Event\ExceptionEvent $event * The event to process. */
  public function onException(ExceptionEvent $event) {
    $exception = $event->getThrowable();

    
$this->setRandomFixtureConfig($fixture);

    // Create an independent memory storage as a backup.     $backup = new MemoryStorage();
    static::replaceStorageContents($this->memory, $backup);

    try {
      call_user_func_array([$this->storage, $method]$arguments);
      $this->fail("exception not thrown");
    }
    catch (\BadMethodCallException $exception) {
      $this->assertEquals(ReadOnlyStorage::class D '::' . $method . ' is not allowed on a ReadOnlyStorage', $exception->getMessage());
    }

    // Assert that the memory storage has not been altered.     $this->assertEquals($backup$this->memory);
  }

  /** * Provide the methods that throw an exception. * * @return array * The data */
throw PaymentException::unknownPaymentMethod($salesChannelContext->getPaymentMethod()->getId());
            }

            if (!($paymentHandler instanceof PreparedPaymentHandlerInterface)) {
                return null;
            }

            return $paymentHandler->validate($cart$dataBag$salesChannelContext);
        } catch (PaymentException $e) {
            $customer = $salesChannelContext->getCustomer();
            $customerId = $customer !== null ? $customer->getId() : '';
            $this->logger->error('An error occurred during processing the validation of the payment. The order has not been placed yet.', ['customerId' => $customerId, 'exceptionMessage' => $e->getMessage()]);

            throw $e;
        }
    }

    public function handlePostOrderPayment(
        OrderEntity $order,
        RequestDataBag $dataBag,
        SalesChannelContext $salesChannelContext,
        ?Struct $preOrderStruct
    ): void {
        
set_exception_handler(static function DThrowable $exception): void {
    echo "\n";

    $cause = $exception;
    $root = true;

    while (null !== $cause) {
        if (!$root) {
            echo "Caused by\n";
        }

        echo $cause::class.': '.$cause->getMessage()."\n";
        echo "\n";
        echo $cause->getFile().':'.$cause->getLine()."\n";
        echo $cause->getTraceAsString()."\n";

        $cause = $cause->getPrevious();
        $root = false;
    }
});

$autoload = __DIR__.'/../../vendor/autoload.php';


            },
            2,
            $logger = new TestLogger()
        );

        $response = $client->request('GET', 'http://does.not.exists/foo-bar');

        try {
            $response->getHeaders();
        } catch (TransportExceptionInterface $e) {
            $this->assertSame('Could not resolve host "does.not.exists".', $e->getMessage());
        }
        $this->assertCount(2, $logger->logs);
        $this->assertSame('Try #{count} after {delay}ms: Could not resolve host "does.not.exists".', $logger->logs[0]);
    }

    public function testCancelOnTimeout()
    {
        $client = HttpClient::create();

        if ($client instanceof NativeHttpClient) {
            $this->markTestSkipped('NativeHttpClient cannot timeout before receiving headers');
        }
Home | Imprint | This part of the site doesn't use cookies.