Skip to content

Conversation

@yceruto
Copy link
Member

@yceruto yceruto commented Mar 24, 2025

Q A
Branch? 7.4
Bug fix? no
New feature? yes
Deprecations? no
Issues -
License MIT

Alternative approach to #58456 (same goal), using a factory selector to pick the correct error renderer based on the runtime mode (APP_RUNTIME_MODE). One advantage of this solution is that it works even if TwigBundle is not installed as the selector/decider doesn't depend on it.

image

@yceruto
Copy link
Member Author

yceruto commented Mar 25, 2025

Now after updating some related tests, I'm concerned that this might break some functional tests out there (after upgrading to 7.3) for example: testing HTML error pages using WebTestCase won't work anymore if these tests are checking for more than just the error message.

Should we consider this a BC break?

This comment was marked as resolved.

@yceruto yceruto force-pushed the cli_errors branch 3 times, most recently from c281ec6 to bb5934f Compare April 2, 2025 17:33
@Spomky
Copy link
Contributor

Spomky commented Apr 8, 2025

Hi,

Thanks, it looks good to me at first glance.
I'll test it on my side to see how it behaves.

@Spomky
Copy link
Contributor

Spomky commented Apr 8, 2025

testing HTML error pages using WebTestCase won't work anymore if these tests are checking for more than just the error message.

Is there a way to opt-in for this feature (e.g. a dedicated env var)?

@yceruto
Copy link
Member Author

yceruto commented Apr 8, 2025

testing HTML error pages using WebTestCase won't work anymore if these tests are checking for more than just the error message.

Is there a way to opt-in for this feature (e.g. a dedicated env var)?

This small change restores the previous behavior. We could document this adjustment for situations where you specifically want to test the actual HTML error page:

-    ->alias('error_renderer.default', 'error_handler.error_renderer.default')
+    ->alias('error_renderer.default', 'error_renderer.html')

Most functional/end-to-end tests have a dedicated config file. That could be better than using an env var, since you can enable or disable this behavior case by case.

@yceruto
Copy link
Member Author

yceruto commented Apr 8, 2025

Or we could add a new framework option to opt-in for this behavior, include a deprecation notice to make it the default in 8.0, and update the recipe file to set it as the default for new projects. What do you think?

@Spomky
Copy link
Contributor

Spomky commented Apr 8, 2025

Sounds good 👍

@yceruto yceruto added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label Apr 9, 2025
@yceruto yceruto removed the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label May 2, 2025
@fabpot fabpot modified the milestones: 7.3, 7.4 May 26, 2025
@craigh
Copy link

craigh commented Oct 15, 2025

support 👍

@yceruto yceruto added the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label Oct 16, 2025
@yceruto
Copy link
Member Author

yceruto commented Oct 17, 2025

Still pending on my side to add the deprecation notice to make the new option defaults to true in 8.0. + a new recipe to set it to true for 7.4 (new projects)

@GromNaN
Copy link
Member

GromNaN commented Oct 23, 2025

Test failure on php_errors_log_levels.yml is a false-positive.

  # Check YAML files for syntax errors
  rm -rf b && cp -a a b && cd b
  find . -name '*.yml' -o -name '*.yaml' \
    | while read -r FILE; do php -r '
      use Symfony\Component\Yaml\{Parser,Yaml};
      require $_SERVER["HOME"]."/.composer/vendor/autoload.php";
      try { (new Parser())->parse(file_get_contents($argv[1]), Yaml::PARSE_CUSTOM_TAGS); }
      catch (Exception $e) { echo "::error::in $argv[1]:\n{$e->getMessage()}\n"; exit(1); }
    ' "$FILE"
    done
  cd ..
  shell: /usr/bin/bash -e {0}
  env:
    GH_TOKEN: ***
Error: in ./src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/php_errors_log_levels.yml:
Non-string keys are not supported. Quote your evaluable mapping keys instead at line 8 (near "!php/const \E_NOTICE: !php/const Psr\Log\LogLevel::ERROR").

@symfony/mergers This PR is ready for 7.4

@nicolas-grekas nicolas-grekas removed the ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" label Oct 24, 2025
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

I think this can and should wait for 8.1
Also because with my latest suggestion, the naming isn't appropriate anymore, and I'm not super happy with adding a new option to everybody's config once again in 7.x.

Also, I'm wondering: couldn't we remove the option? I read that web test cases are the issue. But shouldn't web test cases run in "web" mode?

@yceruto
Copy link
Member Author

yceruto commented Oct 24, 2025

Now with the last suggestion I think the option can be removed as ppl will have the APP_RUNTIME_MODE to switch when they need it.

I will do the changes so we can merge this in 7.4, is it ok for you @nicolas-grekas ?

@yceruto yceruto added Status: Needs Work ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" and removed Status: Reviewed labels Oct 24, 2025
@yceruto yceruto changed the title [ErrorHandler][FrameworkBundle] Add SapiErrorRendererSelector for context-based error rendering [ErrorHandler][FrameworkBundle] Add support for selecting the appropriate error renderer based on the APP_RUNTIME_MODE Oct 24, 2025
@yceruto yceruto force-pushed the cli_errors branch 2 times, most recently from a43365f to ef0f23e Compare October 24, 2025 14:59
@yceruto yceruto force-pushed the cli_errors branch 3 times, most recently from 561e35a to 4920c79 Compare October 24, 2025 15:33
…iate error renderer based on the `APP_RUNTIME_MODE`
@nicolas-grekas
Copy link
Member

Thank you @yceruto.

@nicolas-grekas nicolas-grekas merged commit ecb9dc4 into symfony:7.4 Oct 24, 2025
5 of 12 checks passed
@yceruto yceruto deleted the cli_errors branch October 24, 2025 18:26
xabbuh added a commit that referenced this pull request Oct 24, 2025
… of inline service (yceruto)

This PR was merged into the 7.4 branch.

Discussion
----------

 Fix argument syntax for callable and lazy initialization of inline service

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Issues        | -
| License       | MIT

Fix tests from #60033

Commits
-------

0f6b9eb Fix argument syntax for callable and lazy initialization of inline service
This was referenced Oct 27, 2025
@aschempp
Copy link
Contributor

aschempp commented Dec 1, 2025

As anticipated by @yceruto this breaks some of our functional tests. It can be bypassed by passing ['APP_RUNTIME_MODE' => 'web=1'] to the FunctionalTest::createClient, but I'm not sure this is/was intended in a minor version?

@alexislefebvre
Copy link
Contributor

alexislefebvre commented Dec 1, 2025

As anticipated by @yceruto this breaks some of our functional tests. It can be bypassed by passing ['APP_RUNTIME_MODE' => 'web=1'] to the FunctionalTest::createClient, but I'm not sure this is/was intended in a minor version?

Could you please share the whole code to set APP_RUNTIME_MODE properly? I can’t find a way to make it work.


Update: I put it in phpunit.xml.dist and it worked.

  <php>
    <env name="APP_RUNTIME_MODE" value="web=1"/>
  </php>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ErrorHandler Feature FrameworkBundle ❄️ Feature Freeze Important Pull Requests to finish before the next Symfony "feature freeze" Status: Needs Work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants