Now that we're PHP5+ we've got exceptions we can finally remove all the variations on drupal_set_message('foo', 'error'); return FALSE; from file.inc and just throw an exception back to the caller and the caller can either act on them or report them to the user.

The exceptions seem to need to end up two places, on the form via form_set_error() and logs via watchdog(). watchdog() wants the untranslated string and arguments and form_set_error() needs a form element to blame so I added a DrupalException class that can handle this bit.

This needs a bit of work still. I haven't updated any of the calling code to test it out I just wanted to get this up here so I could get some feedback.

Comments

drewish’s picture

StatusFileSize
new11.22 KB

fixed a couple of obvious bugs.

drewish’s picture

Issue tags: +D7FileAPIWishlist
jhedstrom’s picture

The new field api is also defining it's own Exception class, which directly extends the php Exception class. That should probably be changed to extend the DrupalException class defined in this patch.

kwinters’s picture

Title: Use exceptions to report file.inc failues » Use exceptions to report file.inc failures

#522746: Drupal Exception Wrapper Class is dedicated towards getting better exception handling in core. Once that is fixed, it will just need to be integrated into these modules (if not done already in the other issue).

kwinters’s picture

Version: 7.x-dev » 8.x-dev
jhedstrom’s picture

Issue summary: View changes
Status: Needs work » Active

This is still relevant, I see at least one occurrence of // @todo Replace drupal_set_message() calls with exceptions instead.

jhedstrom’s picture

Status: Active » Needs work
Issue tags: +Needs reroll

'Needs reroll' is a bit of an understatement here.

siva_epari’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new0 bytes

drupal_set_message replaced as per comment #6

siva_epari’s picture

StatusFileSize
new1.44 KB

Sorry. uploaded empty patch file

siva_epari’s picture

StatusFileSize
new1.24 KB

Had added redundant exceptions. Removed it.

The last submitted patch, 9: use_exceptions_to-348993-9.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 10: use_exceptions_to-348993-10.patch, failed testing.

siva_epari’s picture

Status: Needs work » Needs review
StatusFileSize
new1.24 KB

Added t() to the exception.

Status: Needs review » Needs work

The last submitted patch, 13: use_exceptions_to-348993-13.patch, failed testing.

jhedstrom’s picture

I think the failures here are due to these new exceptions not being properly caught.

siva_epari’s picture

Status: Needs work » Needs review
StatusFileSize
new1.77 KB
new3.01 KB

Exceptions are caught now. Also fixed a typo in core/modules/system/src/Tests/File/UnmanagedCopyTest.php s/doesn't exists./doesn't exist./

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

20th’s picture