[CalendarServer-changes] [1505]
PyOpenDirectory/branches/users/cdaboo/better-errors-1318/src
source_changes at macosforge.org
source_changes at macosforge.org
Mon Apr 30 08:20:40 PDT 2007
Revision: 1505
http://trac.macosforge.org/projects/calendarserver/changeset/1505
Author: cdaboo at apple.com
Date: 2007-04-30 08:20:40 -0700 (Mon, 30 Apr 2007)
Log Message:
-----------
Add more information to the Python exception that gets raised so we can do some more detailed debugging.
Modified Paths:
--------------
PyOpenDirectory/branches/users/cdaboo/better-errors-1318/src/CDirectoryService.cpp
PyOpenDirectory/branches/users/cdaboo/better-errors-1318/src/CDirectoryService.h
Modified: PyOpenDirectory/branches/users/cdaboo/better-errors-1318/src/CDirectoryService.cpp
===================================================================
--- PyOpenDirectory/branches/users/cdaboo/better-errors-1318/src/CDirectoryService.cpp 2007-04-30 14:32:47 UTC (rev 1504)
+++ PyOpenDirectory/branches/users/cdaboo/better-errors-1318/src/CDirectoryService.cpp 2007-04-30 15:20:40 UTC (rev 1505)
@@ -31,8 +31,8 @@
extern PyObject* ODException_class;
-# define ThrowIfDSErr(x) { long dirStatus = x; if (dirStatus != eDSNoErr) throw dirStatus; }
-# define ThrowIfNULL(x) { if (x == NULL) throw -1L; }
+# define ThrowIfDSErr(x) { if (x != eDSNoErr) ThrowDSError(x, __FILE__, __LINE__); }
+# define ThrowIfNULL(x) { if (x == NULL) ThrowDSError(-1, __FILE__, __LINE__); }
// This is copied from WhitePages
#define kDSStdRecordTypeResources "dsRecTypeStandard:Resources"
@@ -96,9 +96,9 @@
// Get attribute map
return _ListAllRecordsWithAttributes(recordType, NULL, attributes);
}
- catch(long dserror)
+ catch(SDirectoryServiceException& dserror)
{
- PyErr_SetObject(ODException_class, Py_BuildValue("((s:i))", "DirectoryServices Error", dserror));
+ SetPythonException(dserror);
return NULL;
}
catch(...)
@@ -129,9 +129,9 @@
// Get attribute map
return _QueryRecordsWithAttributes(attr, value, matchType, NULL, casei, recordType, attributes);
}
- catch(long dserror)
+ catch(SDirectoryServiceException& dserror)
{
- PyErr_SetObject(ODException_class, Py_BuildValue("((s:i))", "DirectoryServices Error", dserror));
+ SetPythonException(dserror);
return NULL;
}
catch(...)
@@ -160,9 +160,9 @@
// Get attribute map
return _QueryRecordsWithAttributes(NULL, NULL, 0, query, casei, recordType, attributes);
}
- catch(long dserror)
+ catch(SDirectoryServiceException& dserror)
{
- PyErr_SetObject(ODException_class, Py_BuildValue("((s:i))", "DirectoryServices Error", dserror));
+ SetPythonException(dserror);
return NULL;
}
catch(...)
@@ -188,9 +188,9 @@
result = NativeAuthenticationBasic(guid, user, pswd);
return true;
}
- catch(long dserror)
+ catch(SDirectoryServiceException& dserror)
{
- PyErr_SetObject(ODException_class, Py_BuildValue("((s:i))", "DirectoryServices Error", dserror));
+ SetPythonException(dserror);
return false;
}
catch(...)
@@ -216,9 +216,9 @@
result = NativeAuthenticationDigest(guid, user, challenge, response, method);
return true;
}
- catch(long dserror)
+ catch(SDirectoryServiceException& dserror)
{
- PyErr_SetObject(ODException_class, Py_BuildValue("((s:i))", "DirectoryServices Error", dserror));
+ SetPythonException(dserror);
return false;
}
catch(...)
@@ -390,7 +390,7 @@
CloseNode();
CloseService();
}
- catch(long dsStatus)
+ catch(SDirectoryServiceException& dsStatus)
{
// Cleanup
if (context != NULL)
@@ -624,7 +624,7 @@
CloseNode();
CloseService();
}
- catch(long dsStatus)
+ catch(SDirectoryServiceException& dsStatus)
{
// Cleanup
if (context != NULL)
@@ -800,7 +800,7 @@
long aDataBufSize = sizeof(long) + ::strlen(user) + sizeof(long) + ::strlen(pswd);
authData = ::dsDataBufferAllocate(mDir, aDataBufSize);
if (authData == NULL)
- throw eDSNullDataBuff;
+ ThrowIfDSErr(eDSNullDataBuff);
long aCurLength = 0;
long aTempLength = ::strlen(user);
::memcpy(&(authData->fBufferData[aCurLength]), &aTempLength, sizeof(long));
@@ -926,7 +926,7 @@
sizeof(long) + ::strlen(method);
authData = ::dsDataBufferAllocate(mDir, aDataBufSize);
if (authData == NULL)
- throw eDSNullDataBuff;
+ ThrowIfDSErr(eDSNullDataBuff);
long aCurLength = 0;
long aTempLength = ::strlen(user);
::memcpy(&(authData->fBufferData[aCurLength]), &aTempLength, sizeof(long));
@@ -1009,7 +1009,7 @@
if (dirStatus != eDSNoErr)
{
mDir = 0L;
- throw dirStatus;
+ ThrowIfDSErr(dirStatus);
}
}
}
@@ -1065,7 +1065,7 @@
else
{
result = NULL;
- throw dirStatus;
+ ThrowIfDSErr(dirStatus);
}
dirStatus = ::dsDataListDeallocate(mDir, nodePath);
free(nodePath);
@@ -1110,7 +1110,7 @@
mData = ::dsDataBufferAllocate(mDir, cBufferSize);
if (mData == NULL)
{
- throw eDSNullDataBuff;
+ ThrowIfDSErr(eDSNullDataBuff);
}
mDataSize = cBufferSize;
}
@@ -1139,7 +1139,7 @@
mData = ::dsDataBufferAllocate(mDir, 2 * mDataSize);
if (mData == NULL)
{
- throw eDSNullDataBuff;
+ ThrowIfDSErr(eDSNullDataBuff);
}
mDataSize *= 2;
}
@@ -1184,3 +1184,19 @@
result[len] = 0;
return result;
}
+
+void CDirectoryService::ThrowDSError(long error, const char* file, long line)
+{
+ CDirectoryService::SDirectoryServiceException dirStatus;
+ dirStatus.mDSError = error;
+ ::snprintf(dirStatus.mDescription, 1024, "Exception raised in file %s at line %ld", file, line);
+ throw dirStatus;
+}
+
+void CDirectoryService::SetPythonException(const SDirectoryServiceException& ex)
+{
+ char error[1024];
+ ::snprintf(error, 1024, "%s %s", "DirectoryServices Error:", ex.mDescription);
+ PyErr_SetObject(ODException_class, Py_BuildValue("((s:i))", error, ex.mDSError));
+}
+
Modified: PyOpenDirectory/branches/users/cdaboo/better-errors-1318/src/CDirectoryService.h
===================================================================
--- PyOpenDirectory/branches/users/cdaboo/better-errors-1318/src/CDirectoryService.h 2007-04-30 14:32:47 UTC (rev 1504)
+++ PyOpenDirectory/branches/users/cdaboo/better-errors-1318/src/CDirectoryService.h 2007-04-30 15:20:40 UTC (rev 1505)
@@ -40,6 +40,13 @@
bool AuthenticateUserDigest(const char* guid, const char* user, const char* challenge, const char* response, const char* method, bool& result);
private:
+
+ struct SDirectoryServiceException
+ {
+ long mDSError;
+ char mDescription[1024];
+ };
+
const char* mNodeName;
tDirReference mDir;
tDirNodeReference mNode;
@@ -70,4 +77,7 @@
char* CStringFromBuffer(tDataBufferPtr data);
char* CStringFromData(const char* data, size_t len);
+
+ void ThrowDSError(long error, const char* file, long line);
+ void SetPythonException(const SDirectoryServiceException& ex);
};
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070430/1f35ad4d/attachment.html
More information about the calendarserver-changes
mailing list