Use this chapter as a guide:
Symfony Exception
Every time I get a Symfony Exception error instead of the errors that Laravel itself displays
The error looks like this:
FailedToInitializePatternSearchException > ViewException > ViewException > ViewException > ViewException > ViewException > ViewException
HTTP 500 Internal Server Error
And the error message:
Illuminate\View\ViewException:
(View: /Users/.../vendor/laravel/framework/src/Illuminate/Foundation/resources/exceptions/renderer/components/syntax-highlight.blade.php) (View: /Users/maksimsein/Documents/myProjects/letters-ge/letters-ge-api/vendor/laravel/framework/src/Illuminate/Foundation/resources/exceptions/renderer/components/syntax-highlight.blade.php) (View: /Users/maksimsein/Documents/myProjects/letters-ge/letters-ge-api/vendor/laravel/framework/src/Illuminate/Foundation/resources/exceptions/renderer/components/syntax-highlight.blade.php) (View: /Users/maksimsein/Documents/myProjects/letters-ge/letters-ge-api/vendor/laravel/framework/src/Illuminate/Foundation/resources/exceptions/renderer/components/syntax-highlight.blade.php) (View: /Users/maksimsein/Documents/myProjects/letters-ge/letters-ge-api/vendor/laravel/framework/src/Illuminate/Foundation/resources/exceptions/renderer/components/syntax-highlight.blade.php)
at /Users/.../vendor/phiki/phiki/src/TextMate/PatternSearcher.php:41
at Illuminate\View\Engines\CompilerEngine->handleViewException(object(ViewException), 1)
(/Users/.../vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php:59)
at Illuminate\View\Engines\PhpEngine->evaluatePath('/Users/.../storage/framework/views/0fdceac238c6af0ff02ab3603217985e.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'exception' => object(Exception), 'exceptionAsMarkdown' => '# Error - Internal Server ErrorPHP 8.3.23Laravel 12.30.1127.0.0.1:8000##
I didn't do any updates, didn't download any additional packages, the error just suddenly started displaying in this format
For example, I simply made a call to throw new \Error(); in the controller and instead of the expected error description from Laravel, I got the error description from Symfony.
I also tried running php artisan *:clear commands, I also cleared the cache in the bootstrap and framework/views folders, but it didn't work.
How to solve the problem?
Why should I use error reporting and customization if Laravel's basic debug messages aren't working and that's the only problem? :)
I tested throwing an error and it worked.
$value = -1;
if ($value < 0) {
throw new \Error('Error thrown.');
}
Are your dependencies correct for php and the laravel version you are using?
brianium/paratest v7.12.0 Parallel testing for PHP
brick/math 0.14.0 Arbitrary-precision arithmetic library
carbonphp/carbon-doctrine-types 3.2.0 Types to use Carbon in Doctrine
dflydev/dot-access-data v3.0.3 Given a deep data structure, access data by dot notation.
doctrine/deprecations 1.1.5 A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.
doctrine/inflector 2.1.0 PHP Doctrine Inflector is a small library that can perform string manipulations with regard to upper/lowercase and singular/plural forms of words.
doctrine/lexer 3.0.1 PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.
dragonmantank/cron-expression v3.4.0 CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
egulias/email-validator 4.0.4 A library for validating emails against several RFCs
fakerphp/faker v1.24.1 Faker is a PHP library that generates fake data for you.
fidry/cpu-core-counter 1.3.0 Tiny utility to get the number of CPU cores.
filp/whoops 2.18.4 php error handling for cool kids
firebase/php-jwt v6.11.1 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.
fruitcake/php-cors v1.3.0 Cross-origin resource sharing library for the Symfony HttpFoundation
graham-campbell/result-type v1.1.3 An Implementation Of The Result Type
guzzlehttp/guzzle 7.10.0 Guzzle is a PHP HTTP client library
guzzlehttp/promises 2.3.0 Guzzle promises library
guzzlehttp/psr7 2.8.0 PSR-7 message implementation that also provides common utility methods
guzzlehttp/uri-template v1.0.5 A polyfill class for uri_template of PHP
hamcrest/hamcrest-php v2.1.1 This is the PHP port of Hamcrest Matchers
jean85/pretty-package-versions 2.1.1 A library to get pretty versions strings of installed dependencies
laravel/cashier-paddle v2.6.2 Cashier Paddle provides an expressive, fluent interface to Paddle's subscription billing services.
laravel/framework v12.30.1 The Laravel Framework.
laravel/pail v1.2.3 Easily delve into your Laravel application's log files directly from the command line.
laravel/pint v1.25.1 An opinionated code formatter for PHP.
laravel/prompts v0.3.6 Add beautiful and user-friendly forms to your command-line applications.
laravel/sail v1.45.0 Docker files for running a basic Laravel application.
laravel/sanctum v4.2.0 Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.
laravel/serializable-closure v2.0.4 Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.
laravel/socialite v5.23.0 Laravel wrapper around OAuth 1 & OAuth 2 libraries.
laravel/tinker v2.10.1 Powerful REPL for the Laravel framework.
league/commonmark 2.7.1 Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)
league/config v1.2.0 Define configuration arrays with strict schemas and access values with dot notation
league/flysystem 3.30.0 File storage abstraction for PHP
league/flysystem-local 3.30.0 Local filesystem adapter for Flysystem.
league/mime-type-detection 1.16.0 Mime-type detection for Flysystem
league/oauth1-client v1.11.0 OAuth 1.0 Client Library
league/uri 7.5.1 URI manipulation library
league/uri-interfaces 7.5.0 Common interfaces and classes for URI representation and interaction
mockery/mockery 1.6.12 Mockery is a simple yet flexible PHP mock object framework
moneyphp/money v4.7.1 PHP implementation of Fowler's Money pattern
monolog/monolog 3.9.0 Sends your logs to files, sockets, inboxes, databases and various web services
myclabs/deep-copy 1.13.4 Create deep copies (clones) of your objects
nesbot/carbon 3.10.3 An API extension for DateTime that supports 281 different languages.
nette/schema v1.3.2 📐 Nette Schema: validating data structures against a given Schema.
nette/utils v4.0.8 🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong pass...
nikic/php-parser v5.6.1 A PHP parser written in PHP
nunomaduro/collision v8.8.2 Cli error handling for console/command-line PHP applications.
nunomaduro/termwind v2.3.1 Its like Tailwind CSS, but for the console.
paragonie/constant_time_encoding v3.1.3 Constant-time Implementations of RFC 4648 Encoding (Base-64, Base-32, Base-16)
paragonie/random_compat v9.99.100 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
pestphp/pest v4.1.0 The elegant PHP Testing Framework.
pestphp/pest-plugin v4.0.0 The Pest plugin manager
pestphp/pest-plugin-arch v4.0.0 The Arch plugin for Pest PHP.
pestphp/pest-plugin-laravel v4.0.0 The Pest Laravel Plugin
pestphp/pest-plugin-mutate v4.0.1 Mutates your code to find untested cases
pestphp/pest-plugin-profanity v4.1.0 The Pest Profanity Plugin
phar-io/manifest 2.0.4 Component for reading phar.io manifest information from a PHP Archive (PHAR)
phar-io/version 3.2.1 Library for handling version information and constraints
phiki/phiki v2.0.3 Syntax highlighting using TextMate grammars in PHP.
phpdocumentor/reflection-common 2.2.0 Common reflection classes used by phpdocumentor to reflect the code structure
phpdocumentor/reflection-docblock 5.6.3 With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.
phpdocumentor/type-resolver 1.10.0 A PSR-5 based resolver of Class names, Types and Structural Element Names
phpoption/phpoption 1.9.4 Option Type for PHP
phpseclib/phpseclib 3.0.46 PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.
phpstan/phpdoc-parser 2.3.0 PHPDoc parser with support for nullable, intersection and generic types
phpunit/php-code-coverage 12.3.8 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator 6.0.0 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-invoker 6.0.0 Invoke callables with a timeout
phpunit/php-text-template 5.0.0 Simple template engine.
phpunit/php-timer 8.0.0 Utility class for timing
phpunit/phpunit 12.3.8 The PHP Unit Testing framework.
psr/clock 1.0.0 Common interface for reading the clock.
psr/container 2.0.2 Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher 1.0.0 Standard interfaces for event handling.
psr/http-client 1.0.3 Common interface for HTTP clients
psr/http-factory 1.1.0 PSR-17: Common interfaces for PSR-7 HTTP message factories
psr/http-message 2.0 Common interface for HTTP messages
psr/log 3.0.2 Common interface for logging libraries
psr/simple-cache 3.0.0 Common interfaces for simple caching
psy/psysh v0.12.12 An interactive shell for modern PHP.
ralouphie/getallheaders 3.0.3 A polyfill for getallheaders.
ramsey/collection 2.1.1 A PHP library for representing and manipulating collections.
ramsey/uuid 4.9.1 A PHP library for generating and working with universally unique identifiers (UUIDs).
sebastian/cli-parser 4.2.0 Library for parsing CLI options
sebastian/comparator 7.1.3 Provides the functionality to compare PHP values for equality
sebastian/complexity 5.0.0 Library for calculating the complexity of PHP code units
sebastian/diff 7.0.0 Diff implementation
sebastian/environment 8.0.3 Provides functionality to handle HHVM/PHP environments
sebastian/exporter 7.0.0 Provides the functionality to export PHP variables for visualization
sebastian/global-state 8.0.2 Snapshotting of global state
sebastian/lines-of-code 4.0.0 Library for counting the lines of code in PHP source code
sebastian/object-enumerator 7.0.0 Traverses array structures and object graphs to enumerate all referenced objects
sebastian/object-reflector 5.0.0 Allows reflection of object attributes, including inherited and non-public ones
sebastian/recursion-context 7.0.1 Provides functionality to recursively process PHP variables
sebastian/type 6.0.3 Collection of value objects that represent the types of the PHP type system
sebastian/version 6.0.0 Library that helps with managing the version number of Git-hosted PHP projects
spatie/macroable 2.0.0 A trait to dynamically add methods to a class
spatie/url 2.4.0 Parse, build and manipulate URL's
staabm/side-effects-detector 1.0.5 A static analysis tool to detect side effects in PHP code
symfony/clock v7.3.0 Decouples applications from the system clock
symfony/console v7.3.3 Eases the creation of beautiful and testable command line interfaces
symfony/css-selector v7.3.0 Converts CSS selectors to XPath expressions
symfony/deprecation-contracts v3.6.0 A generic function and convention to trigger deprecation notices
symfony/error-handler v7.3.2 Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher v7.3.3 Provides tools that allow your application components to communicate with each other by dispatching events and listening to them
symfony/event-dispatcher-contracts v3.6.0 Generic abstractions related to dispatching event
symfony/finder v7.3.2 Finds files and directories via an intuitive fluent interface
symfony/http-foundation v7.3.3 Defines an object-oriented layer for the HTTP specification
symfony/http-kernel v7.3.3 Provides a structured process for converting a Request into a Response
symfony/mailer v7.3.3 Helps sending emails
symfony/mime v7.3.2 Allows manipulating MIME messages
symfony/polyfill-ctype v1.33.0 Symfony polyfill for ctype functions
symfony/polyfill-intl-grapheme v1.33.0 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-icu v1.33.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-intl-idn v1.33.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer v1.33.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring v1.33.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php80 v1.33.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/polyfill-php83 v1.33.0 Symfony polyfill backporting some PHP 8.3+ features to lower PHP versions
symfony/polyfill-php84 v1.33.0 Symfony polyfill backporting some PHP 8.4+ features to lower PHP versions
symfony/polyfill-php85 v1.33.0 Symfony polyfill backporting some PHP 8.5+ features to lower PHP versions
symfony/polyfill-uuid v1.33.0 Symfony polyfill for uuid functions
symfony/process v7.3.3 Executes commands in sub-processes
symfony/routing v7.3.2 Maps an HTTP request to a set of configuration variables
symfony/service-contracts v3.6.0 Generic abstractions related to writing services
symfony/string v7.3.3 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way
symfony/translation v7.3.3 Provides tools to internationalize your application
symfony/translation-contracts v3.6.0 Generic abstractions related to translation
symfony/uid v7.3.1 Provides an object-oriented API to generate and represent UIDs
symfony/var-dumper v7.3.3 Provides mechanisms for walking through any arbitrary PHP variable
symfony/yaml v7.3.3 Loads and dumps YAML files
ta-tikoma/phpunit-architecture-test 0.8.5 Methods for testing application architecture
theseer/tokenizer 1.2.3 A small library for converting tokenized PHP source code into XML and potentially other formats
tijsverkoyen/css-to-inline-styles v2.3.0 CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're se...
vlucas/phpdotenv v5.6.2 Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
voku/portable-ascii 2.0.3 Portable ASCII library - performance optimized (ascii) string functions for php.
webmozart/assert 1.11.0 Assertions to validate method input/output with nice error messages.
I just used the basic laravel installation
Show the whole controller method.
There is nothing unusual about it.
Route::get('***', ***Controller::class);
And inside the controller, I immediately raise an error (this is done specifically to show that Laravel cannot correctly display such a simple error)
class ***Controller extends Controller
{
/**
* Handle the incoming request.
*/
public function __invoke(Request $request): JsonResponse
{
throw new \Error();
}
}
What is '***'? Is it namespaced? It seems to be an ajax request, so you need to return json.
An example:
if ($validator->fails()) {
return Response::json($validator->errors(), 422);
}
And I display errors in a div.
Also look at other examples here: https://laravel.com/docs/12.x/errors#rendering-exceptions
They're not trying to debug their code or render custom responses. Their issue is that Laravel's debug page isn't rendering correctly when there's an exception.
Yes, you are right
I suggest if using the php built in server, try apache or nginx instead.
Edit:
What shows in the network tab, response?
I did another test, it is using apache:
Route:
Route::get('tc', TestController::class);
Controller:
<?php
namespace App\Http\Controllers;
class TestController extends Controller
{
public function __invoke(): JsonResponse
{
throw new \Error('yes error here');
}
}
The laravel error page showed with no problems.
Latest laravel, PHP 8.4.
But in production you don't want this, you need to have friendly error pages or if ajax a div showing the error and a redirect to somewhere link.
Does the HTML response body contain any output before the <!doctype>? Do all the response headers look ok, e.g. is Content-Type text/html?
Also wondering what IDE you use. That '***' isn't correct. Unless I am missing something new in laravel.
I wasn't sure if he actually named it with '***' or not.
All I know is it works on my machine.
Please or to participate in this conversation.