? ? Pending

User tests: Successful: Unsuccessful:

avatar olleharstedt
olleharstedt
14 May 2019

Pull Request for Issue #24887.

Summary of Changes

Throw exception instead of returning false.

Testing Instructions

Expected result

Actual result

Documentation Changes Required

avatar olleharstedt olleharstedt - open - 14 May 2019
avatar olleharstedt olleharstedt - change - 14 May 2019
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 14 May 2019
Category Libraries
avatar HLeithner HLeithner - change - 14 May 2019
Title
[imp] Throw exception instead of returning false when uploading file
[4.0] Throw exception instead of returning false when uploading file
avatar HLeithner HLeithner - edited - 14 May 2019
avatar HLeithner HLeithner - change - 14 May 2019
Title
[imp] Throw exception instead of returning false when uploading file
[4.0] Throw exception instead of returning false when uploading file
avatar olleharstedt olleharstedt - change - 14 May 2019
Labels Added: ?
avatar olleharstedt
olleharstedt - comment - 14 May 2019

Two issues:

  1. All exceptions have the same error code. If you want, I can make the error code different for each exception, making it possible for client code to react differently.

  2. This change should be applied to ALL methods in the File class.

avatar olleharstedt
olleharstedt - comment - 14 May 2019

Does Joomla core handle these exception? If not please also adapt core files.

Not sure what you mean here. Adapt how? With try-catch blocks?

avatar HLeithner
HLeithner - comment - 14 May 2019

Does Joomla core handle these exception? If not please also adapt core files.

Not sure what you mean here. Adapt how? With try-catch blocks?

It depends on the case if it suites to catch the exception and handle the return better then do nothing then yes.

avatar olleharstedt
olleharstedt - comment - 14 May 2019

It depends on the case if it suites to catch the exception and handle the return better then do nothing then yes.

I have honestly no idea on which change would be accepted here: https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Installer/Installer.php#L1727

Is there a try-catch at the top? Should I catch it and ignore the error message in the exception? Should the installer be changed also to throw exceptions at failure instead of returning false?

avatar mbabker
mbabker - comment - 14 May 2019

Instead of consistently re-using the SPL Exceptions, core really needs to get better about introducing Exception subclasses that makes it easier to catch specific error types. A try/catch around a RuntimeException is honestly too vague because so many of the SPL Exceptions are subclasses of that, as well as many of the (albeit limited) Joomla Exception classes.

avatar HLeithner
HLeithner - comment - 14 May 2019

Instead of consistently re-using the SPL Exceptions, core really needs to get better about introducing Exception subclasses that makes it easier to catch specific error types. A try/catch around a RuntimeException is honestly too vague because so many of the SPL Exceptions are subclasses of that, as well as many of the (albeit limited) Joomla Exception classes.

iirc many Joomla specific exception classes get removed lately ymmv

avatar mbabker
mbabker - comment - 14 May 2019

Not that I'm aware of? JException was removed, maybe the database exceptions since the Framework package is in use (which also has its own Exception subclasses), that's all I can think of off hand.

avatar HLeithner
HLeithner - comment - 14 May 2019

Not that I'm aware of? JException was removed, maybe the database exceptions since the Framework package is in use (which also has its own Exception subclasses), that's all I can think of off hand.

ok I thought there was more then the JException class.

avatar olleharstedt
olleharstedt - comment - 14 May 2019

There are 12 try-catch blocks in the joomla-cms repo right now. 9 of them are in the Crypto class, the other in Sniffs (phpcs). With this lack of precedence, I have low confidence that I can manage to write something that will be accepted.

avatar robinstern robinstern - test_item - 4 Aug 2020 - Tested unsuccessfully
avatar robinstern
robinstern - comment - 4 Aug 2020

I have tested this item 🔴 unsuccessfully on 21c0408

Tested unsuccessfully!

Exception doesn´t show up, when uploading file!


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/24894.

avatar HLeithner
HLeithner - comment - 27 Jun 2022

This pull request has automatically rebased to 4.2-dev.

avatar olleharstedt olleharstedt - change - 11 Jul 2022
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2022-07-11 12:50:44
Closed_By olleharstedt
Labels Added: ? ?
Removed: ?
avatar olleharstedt olleharstedt - close - 11 Jul 2022

Add a Comment

Login with GitHub to post a comment