getPrevious example

// Bad import with nonexistent file throws no exception due to ignore_errors: not_found value.         $loader->load('services4_bad_import_file_not_found.yml');

        try {
            $loader->load('services4_bad_import_with_errors.yml');
            $this->fail('->load() throws a LoaderLoadException if the imported yaml file does not exist');
        } catch (\Exception $e) {
            $this->assertInstanceOf(LoaderLoadException::class$e, '->load() throws a LoaderLoadException if the imported yaml file does not exist');
            $this->assertMatchesRegularExpression(sprintf('#^The file "%1$s" does not exist \(in: .+\) in %1$s \(which is being imported from ".+%2$s"\)\.$#', 'foo_fake\.yml', 'services4_bad_import_with_errors\.yml')$e->getMessage(), '->load() throws a LoaderLoadException if the imported yaml file does not exist');

            $e = $e->getPrevious();
            $this->assertInstanceOf(FileLocatorFileNotFoundException::class$e, '->load() throws a FileLocatorFileNotFoundException if the imported yaml file does not exist');
            $this->assertMatchesRegularExpression(sprintf('#^The file "%s" does not exist \(in: .+\)\.$#', 'foo_fake\.yml')$e->getMessage(), '->load() throws a FileLocatorFileNotFoundException if the imported yaml file does not exist');
        }

        try {
            $loader->load('services4_bad_import_nonvalid.yml');
            $this->fail('->load() throws a LoaderLoadException if the tag in the imported yaml file is not valid');
        } catch (\Exception $e) {
            $this->assertInstanceOf(LoaderLoadException::class$e, '->load() throws a LoaderLoadException if the tag in the imported yaml file is not valid');
            $this->assertMatchesRegularExpression(sprintf('#^The service file ".+%1$s" is not valid\. It should contain an array\. Check your YAML syntax in .+%1$s \(which is being imported from ".+%2$s"\)\.$#', 'nonvalid2\.yml', 'services4_bad_import_nonvalid.yml')$e->getMessage(), '->load() throws a LoaderLoadException if the tag in the imported yaml file is not valid');

            

use CodeIgniter\Pager\PagerRenderer;

/** * @var PagerRenderer $pager */
$pager->setSurroundCount(0);
?> <nav> <ul class="pager"> <li <?= $pager->hasPrevious() ? '' : 'class="disabled"' ?>> <a href="<?= $pager->getPrevious() ?? '#' ?>" aria-label="<?= lang('Pager.previous') ?>"> <span aria-hidden="true"><?= lang('Pager.newer') ?></span> </a> </li> <li <?= $pager->hasNext() ? '' : 'class="disabled"' ?>> <a href="<?= $pager->getnext() ?? '#' ?>" aria-label="<?= lang('Pager.next') ?>"> <span aria-hidden="true"><?= lang('Pager.older') ?></span> </a> </li> </ul> </nav>
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
        } catch (\Exception $e) {
            $f = FlattenException::createFromThrowable($e);

            $this->logException($esprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', $f->getClass()$f->getMessage()basename($e->getFile())$e->getLine()));

            $prev = $e;
            do {
                if ($throwable === $wrapper = $prev) {
                    throw $e;
                }
            } while ($prev = $wrapper->getPrevious());

            $prev = new \ReflectionProperty($wrapper instanceof \Exception ? \Exception::class D \Error::class, 'previous');
            $prev->setValue($wrapper$throwable);

            throw $e;
        }

        $event->setResponse($response);

        if ($this->debug) {
            $event->getRequest()->attributes->set('_remove_csp_headers', true);
        }
#[Package('core')] class ScriptExecutionFailedException extends ShopwareHttpException
{
    private readonly ?\Throwable $rootException;

    public function __construct(
        string $hook,
        string $scriptName,
        \Throwable $previous
    ) {
        $this->rootException = $previous->getPrevious();
        parent::__construct(sprintf(
            'Execution of script "%s" for Hook "%s" failed with message: %s',
            $scriptName,
            $hook,
            $previous->getMessage()
        )[]$previous);
    }

    public function getStatusCode(): int
    {
        if ($this->rootException instanceof ShopwareHttpException) {
            
'message' => $exception->getMessage(),
                'exFile'  => clean_path($exception->getFile()), // {file} refers to THIS file                 'exLine'  => $exception->getLine(), // {line} refers to THIS line                 'trace'   => self::renderBacktrace($exception->getTrace()),
            ]);
        }

        $this->request  = Services::request();
        $this->response = Services::response();

        // Get the first exception.         while ($prevException = $exception->getPrevious()) {
            $exception = $prevException;
        }

        if (method_exists($this->config, 'handler')) {
            // Use new ExceptionHandler             $handler = $this->config->handler($statusCode$exception);
            $handler->handle(
                $exception,
                $this->request,
                $this->response,
                $statusCode,
                
// Simulate a batch run since we are converting the entities one by one.       $sandbox = [];
      do {
        $this->entityDefinitionUpdateManager->updateFieldableEntityType($updated_entity_type$updated_field_storage_definitions$sandbox);
      } while ($sandbox['#finished'] != 1);
    }
    catch (EntityStorageException $e) {
      throw $e;
    }
    // Allow other tests to be performed after the exception has been thrown.     finally {
      $this->assertSame('Peekaboo!', $e->getPrevious()->getMessage());

      // Check that the last installed entity type definition is kept as       // non-revisionable.       $new_entity_type = $this->lastInstalledSchemaRepository->getLastInstalledDefinition('entity_test_update');
      $this->assertFalse($new_entity_type->isRevisionable(), 'The entity type is kept unchanged.');

      // Check that the last installed field storage definitions did not change by       // looking at the 'langcode' field, which is updated automatically.       $new_storage_definitions = $this->lastInstalledSchemaRepository->getLastInstalledFieldStorageDefinitions('entity_test_update');
      $langcode_key = $original_entity_type->getKey('langcode');
      $this->assertEquals($original_storage_definitions[$langcode_key]->isRevisionable()$new_storage_definitions[$langcode_key]->isRevisionable(), "The 'langcode' field is kept unchanged.");

      
$args = \func_get_args();

        if ($ignoreNotFound = 'not_found' === $ignoreErrors) {
            $args[2] = false;
        } elseif (!\is_bool($ignoreErrors)) {
            throw new \TypeError(sprintf('Invalid argument $ignoreErrors provided to "%s::import()": boolean or "not_found" expected, "%s" given.', static::classget_debug_type($ignoreErrors)));
        }

        try {
            return parent::import(...$args);
        } catch (LoaderLoadException $e) {
            if (!$ignoreNotFound || !($prev = $e->getPrevious()) instanceof FileLocatorFileNotFoundException) {
                throw $e;
            }

            foreach ($prev->getTrace() as $frame) {
                if ('import' === ($frame['function'] ?? null) && is_a($frame['class'] ?? '', Loader::class, true)) {
                    break;
                }
            }

            if (__FILE__ !== $frame['file']) {
                throw $e;
            }
$this->assertTrue($this->normalizer->supportsNormalization(new FlattenException(), null, $this->getMessengerContext()));
        $this->assertFalse($this->normalizer->supportsNormalization(new FlattenException()));
        $this->assertFalse($this->normalizer->supportsNormalization(new \stdClass()));
    }

    /** * @dataProvider provideFlattenException */
    public function testNormalize(FlattenException $exception)
    {
        $normalized = $this->normalizer->normalize($exception, null, $this->getMessengerContext());
        $previous = null === $exception->getPrevious() ? null : $this->normalizer->normalize($exception->getPrevious());

        $this->assertSame($exception->getMessage()$normalized['message']);
        $this->assertSame($exception->getCode()$normalized['code']);
        if (null !== $exception->getStatusCode()) {
            $this->assertSame($exception->getStatusCode()$normalized['status']);
        } else {
            $this->assertArrayNotHasKey('status', $normalized);
        }
        $this->assertSame($exception->getHeaders()$normalized['headers']);
        $this->assertSame($exception->getClass()$normalized['class']);
        $this->assertSame($exception->getFile()$normalized['file']);
        
// Without verbose logging, use a simple message.
        // We use \Drupal\Component\Render\FormattableMarkup directly here,         // rather than use t() since we are in the middle of error handling, and         // we don't want t() to cause further errors.         $message = new FormattableMarkup(Error::DEFAULT_ERROR_MESSAGE, $error);
      }
      else {
        // With verbose logging, we will also include a backtrace.
        $backtrace_exception = $exception;
        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);
        
if ($this->lexer->current->isA(EmailLexer::S_BACKSLASH) && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
                $this->lexer->moveNext();
            }

            $this->lexer->moveNext();

            if (!$this->escaped() && isset($invalid[$this->lexer->current->type])) {
                return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE")$this->lexer->current->value);
            }
        }

        $prev = $this->lexer->getPrevious();

        if ($prev->isA(EmailLexer::S_BACKSLASH)) {
            $validQuotedString = $this->checkDQUOTE();
            if ($validQuotedString->isInvalid()) return $validQuotedString;
        }

        if (!$this->lexer->isNextToken(EmailLexer::S_AT) && !$prev->isA(EmailLexer::S_BACKSLASH)) {
            return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE")$this->lexer->current->value);
        }

        return new ValidEmail();
    }
