When we try to run code written with errors, we get error(s). Error(s) not handled, the submit is interrupted and every time you need to go back to correct the error and execute the code again.

It would be nice to handle errors without aborting the submit and display them as messages.
Examples of errors attached.

Comments

david.pashaev created an issue. See original summary.

davps’s picture

Assigned: davps » Unassigned
Status: Active » Needs review
StatusFileSize
new26.91 KB
new24.82 KB
new60.19 KB
new966 bytes

This patch and attached images show how it works.

willzyx’s picture

Status: Needs review » Needs work

@thanks for contributing! This could be an useful feature. A quick review:

  1. +++ b/src/Form/ExecutePHP.php
    @@ -4,6 +4,8 @@ namespace Drupal\devel\Form;
    +use ParseError;
    +use Error;
    

    I think that the coding standard for using this class is use FQNS (\ParseError, \Error - without using the use statement)

  2. +++ b/src/Form/ExecutePHP.php
    @@ -45,11 +47,20 @@ class ExecutePHP extends FormBase {
    +    catch (ParseError $error) {}
    +    catch (Error $error) {}
    +
    +    if (isset($error)) {
    +      drupal_set_message($error->getMessage(), 'error');
    +    }
    

    there is a reason for catching the two error separately? looking at the Error hierarchy ParseError extends Error.. so probably we can simply write the code like :

    } 
    catch (\Error $error) {
      drupal_set_message($error->getMessage(), 'error');
    }

    I'm missing something?

and probably we need to write a little test for this :)

davps’s picture

Assigned: Unassigned » davps
moshe weitzman’s picture

Status: Needs work » Closed (won't fix)
geek-merlin’s picture

Project: Devel » Devel PHP
Component: devel » Code
Status: Closed (won't fix) » Needs work
davps’s picture

Assigned: davps » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.25 KB

Patch updated.
Added few tests.

  • lussoluca committed 51d6695 on 8.x-1.x authored by davps
    Issue #2883632 by davps: Handle errors when PHP code executes
    
lussoluca’s picture

Status: Needs review » Fixed

Committed and pushed to 8.x-1.x
Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.