Moodle dies if there is an error in plugin...

Moodle dies if there is an error in plugin...

by Peter Eliyahu Kornfeld -
Number of replies: 3
Picture of Core developers Picture of Plugin developers

Hello,

I have developed a new plugin, that worked fine... To extend I added some functionality to access tags, for that I added this line:

require_once (__DIR__ . '../../../tag/clasess/tag.php');

As you can see I have a typo there... It is obvious that I can fix the code, but what I was wondering about is... What if that code was released to the wild and installed by some innocent user, with no access to the server (via UI)...

In my case moodle keeps displaying a fatal error, that prevents ANY action via the UI...

Fatal error: require_once(): Failed opening required '/var/www/sites/moodle-server.openapp.co.il/iaa/local/ws_rashim../../../tag/clasess/tag.php' (include_path='/var/www/sites/moodle-server.openapp.co.il/iaa/lib/zend:/var/www/sites/moodle-server.openapp.co.il/iaa/lib/pear:.:/usr/share/pear:/usr/share/php') in /var/www/sites/moodle-server.openapp.co.il/iaa/local/ws_rashim/locallib.php on line 7

There is any way to fix it without access to the server?


Regards

Peter

Average of ratings: -
In reply to Peter Eliyahu Kornfeld

Re: Moodle dies if there is an error in plugin...

by Matteo Scaramuccia -

Hi Peter,
unfortunately no; that's the reason why:

  • people using 3rd party plug-ins should test each (new version of a) plug-in in a separate environment, closest to their production settings and data (ideally, a clone being kept aligned)
  • developers should start using a CI environment like Travis to test their plug-in, at least the installation stage: https://docs.moodle.org/dev/Travis_integration. Then, apply the (new version of the) plug-in release to the Moodle Plug-ins Directory

HTH,
Matteo

Average of ratings: Useful (1)
In reply to Matteo Scaramuccia

Re: Moodle dies if there is an error in plugin...

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

And to add (the slightly obvious) to Matteo's comments, developers should add plenty of phpunit tests. In fact that might be something to add to a checklist of should is this a good plugin checkboxery, i.e. does it have plenty of Unit tests. It is not just about testing, it is about documenting. Tests document the expected behaviour.

In reply to Marcus Green

Re: Moodle dies if there is an error in plugin...

by Matteo Scaramuccia -

That's true big grin!

And Moodle Testing framework is quite nice and best integrated w/ Travis even for plug-ins thanks to moodle-plugin-ci, especially the "integration" tests via Behat Yes.

HTH,
Matteo