Repository: easybuilders/easybuild-easyblocks

Issue:
MATLAB easyblock doesn't handle errors during install
The matlab installer script always returns 0, even if it fails due to, e.g. specifying the wrong key. 
There is no way to view the reason why, because the installer doesn't output anything to stdout. I had to run the install command myself with a modified with a outputFile specified, which contained the actual errors.

We should minimum just specify the outputFile argument so that the error logs appear *somewhere*, and possibly check for any errors inside this file. 


Discussion:
This is part of the reason we have a sanity check step, I remember hitting this several times in the distant past, only to discover later nothing was installed at all...

Resolving patch:
diff --git a/easybuild/easyblocks/m/matlab.py b/easybuild/easyblocks/m/matlab.py
--- a/easybuild/easyblocks/m/matlab.py
+++ b/easybuild/easyblocks/m/matlab.py
@@ -55,6 +55,7 @@ def __init__(self, *args, **kwargs):
         super(EB_MATLAB, self).__init__(*args, **kwargs)
         self.comp_fam = None
         self.configfile = os.path.join(self.builddir, 'my_installer_input.txt')
+        self.outputfile = os.path.join(self.builddir, 'my_installer_output.txt')
 
     @staticmethod
     def extra_options():
@@ -98,12 +99,14 @@ def configure_step(self):
             regagree = re.compile(br"^# agreeToLicense=.*", re.M)
             regmode = re.compile(br"^# mode=.*", re.M)
             reglicpath = re.compile(br"^# licensePath=.*", re.M)
+            regoutfile = re.compile(br"^# outputFile=.*", re.M)
 
             # must use byte-strings here when using Python 3, see above
             config = regdest.sub(b"destinationFolder=%s" % self.installdir.encode('utf-8'), config)
             config = regagree.sub(b"agreeToLicense=Yes", config)
             config = regmode.sub(b"mode=silent", config)
             config = reglicpath.sub(b"licensePath=%s" % licfile.encode('utf-8'), config)
+            config = regoutfile.sub(b"outputFile=%s" % self.outputfile.encode('utf-8'), config)
 
             write_file(self.configfile, config)
 
@@ -188,6 +191,12 @@ def install_step(self):
             # check installer output for known signs of trouble
             patterns = [
                 "Error: You have entered an invalid File Installation Key",
+                "Not a valid key",
+                "All selected products are already installed",
+                "The application encountered an unexpected error and needs to close",
+                "Error: Unable to write to",
+                "Exiting with status -\\d",
+                "End - Unsuccessful",
             ]
 
             for pattern in patterns:
@@ -195,6 +204,10 @@ def install_step(self):
                 if regex.search(out):
                     raise EasyBuildError("Found error pattern '%s' in output of installation command '%s': %s",
                                          regex.pattern, cmd, out)
+                with open(self.outputfile) as f:
+                    if regex.search(f.read()):
+                        raise EasyBuildError("Found error pattern '%s' in output file of installer",
+                                             regex.pattern)
 
     def sanity_check_step(self):
         """Custom sanity check for MATLAB."""


Test patch: