Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[ErrorHandler] Add a command to dump static error pages#58769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:7.3frompyrech:dump-error-pages
Mar 1, 2025

Conversation

pyrech
Copy link
Contributor

@pyrechpyrech commentedNov 5, 2024
edited
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
Issues-
LicenseMIT

When a web server cannot handle a request or trigger an error without calling the PHP application, it will return instead its default error pages, ignoring completly the error templates defined by the application (Symfony's default "Oops" error page or overriden one in user's app).

Take for example the case of the simple/% url : it will trigger an error on almost all web servers (nginx, apache, cloudflare, etc):

In all these cases, web servers returned their default error page.

To avoid that, in some of our projects, we created a Symfony command to dump the application error pages in static HTML files that the web server can render when it encounters an internal error. The idea is to dump these pages at deploy time so there is nothing else to do at runtime.

Here is a sample on how we configured our nginx to use our beautiful error pages:

error_page 400 /error_pages/400.html;error_page 401 /error_pages/401.html;# ...error_page 510 /error_pages/510.html;error_page 511 /error_pages/511.html;location ^~ /error_pages/ {  root /path/to/your/symfony/var/cache/error_pages;  internal; # allows this location block to not be triggered when a user manually call these /error_pages/.* urls}

(Kudos to@xavierlacot for all the hard work and researches on this topic 💛)

We propose to add this command directly to Symfony so everybody can make use of it.

Usage

bin/console error:dump var/cache/prod/error_page [--force] [400 401 ... 511]

tucksaun, xavierlacot, ternel, damienalexandre, bastnic, ro0NL, lyrixx, alessandro-podo, dsentker, smnandre, and 4 more reacted with heart emoji
@carsonbotcarsonbot added this to the7.2 milestoneNov 5, 2024
@pyrechpyrechforce-pushed thedump-error-pages branch 4 times, most recently from2ce43b0 to79cfa6eCompareNovember 5, 2024 15:47
@pyrechpyrechforce-pushed thedump-error-pages branch 4 times, most recently fromd6d7401 to0fc7cebCompareNovember 12, 2024 20:55
@pyrech
Copy link
ContributorAuthor

I have just moved the command in the Twig bundle, applied most of the review suggestions (and mark them as resolved) and answered to the remaining ones.

I don't understand the psalm failure as the arrayNode method of the configuration is used elsewhere without issue. Did I miss something?

@pyrechpyrechforce-pushed thedump-error-pages branch 3 times, most recently from62cd182 to49aa562CompareNovember 12, 2024 21:57
@smnandre
Copy link
Member

I don't understand the psalm failure as the arrayNode method of the configuration is used elsewhere without issue. Did I miss something?

I guess it can be ignored, Psalm does not know the exact type of the "rootNode" here.. and so type it as ParentNode|ArrayDefinition 🤷‍♂️

pyrech reacted with thumbs up emoji

@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@pyrech
Copy link
ContributorAuthor

I guess it can be ignored, Psalm does not know the exact type of the "rootNode" here.. and so type it as ParentNode|ArrayDefinition 🤷‍♂️

The Psalm baseline seems to be build automatically so not sure if I have something to do on my side to "ignore" this error?

--

Meanwhile I fixed latest review comments. Is there anything I can do to move forward with PR? 🙂

Thanks

@Jean-Beru
Copy link
Contributor

Meanwhile I fixed latest review comments. Is there anything I can do to move forward with PR? 🙂

If we use semantic configuration to configure this command, we have to add a test inhttps://github.com/symfony/symfony/blob/7.3/src/Symfony/Bundle/TwigBundle/Tests/DependencyInjection/ConfigurationTest.php

FYI, we'll also have to updatehttps://github.com/symfony/symfony/blob/7.3/src/Symfony/Bundle/TwigBundle/Resources/config/schema/twig-1.0.xsd.

pyrech reacted with thumbs up emoji

@carsonbotcarsonbot changed the titleAdd a command to dump static error pages[TwigBundle] Add a command to dump static error pagesJan 6, 2025
@Jean-Beru
Copy link
Contributor

Jean-Beru commentedJan 7, 2025
edited
Loading

The Psalm baseline seems to be build automatically so not sure if I have something to do on my side to "ignore" this error?

Is it linked to a missing->end() after->prototype('integer')?

The configuration will be:

privatefunctionaddErrorDumperSection(ArrayNodeDefinition$rootNode):void    {$rootNode            ->children()                ->arrayNode('error_dumper')                    ->addDefaultsIfNotSet()                    ->children()                        ->scalarNode('path')                            ->info('The directory where error pages will be dumped.')                            ->defaultValue('%kernel.build_dir%/error_pages')                        ->end()                        ->arrayNode('status_codes')                            ->info('The error status codes to dump. By default, all 4xx and 5xx status codes will be dumped.')                            ->defaultValue([])                            ->integerPrototype()->end()                        ->end()                    ->end()                ->end()            ->end()        ;    }
pyrech reacted with heart emoji

@carsonbotcarsonbot changed the title[TwigBundle] Add a command to dump static error pages[ErrorHandler] Add a command to dump static error pagesFeb 20, 2025
Copy link
Member

@lyrixxlyrixx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks 👍🏼

@pyrech
Copy link
ContributorAuthor

pyrech commentedFeb 28, 2025
edited
Loading

Applied suggestions from@fabpot &@mtarld 👍

However, tests are now failling onSymfony\Bridge\Twig\Tests\NodeVisitor\TranslationDefaultDomainNodeVisitorTest , but I fail to see how this is related to this PR.

@pyrechpyrechforce-pushed thedump-error-pages branch 2 times, most recently from6b9e6fe to37899b7CompareFebruary 28, 2025 10:08
@OskarStark
Copy link
Contributor

However, tests are now failling on Symfony\Bridge\Twig\Tests\NodeVisitor\TranslationDefaultDomainNodeVisitorTest , but I fail to see how this is related to this PR.

You can ignore it then.
Checking the 7.3 branch if it is failing there too, is a good double check and if not, a rebase should help 😃

@pyrechpyrechforce-pushed thedump-error-pages branch 2 times, most recently fromd1a8c60 tob161e14CompareFebruary 28, 2025 11:17
@fabpot
Copy link
Member

Thank you@pyrech.

pyrech, lyrixx, and yceruto reacted with heart emoji

@fabpotfabpot merged commit9d84727 intosymfony:7.3Mar 1, 2025
8 of 9 checks passed
@pyrechpyrech deleted the dump-error-pages branchMarch 1, 2025 16:57
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestMar 10, 2025
This PR was merged into the 7.3 branch.Discussion----------Add documentation for `error:dump` command<!--If your pull request fixes a BUG, use the oldest maintained branch that containsthe bug (seehttps://symfony.com/releases for the list of maintained branches).If your pull request documents a NEW FEATURE, use the same Symfony branch wherethe feature was introduced (and `7.x` for features of unreleased versions).-->Fix#20704PR introducing the command:symfony/symfony#58769Commits-------d976d0e Add documentation for error:dump command
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@lyrixxlyrixxlyrixx approved these changes

@ycerutoycerutoyceruto approved these changes

@alexislefebvrealexislefebvrealexislefebvre left review comments

@fabpotfabpotfabpot approved these changes

@mtarldmtarldmtarld approved these changes

@smnandresmnandreAwaiting requested review from smnandre

@Jean-BeruJean-BeruAwaiting requested review from Jean-Beru

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

11 participants
@pyrech@smnandre@Jean-Beru@yceruto@stof@OskarStark@fabpot@lyrixx@alexislefebvre@mtarld@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp