Jump to content

Hook compile errors are discarded silently even in dev


Recommended Posts

Currently, if a hook has a compile error, such as not reflecting the parameters of the method that it overrides (particularly an issue with the backwards-incompatible changes in 4.2), the error is discarded silently, even when IN_DEV. This obviously isn't ideal. Can we kill two birds with one stone and get better exceptions for hooks too, by replacing the monkey patch code with

					$contents = "namespace {$namespace}; ". str_replace( '_HOOK_CLASS_', $realClass, file_get_contents( ROOT_PATH . '/' . $data['file'] ) );
					if (\IPS\IN_DEV) {
						$filename = tempnam(\IPS\TEMP_DIRECTORY, "HOOK_{$namespace}\\{$finalClass}_{$data['file']}");
						$fullContents = "<?php " . $contents;
						\file_put_contents($filename, $fullContents);
						
						register_shutdown_function( function( $temp ) {
							unlink( $temp );
						}, $filename );
						
						require $filename;
						
						$realClass = $data['class'];
					} else {
						try
						{
							if( @eval( $contents ) !== FALSE )
							{
								$realClass = $data['class'];
							}
						} catch ( \ParseError $e ) { }
					}

I have tested this code and not encountered any issues (though on windows there might be a problem with the use of \, in which case maybe a replace to - or _ is needed).

Link to comment
Share on other sites

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...