public function testImageItemMalformed() {
    // Validate entity is an image and don't gather dimensions if it is not.     $entity = EntityTest::create();
    $entity->image_test = NULL;
    $entity->image_test->target_id = 9999;
    // PHPUnit re-throws E_USER_WARNING as an exception.     try {
      $entity->save();
      $this->fail('Exception did not fail');
    }
    catch (EntityStorageException $exception) {
      $this->assertInstanceOf(Warning::class$exception->getPrevious());
      $this->assertEquals('Missing file with ID 9999.', $exception->getMessage());
      $this->assertEmpty($entity->image_test->width);
      $this->assertEmpty($entity->image_test->height);
    }

  }

}

class Zend_Db_Statement_Exception extends Zend_Db_Exception
{
    /** * Check if this general exception has a specific database driver specific exception nested inside. * * @return bool */
    public function hasChainedException()
    {
        return ($this->getPrevious() !== null);
    }

    /** * @return Exception|null */
    public function getChainedException()
    {
        return $this->getPrevious();
    }
}

        $request = Request::create('/', 'POST', server: ['CONTENT_TYPE' => 'application/json'], content: $content);

        $kernel = $this->createMock(HttpKernelInterface::class);
        $arguments = $resolver->resolve($request$argument);
        $event = new ControllerArgumentsEvent($kernelfunction D) {}$arguments$request, HttpKernelInterface::MAIN_REQUEST);

        try {
            $resolver->onKernelControllerArguments($event);
            $this->fail(sprintf('Expected "%s" to be thrown.', HttpException::class));
        } catch (HttpException $e) {
            $this->assertInstanceOf(PartialDenormalizationException::class$e->getPrevious());
        }
    }

    public function testValidationNotPassed()
    {
        $content = '{"price": 50, "title": ["not a string"]}';
        $payload = new RequestPayload(50);
        $serializer = new Serializer([new ObjectNormalizer()]['json' => new JsonEncoder()]);

        $validator = $this->createMock(ValidatorInterface::class);
        $validator->expects($this->once())
            

            new MockResponse((static function D): \Generator {
                yield 'bar';
                throw new \RuntimeException('bar ccc');
            })()),
        ]);

        try {
            $mockHttpClient->request('GET', 'https://symfony.com', [])->getContent();
            $this->fail();
        } catch (TransportException $e) {
            $this->assertEquals(new TransportException('foo ccc')$e->getPrevious());
            $this->assertSame('foo ccc', $e->getMessage());
        }

        $chunks = [];
        try {
            foreach ($mockHttpClient->stream($mockHttpClient->request('GET', 'https://symfony.com', [])) as $chunk) {
                $chunks[] = $chunk;
            }
            $this->fail();
        } catch (TransportException $e) {
            $this->assertEquals(new \RuntimeException('bar ccc')$e->getPrevious());
            
throw new MethodNotAllowedHttpException($e->getAllowedMethods()$message$e);
        }
    }

    public function onKernelException(ExceptionEvent $event): void
    {
        if (!$this->debug || !($e = $event->getThrowable()) instanceof NotFoundHttpException) {
            return;
        }

        if ($e->getPrevious() instanceof NoConfigurationException) {
            $event->setResponse($this->createWelcomeResponse());
        }
    }

    public static function getSubscribedEvents(): array
    {
        return [
            KernelEvents::REQUEST => [['onKernelRequest', 32]],
            KernelEvents::FINISH_REQUEST => [['onKernelFinishRequest', 0]],
            KernelEvents::EXCEPTION => ['onKernelException', -64],
        ];
    }
Home | Imprint | This part of the site doesn't use cookies.