Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] Handle error when expected directory is a file #60808

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from

Conversation

afiestas
Copy link

@afiestas afiestas commented Jun 17, 2025

Q A
Branch? 7.4
Bug fix? kinda
New feature? no
Deprecations? no
License MIT

[HttpFoundation] In File::getTargetFile the directory is recursively created if it does not exists. If directory creation fails a FileException is thrown.

This commit improves error clarity by adding a new FileException for the relatively common case where the path exists but instead of a directory it is a file.

Since errors from @mkdir are being suppressed we don't really know why the operation has failed.

There are many ways of doing this depending on the warranties that Symfony gives on retro-compatibility for the thrown exceptions. I Haven't been able to find documentation about that so I've decided to open a PR with the easiest to read change to get the conversation started.

Depending on your preferences we could:

  • Manage the mkdir errors similar to how is done in Filesystem::box. Perhaps add that extra information after the current message like "Unable to create the %s directory (error goes here).
  • Same thing as the PR but as part of the if/elseif block.
  • Move the is_file check within the error handling code path to prevent another I/O operation (so we do not affect the happy path)
  • Others?

Also since I haven't been able to find the compatibility guidelines I'm doing this to the 7.4 branch.

@carsonbot carsonbot added this to the 7.4 milestone Jun 17, 2025
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 7.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot

This comment was marked as outdated.

@afiestas afiestas force-pushed the bug/file-error-improvement branch 2 times, most recently from 3337a3a to c1c4494 Compare June 17, 2025 09:04
In File::getTargetFile the directory is recursively
created if it does not exists. If directory creation
fails a FileException is thrown.

This commit improves error clarity by adding  a new Exception
for the relatively common situation where the path exists but
instead of a directory it is a file.
@afiestas afiestas force-pushed the bug/file-error-improvement branch from c1c4494 to 3d65354 Compare June 17, 2025 09:11
@carsonbot carsonbot changed the title Handle error when expected directory is a file [HttpFoundation] Handle error when expected directory is a file Jun 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants