I am trying to recover the last (fatal) error message through these functions:
$last_error = error_get_last();
echo $last_error['message'];
Using the exception:
throw new Exception("Error n.1");
I would expect to get this string "Error n.1", but I get something like this (which depends on the PHP version):
Uncaught Exception: Error n.1 in C:\wamp\www\JUICE\projects\JATE\dist\jate\functions\errorHandler.php:66 Stack trace: #0 C:\wamp\www\JUICE\projects\JATE\dist\jate\functions\requirer.php(37): require_once() #1 C:\wamp\www\JUICE\projects\JATE\dist\jate\functions\requirer.php(5): jRequire('C:\\wamp\\www\\JUI...', false, 0) #2 C:\wamp\www\JUICE\projects\JATE\dist\jate\functions\requirer.php(15): requireComponent('C:\\wamp\\www\\JUI...', false) #3 C:\wamp\www\JUICE\projects\JATE\dist\jate\coreEngine.php(10): requireComponents('functions') #4 C:\wamp\www\JUICE\projects\JATE\examples\01essential\jate.php(15): require_once('C:\\wamp\\www\\JUI...') #5 C:\wamp\www\JUICE\projects\JATE\examples\01essential\index.php(2): require_once('C:\\wamp\\www\\JUI...') #6 {main} thrown
How can I get the error string and not all the things added by the system?
Your expectation is wrong. Throwing an exception doesn't cause an error by itself, so that's not what is shown in $last_error. Failing to catch an exception causes an error, but the message for that error is Uncaught Exception followed by the details of the exception, not just the exception string.
Since the specific format of that message is version-dependent, the best you can do is search it for the exception string in it:
if (preg_match('/Error n\.1/', $last_error['message']) {
echo "Error n.1";
}
Related
WPForms Lite has caused a fatal error on my WordPress page, and I struggle with figuring out what the problem is and how to fix it.
Error Details:
An error of type E_ERROR was caused in line 106 of the file /home/pagename/public_html/wp-content/plugins/wpforms-lite/src/Helpers/Templates.php. Error message: Uncaught RuntimeException: Extraction failed: variable names are clashing with the existing ones. in /home/pagename/public_html/wp-content/plugins/wpforms-lite/src/Helpers/Templates.php:106
It seems like the function is supposed to include a template, and the error exists to "protect the scope from modification".
Stack trace:
#0 /home/pagename/public_html/wp-content/plugins/wpforms-lite/src/Helpers/Templates.php(127): WPForms\Helpers\Templates::include_html('education/admin...', Array, true)
#1 /home/pagename/public_html/wp-content/plugins/wpforms-lite/includes/functions.php(2402): WPForms\Helpers\Templates::get_html('education/admin...', Array, true)
#2 /home/pagename/public_html/wp-content/plugins/wpforms-lite/src/Lite/Admin/Education/Admin/NoticeBar.php(69): wpforms_render('education/admin...', Array, true)
#3 /home/pagename/public_html/wp-includes/class-wp-hook.php(303): WPForms\Lite\Admin\Education\Admin\NoticeBar->display('')
#4 /home/pagename/public_html/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters('', Array)
#5 /home/vpagename/public_html/wp-includes/plugin.php(470): WP_Hook->do_action(Arra
I downloaded and installed neo4j-php-client and neo4j 2.3.2. Actually all works fine, but I just wondering why there is no error handlers in this php client? For example if there is an error in cypher query, no error has throwing to be easy to catch it. I searching through the network, but I can't found a solution.
Do anybody have an idea how to turn on error handlers?
Thanks in advance.
I'm the maintainer of neo4j-php-client.
When you send a query to Neo4j, it is actually sent via Guzzle.
Of course there is a try/catch block for handling exceptions, which is located here :
https://github.com/graphaware/neo4j-php-client/blob/master/src/HttpClient/GuzzleHttpClient.php#L76
If there is an error in your cypher query, an exception will be thrown of course, the exception is of type Neo4jException (https://github.com/graphaware/neo4j-php-client/blob/master/src/Exception/Neo4jException.php)
Here is a simple code with a cypher syntax error and you can see an exception is thrown :
<?php
require_once __DIR__ .'/vendor/autoload.php';
use Neoxygen\NeoClient\ClientBuilder;
$client = ClientBuilder::create()
->addConnection('default', 'http', 'localhost', 7474)
->setAutoFormatResponse(true)
->build();
$query = 'MATCH (n) RETURN x';
$result = $client->sendCypherQuery($query)->getResult();
-
ikwattro#graphaware ~/d/g/p/neo4j-php-client> php test.php
PHP Fatal error: Uncaught Neoxygen\NeoClient\Exception\Neo4jException: Neo4j Exception with code "Neo.ClientError.Statement.InvalidSyntax" and message "Variable `x` not defined (line 1, column 18 (offset: 17))
"MATCH (n) RETURN x"
^" in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php:117
Stack trace:
#0 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php(104): Neoxygen\NeoClient\Extension\AbstractExtension->checkResponseErrors(Array)
#1 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/NeoClientCoreExtension.php(98): Neoxygen\NeoClient\Extension\AbstractExtension->handleHttpResponse(Object(Neoxygen\NeoClient\Request\Response))
#2 [internal function]: Neoxygen\NeoClient\Extension\NeoClientCoreExtension->sendCypherQuery('MATCH (n) RETUR...')
#3 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/ExtensionManager.php(53): call_user_func_array(Array, Array)
#4 /Users/ikwattro/dev/graphaware/php/neo4j-php-cli in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php on line 117
Fatal error: Uncaught Neoxygen\NeoClient\Exception\Neo4jException: Neo4j Exception with code "Neo.ClientError.Statement.InvalidSyntax" and message "Variable `x` not defined (line 1, column 18 (offset: 17))
"MATCH (n) RETURN x"
^" in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php:117
Stack trace:
#0 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php(104): Neoxygen\NeoClient\Extension\AbstractExtension->checkResponseErrors(Array)
#1 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/NeoClientCoreExtension.php(98): Neoxygen\NeoClient\Extension\AbstractExtension->handleHttpResponse(Object(Neoxygen\NeoClient\Request\Response))
#2 [internal function]: Neoxygen\NeoClient\Extension\NeoClientCoreExtension->sendCypherQuery('MATCH (n) RETUR...')
#3 /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/ExtensionManager.php(53): call_user_func_array(Array, Array)
#4 /Users/ikwattro/dev/graphaware/php/neo4j-php-cli in /Users/ikwattro/dev/graphaware/php/neo4j-php-client/src/Extension/AbstractExtension.php on line 117
Thanks for the answer. The problem is seems on my end, I figured out after few tests - Error hanldering overwrites by the php framework.
Problem
My PHP Stack Trace is abbreviated:
Stack trace:
#0 /www/html/table/app/create.php(128): SoapClient->__call('call', Array)
#1 /www/html/table/app/create.php(128): SoapClient->call('5e81ad4c12668ec...', 'table.ad...', Array)
Expected Outcome
I want to see the part that is hidden by the ... when running php from the command line. How do I make php show the full message?
You can surround it in a try ... catch and then do a var_dump on the exception.
try {
// the code that throws an exception
} catch ( Exception $e ) {
var_dump( $e->getTrace() );
}
I'm using Google App Engine in combination with PHP.
After a couple request I get the following error
Fatal error: Uncaught exception 'google\net\ProtocolBufferEncodeError' with message 'Internal bug: Encoded size doesn't match predicted' in /base/data/home/runtimes/php/sdk/google/appengine/runtime/proto/ProtocolMessage.php:68
Stack trace:
#0 /base/data/home/runtimes/php/sdk/google/appengine/runtime/proto/ProtocolMessage.php(50): google\net\ProtocolMessage->serializePartialToString()
#1 /base/data/home/runtimes/php/sdk/google/appengine/runtime/RealApiProxy.php(52): google\net\ProtocolMessage->serializeToString()
#2 /base/data/home/runtimes/php/sdk/google/appengine/runtime/ApiProxy.php(42): google\appengine\runtime\RealApiProxy->makeSyncCall('taskqueue', 'BulkAdd', Object(google\appengine\TaskQueueBulkAddRequest), Object(google\appengine\TaskQueueBulkAddResponse), NULL)
#3 /base/data/home/runtimes/php/sdk/google/appengine/api/taskqueue/PushQueue.php(195): google\appengine\runtime\ApiProxy::makeSyncCall('taskqueue', 'BulkAdd', Object(google\appengine\TaskQueueBulkAddRequest), Object(google\appengine\TaskQueueBulkAddResponse in /base/data/home/runtimes/php/sdk/google/appengine/runtime/proto/ProtocolMessage.php on line 68
Fatal error: Uncaught exception 'google\net\ProtocolBufferEncodeError' with message 'Internal bug: Encoded size doesn't match predicted' in /base/data/home/runtimes/php/sdk/google/appengine/runtime/proto/ProtocolMessage.php:68
Stack trace:
#0 /base/data/home/runtimes/php/sdk/google/appengine/runtime/proto/ProtocolMessage.php(50): google\net\ProtocolMessage->serializePartialToString()
#1 /base/data/home/runtimes/php/sdk/google/appengine/runtime/RealApiProxy.php(52): google\net\ProtocolMessage->serializeToString()
#2 /base/data/home/runtimes/php/sdk/google/appengine/runtime/ApiProxy.php(42): google\appengine\runtime\RealApiProxy->makeSyncCall('taskqueue', 'BulkAdd', Object(google\appengine\TaskQueueBulkAddRequest), Object(google\appengine\TaskQueueBulkAddResponse), NULL)
#3 /base/data/home/runtimes/php/sdk/google/appengine/api/taskqueue/PushQueue.php(195): google\appengine\runtime\ApiProxy::makeSyncCall('taskqueue', 'BulkAdd', Object(google\appengine\TaskQueueBulkAddRequest), Object(google\appengine\TaskQueueBulkAddResponse in /base/data/home/runtimes/php/sdk/google/appengine/runtime/proto/ProtocolMessage.php on line 68
To solve this I shutdown all the instances and the code just loads normally. And again after a couple of request I get the same fatal error.
What can cause this Fatal error ? And how do I solve it.
The error is raised in the following file
https://chromium.googlesource.com/external/googleappengine/python/+/4523f63814037ed833b8bb55273c09a43dd69fb0/php/sdk/google/appengine/runtime/proto/ProtocolMessage.php
So I have a XMLRPC developed in Zend PHP which calls a SOAP request to start another process (SOAP is not my script but the XMLRPC is).
During the SOAP request if the host is not found, this sometimes crashes my XMLRPC call.
How can I return the XMLRPC request with a response instead of an error? Does the logic look ok? I know all the functionality works and I have gotten the response I desire (sometimes) but I need to make sure the script doesn't crash. Any thoughts? tips?
Here is what I have
try {
$soap_call = new ReportSoapClient();
$soap_call->RunReport();
} catch(Exception $e) {
// Set the Error Alert Email Message
$this->setErrorAlertMessage($this->getErrorAlertMessage()."ERROR: SOAP Exception: ".$e->getMessage());
// Send the Email
$this->sendErrorAlertEmail();
// This set the XMLRPC Response
$this->setXMLRPCResponse('Code: '.$e->getCode().' Message: '.$e->getMessage());
// This is a logger
$this->debug('Code: '.$e->getCode().' Message: '.$e->getMessage());
// Return the XMLRPC Response
return $this->getXMLRPCResponse();
}
Here is the email I get:
ERROR: SOAP Exception: Could not connect to host
Here is the error I get when crashing (happens only sometimes, why???):
Fatal error: Uncaught exception 'Zend_Http_Client_Adapter_Exception' with message 'Read timed out after 10 seconds' in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php:512
Stack trace:
#0 /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php(330): Zend_Http_Client_Adapter_Socket->_checkSocketReadTimeout()
#1 /usr/share/php/libzend-framework-php/Zend/Http/Client.php(989): Zend_Http_Client_Adapter_Socket->read()
#2 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(280): Zend_Http_Client->request('POST')
#3 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(361): Zend_XmlRpc_Client->doRequest(Object(Zend_XmlRpc_Request))
#4 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client/ServerProxy.php(93): Zend_XmlRpc_Client->call('system.multical...', Array)
#5 [internal function]: Zend_XmlRpc_Client_ServerProxy->__call('multicall', Array)
#6 /path/to/xmlrpc.client.php(70): Zend_XmlRpc_Client_ServerProxy->multicall(Array)
#7 {main}
thrown in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php on line 512
I increased the timeout to 30 seconds (<-- Link: if you need to see how) and then I sometimes get this: (again why???):
Fatal error: Uncaught exception 'Zend_Http_Client_Adapter_Exception' with message 'Read timed out after 30 seconds' in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php:512
Stack trace:
#0 /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php(330): Zend_Http_Client_Adapter_Socket->_checkSocketReadTimeout()
#1 /usr/share/php/libzend-framework-php/Zend/Http/Client.php(989): Zend_Http_Client_Adapter_Socket->read()
#2 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(280): Zend_Http_Client->request('POST')
#3 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client.php(361): Zend_XmlRpc_Client->doRequest(Object(Zend_XmlRpc_Request))
#4 /usr/share/php/libzend-framework-php/Zend/XmlRpc/Client/ServerProxy.php(93): Zend_XmlRpc_Client->call('system.multical...', Array)
#5 [internal function]: Zend_XmlRpc_Client_ServerProxy->__call('multicall', Array)
#6 /path/to/xmlrpc.client.php(23): Zend_XmlRpc_Client_ServerProxy->multicall(Array)
#7 in /usr/share/php/libzend-framework-php/Zend/Http/Client/Adapter/Socket.php on line 512
Here is what comes back sometimes (this is the desired response):
Code: 0 Message: Could not connect to host
it was the SOAP process erroring out and wasn't throwing the error properly. ugh