PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Web Services » XML_RPC » Bug #4831

XML_RPC doesn't propagate PEAR errors

Details

Request #4831XML_RPC doesn't propagate PEAR errors
Submitted2005-07-14 01:23 UTC
Frombrion at pobox dot com
Assigneddanielc
StatusWont fix
PackageXML_RPC
PHP Version4.3.11
OSMac OS X
Roadmaps(Not assigned)

Comments

[2005-07-14 01:23 UTC] brion at pobox dot com

Description:
------------
In various places the XML_RPC client uses PEAR::raiseError(),
but then returns 0 from the function:

$this->raiseError('Connection to RPC server '
. $server . ':' . $port
. ' failed. ' . $this->errstr,
XML_RPC_ERROR_CONNECTION_FAILED);
return 0;

Since the PEAR_error value isn't propagated back to the
caller, it's difficult to diagnose errors without setting
PEAR's error handling into a more painful mode.

The caller can tell _something_ went wrong if he gets 0, but
not what.

Reproduce code:
---------------
require_once 'PEAR.php';
require_once 'XML/RPC.php';

$client = new XML_RPC_Client('/rpc', 'localhost');
$message = new XML_RPC_Message('method', array());
$result = $client->send($message);

if (PEAR::isError($result)) {
print $result->getMessage();
print "\nTrying secondary server...";
} elseif ($result->faultCode()) {
print $result->faultString();
} else {
$value = $result->value();
print $value->getval();
}

Expected result:
----------------
xml_rpc_client: Connection to RPC server localhost:80 failed.
Connection refused
Trying secondary server...

Actual result:
--------------
Fatal error: Call to a member function on a non-object in /
Users/brion/Documents/xml-foo.php on line 11

[2005-07-14 02:47 UTC] brion at pobox dot com

The problem I have with $result->errstr is that it contains
no contextual information, making it hard to localize the
problem. I was getting "Invalid argument", without any clue
as to _what_ might be invalid, or where the error might be
getting reported from.

Searching for the error string in the source didn't help
since as it turns out it comes from lower level code.

Once I figured out how to get the PEAR_error printed out:
"xml_rpc_client: Connection to RPC server scecore.usc.edu:80
failed. Invalid argument" I could tell where in the process
it was failing (at socket open), and could see pretty easily
what was wrong (I misspelled the server name).

Just a little bit of context goes a long way, but that
context isn't there in $errstr. If it included some context
like a function name, that would be almost as good though.

[2005-08-04 11:16 UTC] markus at fischer dot name

And if a new package, XML_RPC2, is created which follows the PEAR standard more closer by breaking BC? So no one is getting an incompatible XML_RPC update.