Skip to content

BO: Hide raw exception on state delete failure#40742

Open
mattiaclementi wants to merge 1 commit into
PrestaShop:developfrom
mattiaclementi:fix-delete-state
Open

BO: Hide raw exception on state delete failure#40742
mattiaclementi wants to merge 1 commit into
PrestaShop:developfrom
mattiaclementi:fix-delete-state

Conversation

@mattiaclementi
Copy link
Copy Markdown

Questions Answers
Branch? develop
Description? Handle DeleteStateException::FAILED_DELETE in the State BO controller to avoid exposing raw exception messages. Add an integration test ensuring an error flash is shown when delete fails.
Type? bug fix
Category? BO
BC breaks? no
Deprecations? no
How to test? 1) In BO go to International > Locations > States, try to delete a state linked to an address, and verify the flash error is An error occurred while deleting the object. (no raw exception message) 2) Run php vendor/bin/phpunit tests/Integration/PrestaShopBundle/Controller/Admin/Improve/International/StateControllerTest.php
UI Tests Not run (not applicable).
Fixed issue or discussion? Resolve #39761
Related PRs N/A
Sponsor company N/A

@mattiaclementi mattiaclementi requested a review from a team as a code owner February 11, 2026 08:06
@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Feb 11, 2026
@ps-jarvis ps-jarvis added develop Branch Bug fix Type: Bug fix labels Feb 11, 2026
@ps-jarvis
Copy link
Copy Markdown

Hello @mattiaclementi!

This is your first pull request on PrestaShop repository of the PrestaShop project.

Thank you, and welcome to this Open Source community!

@Touxten
Copy link
Copy Markdown
Contributor

Touxten commented Feb 11, 2026

Thanks you, I launched the CI.
It's much clearer for an e-merchant.
What do you think about explaining why this state cannot be deleted in the error message?

That way, the e-merchant won't try a second or third time...

@Touxten
Copy link
Copy Markdown
Contributor

Touxten commented Feb 11, 2026

cc @kpodemski for wording

@Touxten Touxten added this to the 9.2.0 milestone Feb 11, 2026
@ps-jarvis
Copy link
Copy Markdown

This pull request seems to contain new translation strings. I have summarized them below to ease up review:

  • Admin.Notifications.Error
    • This state cannot be deleted because it is used in at least one address.

(Note: this is an automated message, but answering it will reach a real human)

@mattiaclementi
Copy link
Copy Markdown
Author

Thanks you, I launched the CI. It's much clearer for an e-merchant. What do you think about explaining why this state cannot be deleted in the error message?

That way, the e-merchant won't try a second or third time...

It is a good idea, i've change the message to be much clearer.
Thank you.

Copy link
Copy Markdown
Contributor

@Hlavtox Hlavtox left a comment

Choose a reason for hiding this comment

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

Guys, this is not proper, the state can be deleted from multiple reasons, not only because the state is used.

The exception must be universal.

If needed, you can throw different exceptions with different messages. 👍

@ps-jarvis ps-jarvis added the Waiting for author Status: action required, waiting for author feedback label Feb 11, 2026
@ps-jarvis ps-jarvis moved this from Ready for review to Waiting for author in PR Dashboard Feb 11, 2026
@mattiaclementi
Copy link
Copy Markdown
Author

Guys, this is not proper, the state can be deleted from multiple reasons, not only because the state is used.

The exception must be universal.

If needed, you can throw different exceptions with different messages. 👍

You're right! Sorry, I deleted the last commit, so the message is generic again.

@Touxten Touxten removed the Waiting for author Status: action required, waiting for author feedback label Feb 12, 2026
@Touxten Touxten requested a review from Hlavtox February 12, 2026 08:42
Hlavtox
Hlavtox previously approved these changes Feb 12, 2026
@ps-jarvis ps-jarvis moved this from Waiting for author to Need 2nd approval in PR Dashboard Feb 12, 2026
Touxten
Touxten previously approved these changes Feb 12, 2026
@Touxten Touxten added the Waiting for QA Status: action required, waiting for test feedback label Feb 13, 2026
@ps-jarvis ps-jarvis moved this from Need 2nd approval to To be tested in PR Dashboard Feb 13, 2026
jolelievre
jolelievre previously approved these changes Feb 18, 2026
Copy link
Copy Markdown
Contributor

