PHP - One last call - cron

Is there a way to tell PHP to run one last function, or somehow override some error handler in the event of a fatal error? I have a cron that has a main entry point of:
$obj = new obj();
$obj->run();
exit;
Would wrapping that in a try catch do the trick if I'm not explicitly throwing errors? All I want is for PHP to do something as simple as create a txt file containing the fatal error, or even just create an empty file named 'failed.txt', or something.
Thanks!

error_handler might help you here
Or this for fatal errors: http://insomanic.me.uk/post/229851073/php-trick-catching-fatal-errors-e-error-with-a

You write it's cron. Call the script with a path to a new php.ini file wherein you make PHP to log the errors to STDERR or STDOUT.
php -h
will give you all commandline options.
Cron will send you the reports then if something failed by email.
Alternatively you can set this up to log into your own log as it's a new php.ini. In case that's easier for you to review.

You can set a custom error handler for most errors, and execute some code there.
But cannot handle an E_ERROR which is what your fatal error is likely to be.
Imagine if that error was for running out of memory. You try to handle that error, and end up using more memory. Which just throws another error, and you're right where you started.

Use register_shutdown_function() to register a function to execute as the last call. This will get call whether there was an error or not.
See http://php.net/manual/function.register-shutdown-function.php for more information.

You can do custom error handling in PHP. Check the manual at: http://php.net/function.set-error-handler. This is a fairly straightforward application of that.

Use
try
{
//Code
}
catch(Exception $e)
{
//Execute on error
}

Related

How can I solve error of unexpected } in php

When I was running a process in ProcessMaker, I got error message "Fatal error in trigger", then I checked the error logs and found this
PHP Parse error: syntax error, unexpected '}' in /opt/processmaker/workflow/engine/classes/class.pmScript.php(216) : eval()'d code on line 9.
Could anyone tell me please what should I do?
Thank you so much for your help.
Here's the code :
public function executeAndCatchErrors($sScript, $sCode)
{
ob_start('handleFatalErrors');
set_error_handler('handleErrors');
$_SESSION['_CODE_'] = $sCode;
eval($sScript );
$this->evaluateVariable();
unset( $_SESSION['_CODE_'] );
ob_end_flush();
}
ProcessMaker supports Triggers, where you can embed PHP code directly into a workflow process.
The code you have pasted is actually part of the ProcessMaker source code, which evaluates the triggers during the execution of a workflow process.
It appears though there is a PHP syntax error in a trigger rather than the source code itself.
In order to fix this issue, I would look at the process triggers and check for PHP syntax errors. I would also try and run through the process and see at what point you get the error and then check the triggers that are defined around the task that caused the error.
For more information on triggers, see:
https://wiki.processmaker.com/3.0/Triggers

node option: making it quite when an error is thrown

is there a node cli option that lets it not print an error?
For example, I'd like the command below not to print an uncaught exception, even if it occurs. But I don't simply want to catch it in the code. If there's no exception or error, then it should print (if message to print exists) what it's intended to.
$ node --quiet-on-err(?) this-script-throws-err.js
Thanks,
This is a good use case for redirection (assuming you're using a platform that has /dev/null): node this-script-throws-err.js 2/>dev/null.
Wouldn't catching all uncaught exception work for you? Add this to the code. This is a process wide event handler that gets called whenever an uncaught exception is found.
process.on('uncaughtException', (exception) => {
// handle or ignore error
});

Netsuite: ReferenceError functionName is not defined

This is probably a stupid one but I have tried all the things I can think of. I am currently getting the below error on my client side script when I try and execute it.
Error: ReferenceError acvt_serialNumber_saveRecord is not defined
On the Script record in Netsuite I have set the saveRecord function as follows:
acvt_serialNumber_saveRecord
The code in the file is:
function acvt_serialNumber_saveRecord(){
/**do stuff */
}
I have reuploaded to code to make sure the right version was in NetSuite. I have added one character to both the script fn name and the fn name on the Script record (as a shot in the dark). I have seen in the Javascript console at runtime that the correct code is in there and I can see the exact function name (I did a ctrl+f for the "undefined" function in the code in the console to make sure spelling was all the same).
NOTHING has worked. I had this code working earlier, but the changes I made were not to this function at all.
Any help is appreciated
Another thing to check is the code that you recently changed. In particular, check for a hanging comma. IE:
var someObj = {
someProp:'somevalue',
};
The comma at the end of 'somevalue' will cause the script to fail, throwing 'undefined' errors.
Have you tried deleting the Script record in NetSuite and re-creating it?
Do you have any library included for that Client Script in netsuite ?
Provide a screen shot of your Netsuite script page
I encounter similar problem like this before, but it was because i called a function which is inside a library file
Thanks

node.js debugging with source line numbers

Similar questions has been asked, I went through 'how to debug node' threads, but
those are however either old or not about the problem i got.
Problem:
I'm writing some small tools in node.js stack - and my debugging experience is quite frustrating: when an exception is thrown, in many cases I get very annoying messages like the one here:
TypeError: Bad argument
wtf? it's neither verbose or useful - no source line number, no information in which file this exception was thrown.
Question:
How do I get my console to output usefull information when exceptions/errors are thrown and console.log function has something to say. would be great to have a simple console.log call where it actually puts a line number and maybe a file name where the message happens.
in nodejs i use this function to see error stack:
process.on('uncaughtException', function(err) {
console.log(err.stack);
})
Use the --stack option to see stack traces. Such as grunt task --stack

How do I write log messages in Kohana 3.2?

Ok I've tried searching all over but can't seem to get just a simple straight forward answer.
I want to write log messages (INFO, ERROR, etc.) to the Kohana log file /application/logs/YYYY/MM/DD.php.
How do I do it?
Try the log class add() method: http://kohanaframework.org/3.2/guide/api/Log#add
Call it like this:
Log::instance()->add(Log::NOTICE, 'My Logged Message Here');
For the first parameter (level) use one of the 9 constants defined in the log class
Shuadoc you shouldn't touch system files (all those under system folder).
Change the value in bootstrap.php instead as stated by Ygam
Otherwise, when updates come you'll be in trouble.

Resources