Hi all,
I have just checked in a change that allows for more detailed error
reporting.
When a function fails you are now able to call mgd_errno() which reports
the reason for the failure, and mgd_errstr(reason) which gives an english
short description of the error code.
For the users:
mgd_errno clears the error after it's called, and only then. In order to
get a reliable value from mgd_errno, you have to either make sure that you
call mgd_errno after _every_ failed call, or do something like this:
mgd_errno();
$res = mgd_delete_host($whatever);
if ($res) { $error = mgd_errno(); }
The first call guarantees you're not seeing any old results. This is
important because mgd_errno holds the _first_ failure it meets while
processing a call and if errno is still set before doing a call it _will
not change_. The reason for this is that as a result of an earlier error
like MGD_ERR_NOT_OBJECT (calling a method on a value that's not an object)
may be caused by an earlier error of MGD_ERR_ACCESS_DENIED. The former
error is more useful to get the problem resolved, so that's what's
reported.
Do not rely on mgd_error to see if the call failed, unless you make sure
you clear it before. If cleared, and the call succeeds, the reported value
will remain the cleared value (=MGD_ERR_OK)
The possible values:
MGD_ERR_OK
MGD_ERR_ERROR Unspecified error. You shouldn't see these
MGD_ERR_ACCESS_DENIED Access denied
MGD_ERR_SITEGROUP_VIOLATION Resource link crosses sitegroup borders
MGD_ERR_NOT_OBJECT Object has no ID
MGD_ERR_NOT_EXISTS Object does not exists
MGD_ERR_NO_MEM Can't allocate memory
MGD_ERR_INVALID_NAME Object name has invalid characters
MGD_ERR_DUPLICATE Name exists
MGD_ERR_HAS_DEPENDANTS Resource has dependants
MGD_ERR_RANGE Date range error
MGD_ERR_INTERNAL Internal error. You shouldn't see these.
For the developers:
There's a perl script that generates the error codes. You put any new ones
you may need in the script itself, first the name of the error, then one
or more tabs, then the error message.
There are two new #defines, RETURN_FALSE_BECAUSE and RETVAL_FALSE_BECAUSE
which do exactly what their non-BECAUSE counterparts do accept a
errorcode which can be retrieved later.
I've changed everything I could find but you're very much welcome to
glance over the code to see if I picked the right error code for your
code. Also, there are a few spots where I used MGD_ERR_ERROR where I
couldn't think of the right code. I'd very much like to see these
replaced.
Emile
--
This is The Midgard Project's mailing list. For more information,
please visit the project's web site at http://www.midgard-project.org
To unsubscribe the list, send an empty email message to address
[EMAIL PROTECTED]