@jolelievre jolelievre left a comment

Choose a reason for hiding this comment

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

The integration test is maybe a bit overkill for such improvement But thank you for the accuracy

@jolelievre jolelievre closed this Feb 18, 2026
@github-project-automation github-project-automation Bot moved this from To be tested to Closed in PR Dashboard Feb 18, 2026
@jolelievre jolelievre reopened this Feb 18, 2026
@github-project-automation github-project-automation Bot moved this from Closed to Reopened in PR Dashboard Feb 18, 2026
Codencode
Codencode previously approved these changes Feb 18, 2026
@SiraDIOP SiraDIOP self-assigned this Feb 26, 2026
Copy link
Copy Markdown

@SiraDIOP SiraDIOP left a comment

Choose a reason for hiding this comment

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

Hello @mattiaclementi,

Thank you for your PR, I've tested this locally and everything looks good. However, I'm unable to approve the merge yet as the CI checks are still pending. I'll approve them and we'll see if everything passes! 🙂

Enregistrement.de.l.ecran.2026-02-26.a.19.16.54.mov

Thank you

@mattiaclementi
Copy link
Copy Markdown
Author

mattiaclementi commented Feb 26, 2026

Hello @mattiaclementi,

Thank you for your PR, I've tested this locally and everything looks good. However, I'm unable to approve the merge yet as the CI checks are still pending. I'll approve them and we'll see if everything passes! 🙂

Enregistrement.de.l.ecran.2026-02-26.a.19.16.54.mov
Thank you

Hi @SiraDIOP, i've force push a commit with the fix for header of tests/Integration/PrestaShopBundle/Controller/Admin/Improve/International/StateControllerTest.php file.
Now CI should pass without problems.
Thank you.

Copy link
Copy Markdown
Contributor

@kpodemski kpodemski left a comment

Choose a reason for hiding this comment

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

Hello @mattiaclementi

The only thing missing is to fix the license header in the test file you added. We've recently changed the format of the license header and added a CI checks for it.

@kpodemski kpodemski added Waiting for author Status: action required, waiting for author feedback and removed Waiting for QA Status: action required, waiting for test feedback labels Mar 10, 2026
@ps-jarvis ps-jarvis moved this from Reopened to Waiting for author in PR Dashboard Mar 10, 2026
@mattiaclementi mattiaclementi force-pushed the fix-delete-state branch 2 times, most recently from 14e32b5 to 9f06105 Compare March 13, 2026 17:32
@mattiaclementi
Copy link
Copy Markdown
Author

Hello @mattiaclementi

The only thing missing is to fix the license header in the test file you added. We've recently changed the format of the license header and added a CI checks for it.

Hello @kpodemski
I've commit the fix for license header, my repo workflow is green now.
Thank you.

@ps-jarvis ps-jarvis moved this from Waiting for author to Need 2nd approval in PR Dashboard Mar 25, 2026
@kpodemski kpodemski removed the Waiting for author Status: action required, waiting for author feedback label Mar 25, 2026
@ps-jarvis ps-jarvis added the Waiting for author Status: action required, waiting for author feedback label Mar 25, 2026
@ps-jarvis ps-jarvis moved this from Need 2nd approval to Waiting for author in PR Dashboard Mar 25, 2026
@kpodemski kpodemski requested a review from jolelievre March 25, 2026 12:57
@ps-jarvis ps-jarvis added the Waiting for QA Status: action required, waiting for test feedback label Mar 25, 2026
@ps-jarvis ps-jarvis moved this from Waiting for author to To be tested in PR Dashboard Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix Type: Bug fix develop Branch Waiting for author Status: action required, waiting for author feedback Waiting for QA Status: action required, waiting for test feedback

Projects

Status: To be tested

Development

Successfully merging this pull request may close these issues.

An unexpected error occurred. [PrestaShop\PrestaShop\Core\Domain\State\Exception\DeleteStateException code 1]

9 participants