code restructing: Exception, throwError()

Raising exceptions via throwError() looses the original source code
location information. Fixing that by explicitly passing that
information as additional parameter, created with the preprocessor
macro SE_HERE.

Several files included the complex SyncContext.h only because needed
throwError(). A better place for the revised implementation is the
Exception class which used to be in util.h, now Exception.h.

Simplifying the include statements exposed indirect include
dependencies and removed "using namespace std" from the compilation of
some source files which happened to rely on it. We want to get rid of
that name space polution, so fix the code instead of adding it back.
This commit is contained in:
Patrick Ohly 2014-04-02 14:57:56 +02:00
parent 7812dc126f
commit de8461f802
54 changed files with 776 additions and 708 deletions

View file

@ -132,7 +132,7 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std
continue;
}
gerror.throwError("reading ActiveSync changes");
gerror.throwError(SE_HERE, "reading ActiveSync changes");
}
GStringPtr bufferOwner(buffer, "reading changes: empty sync key returned");
@ -144,15 +144,15 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std
// populate ID lists and content cache
BOOST_FOREACH(EasItemInfo *item, created) {
if (!item->server_id) {
throwError("no server ID for new eas item");
throwError(SE_HERE, "no server ID for new eas item");
}
string easid(item->server_id);
if (easid.empty()) {
throwError("empty server ID for new eas item");
throwError(SE_HERE, "empty server ID for new eas item");
}
SE_LOG_DEBUG(getDisplayName(), "new eas item %s", easid.c_str());
if (!item->data) {
throwError(StringPrintf("no body returned for new eas item %s", easid.c_str()));
throwError(SE_HERE, StringPrintf("no body returned for new eas item %s", easid.c_str()));
}
Event &event = setItemData(easid, item->data);
BOOST_FOREACH(const std::string &subid, event.m_subids) {
@ -163,15 +163,15 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std
}
BOOST_FOREACH(EasItemInfo *item, updated) {
if (!item->server_id) {
throwError("no server ID for updated eas item");
throwError(SE_HERE, "no server ID for updated eas item");
}
string easid(item->server_id);
if (easid.empty()) {
throwError("empty server ID for updated eas item");
throwError(SE_HERE, "empty server ID for updated eas item");
}
SE_LOG_DEBUG(getDisplayName(), "updated eas item %s", easid.c_str());
if (!item->data) {
throwError(StringPrintf("no body returned for updated eas item %s", easid.c_str()));
throwError(SE_HERE, StringPrintf("no body returned for updated eas item %s", easid.c_str()));
}
Event &event = setItemData(easid, item->data);
BOOST_FOREACH(const std::string &subid, event.m_subids) {
@ -182,11 +182,11 @@ void ActiveSyncCalendarSource::beginSync(const std::string &lastToken, const std
}
BOOST_FOREACH(const char *serverID, deleted) {
if (!serverID) {
throwError("no server ID for deleted eas item");
throwError(SE_HERE, "no server ID for deleted eas item");
}
string easid(serverID);
if (easid.empty()) {
throwError("empty server ID for deleted eas item");
throwError(SE_HERE, "empty server ID for deleted eas item");
}
Event &event = findItem(easid);
if (event.m_subids.empty()) {
@ -300,7 +300,7 @@ ActiveSyncCalendarSource::Event &ActiveSyncCalendarSource::findItem(const std::s
{
EventCache::iterator it = m_cache.find(easid);
if (it == m_cache.end()) {
throwError(STATUS_NOT_FOUND, "merged event not found: " + easid);
throwError(SE_HERE, STATUS_NOT_FOUND, "merged event not found: " + easid);
}
return *it->second;
}
@ -606,7 +606,7 @@ void ActiveSyncCalendarSource::readItem(const std::string &luid, std::string &it
eptr<char> icalstr(ical_strdup(icalcomponent_as_ical_string(event.m_calendar)));
item = icalstr.get();
} else {
throwError(STATUS_NOT_FOUND, "sub event not found: " + subid + " in " + easid);
throwError(SE_HERE, STATUS_NOT_FOUND, "sub event not found: " + subid + " in " + easid);
}
} else {
// complex case: create VCALENDAR with just the VTIMEZONE definition(s)
@ -630,7 +630,7 @@ void ActiveSyncCalendarSource::readItem(const std::string &luid, std::string &it
}
}
if (!found) {
throwError(STATUS_NOT_FOUND, "sub event not found: " + subid + " in " + easid);
throwError(SE_HERE, STATUS_NOT_FOUND, "sub event not found: " + subid + " in " + easid);
}
eptr<char> icalstr(ical_strdup(icalcomponent_as_ical_string(calendar)));
item = icalstr.get();
@ -650,7 +650,7 @@ void ActiveSyncCalendarSource::deleteItem(const string &luid)
if (event.m_subids.size() == 1) {
// remove entire merged item, nothing will be left after removal
if (*event.m_subids.begin() != subid) {
throwError(STATUS_NOT_FOUND, "sub event not found: " + subid + " in " + easid);
throwError(SE_HERE, STATUS_NOT_FOUND, "sub event not found: " + subid + " in " + easid);
} else {
event.m_subids.clear();
event.m_calendar = NULL;
@ -674,7 +674,7 @@ void ActiveSyncCalendarSource::deleteItem(const string &luid)
}
}
if (!found) {
throwError(STATUS_NOT_FOUND, "sub event not found: " + subid + " in " + easid);
throwError(SE_HERE, STATUS_NOT_FOUND, "sub event not found: " + subid + " in " + easid);
}
event.m_subids.erase(subid);
// TODO: avoid updating the item immediately

View file

@ -83,14 +83,14 @@ void ActiveSyncSource::findCollections(const std::string &account, const bool fo
/* Fetch the folders */
handler = EasSyncHandlerCXX::steal(eas_sync_handler_new(account.c_str()));
if (!handler) throwError("findCollections cannot allocate sync handler");
if (!handler) throwError(SE_HERE, "findCollections cannot allocate sync handler");
if (!eas_sync_handler_get_folder_list (handler,
force_update,
folders,
NULL,
gerror)) {
gerror.throwError("fetching folder list");
gerror.throwError(SE_HERE, "fetching folder list");
}
/* Save the Collections */
@ -157,7 +157,7 @@ ActiveSyncSource::Databases ActiveSyncSource::getDatabases()
// do a scan if username is set
UserIdentity identity = m_context->getSyncUser();
if (identity.m_provider != USER_IDENTITY_PLAIN_TEXT) {
throwError(StringPrintf("%s: only the 'user:<account ID in gconf>' format is supported by ActiveSync", identity.toString().c_str()));
throwError(SE_HERE, StringPrintf("%s: only the 'user:<account ID in gconf>' format is supported by ActiveSync", identity.toString().c_str()));
}
const std::string &account = identity.m_identity;
@ -206,7 +206,7 @@ void ActiveSyncSource::open()
// extract account ID and throw error if missing
UserIdentity identity = m_context->getSyncUser();
if (identity.m_provider != USER_IDENTITY_PLAIN_TEXT) {
throwError(StringPrintf("%s: only the 'user:<account ID in gconf>' format is supported by ActiveSync", identity.toString().c_str()));
throwError(SE_HERE, StringPrintf("%s: only the 'user:<account ID in gconf>' format is supported by ActiveSync", identity.toString().c_str()));
}
const std::string &username = identity.m_identity;
@ -229,7 +229,7 @@ void ActiveSyncSource::open()
m_folder = lookupFolder(folder);
}
if (m_folder.empty()) {
throwError("could not find folder: "+folder);
throwError(SE_HERE, "could not find folder: "+folder);
}
}
@ -306,7 +306,7 @@ void ActiveSyncSource::beginSync(const std::string &lastToken, const std::string
continue;
}
gerror.throwError("reading ActiveSync changes");
gerror.throwError(SE_HERE, "reading ActiveSync changes");
}
GStringPtr bufferOwner(buffer, "reading changes: empty sync key returned");
@ -317,43 +317,43 @@ void ActiveSyncSource::beginSync(const std::string &lastToken, const std::string
// populate ID lists and content cache
BOOST_FOREACH(EasItemInfo *item, created) {
if (!item->server_id) {
throwError("no server ID for new eas item");
throwError(SE_HERE, "no server ID for new eas item");
}
string luid(item->server_id);
if (luid.empty()) {
throwError("empty server ID for new eas item");
throwError(SE_HERE, "empty server ID for new eas item");
}
SE_LOG_DEBUG(getDisplayName(), "new item %s", luid.c_str());
addItem(luid, NEW);
m_ids->setProperty(luid, "1");
if (!item->data) {
throwError(StringPrintf("no body returned for new eas item %s", luid.c_str()));
throwError(SE_HERE, StringPrintf("no body returned for new eas item %s", luid.c_str()));
}
m_items[luid] = item->data;
}
BOOST_FOREACH(EasItemInfo *item, updated) {
if (!item->server_id) {
throwError("no server ID for updated eas item");
throwError(SE_HERE, "no server ID for updated eas item");
}
string luid(item->server_id);
if (luid.empty()) {
throwError("empty server ID for updated eas item");
throwError(SE_HERE, "empty server ID for updated eas item");
}
SE_LOG_DEBUG(getDisplayName(), "updated item %s", luid.c_str());
addItem(luid, UPDATED);
// m_ids.setProperty(luid, "1"); not necessary, should already exist (TODO: check?!)
if (!item->data) {
throwError(StringPrintf("no body returned for updated eas item %s", luid.c_str()));
throwError(SE_HERE, StringPrintf("no body returned for updated eas item %s", luid.c_str()));
}
m_items[luid] = item->data;
}
BOOST_FOREACH(const char *serverID, deleted) {
if (!serverID) {
throwError("no server ID for deleted eas item");
throwError(SE_HERE, "no server ID for deleted eas item");
}
string luid(serverID);
if (luid.empty()) {
throwError("empty server ID for deleted eas item");
throwError(SE_HERE, "empty server ID for deleted eas item");
}
SE_LOG_DEBUG(getDisplayName(), "deleted item %s", luid.c_str());
addItem(luid, DELETED);
@ -415,7 +415,7 @@ void ActiveSyncSource::deleteItem(const string &luid)
// the problem by looking up the item in our list (and keep the
// list up-to-date elsewhere)
if (m_ids && m_ids->readProperty(luid).empty()) {
throwError(STATUS_NOT_FOUND, "item not found: " + luid);
throwError(SE_HERE, STATUS_NOT_FOUND, "item not found: " + luid);
}
// send delete request
@ -432,7 +432,7 @@ void ActiveSyncSource::deleteItem(const string &luid)
m_folder.c_str(),
items,
gerror)) {
gerror.throwError("deleting eas item");
gerror.throwError(SE_HERE, "deleting eas item");
}
GStringPtr bufferOwner(buffer, "delete items: empty sync key returned");
@ -477,15 +477,15 @@ SyncSourceSerialize::InsertItemResult ActiveSyncSource::insertItem(const std::st
m_folder.c_str(),
items,
gerror)) {
gerror.throwError("adding eas item");
gerror.throwError(SE_HERE, "adding eas item");
}
if (!item->server_id) {
throwError("no server ID for new eas item");
throwError(SE_HERE, "no server ID for new eas item");
}
// get new ID from updated item
res.m_luid = item->server_id;
if (res.m_luid.empty()) {
throwError("empty server ID for new eas item");
throwError(SE_HERE, "empty server ID for new eas item");
}
// TODO: if someone else has inserted a new calendar item
@ -502,7 +502,7 @@ SyncSourceSerialize::InsertItemResult ActiveSyncSource::insertItem(const std::st
m_folder.c_str(),
items,
gerror)) {
gerror.throwError("updating eas item");
gerror.throwError(SE_HERE, "updating eas item");
}
res.m_luid = luid;
}
@ -542,13 +542,13 @@ void ActiveSyncSource::readItem(const std::string &luid, std::string &item)
message = 0xda2940 "GDBus.Error:org.meego.activesyncd.ItemOperationsError.ObjectNotFound: Document library - The object was not found or access denied."}
*/) {
throwError(STATUS_NOT_FOUND, "item not found: " + luid);
throwError(SE_HERE, STATUS_NOT_FOUND, "item not found: " + luid);
} else {
gerror.throwError(StringPrintf("reading eas item %s", luid.c_str()));
gerror.throwError(SE_HERE, StringPrintf("reading eas item %s", luid.c_str()));
}
}
if (!tmp->data) {
throwError(StringPrintf("no body returned for eas item %s", luid.c_str()));
throwError(SE_HERE, StringPrintf("no body returned for eas item %s", luid.c_str()));
}
item = tmp->data;
} else {

View file

@ -82,7 +82,7 @@ bool AkonadiSyncSource::isEmpty()
//To Check if the respective collection is Empty, without actually loading the collections
std::auto_ptr<CollectionStatisticsJob> statisticsJob(DisableAutoDelete(new CollectionStatisticsJob(m_collection)));
if (!statisticsJob->exec()) {
throwError("Error fetching the collection stats");
throwError(SE_HERE, "Error fetching the collection stats");
}
return statisticsJob->statistics().count() == 0;
}
@ -135,7 +135,7 @@ SyncSource::Databases AkonadiSyncSource::getDatabases()
fetchJob->fetchScope().setContentMimeTypes(m_mimeTypes);
if (!fetchJob->exec()) {
throwError("cannot list collections");
throwError(SE_HERE, "cannot list collections");
}
// Currently, the first collection of the right type is the default
@ -196,11 +196,11 @@ void AkonadiSyncSource::open()
std::auto_ptr<CollectionFetchJob> fetchJob(DisableAutoDelete(new CollectionFetchJob(m_collection,
CollectionFetchJob::Base)));
if (!fetchJob->exec()) {
throwError(StringPrintf("cannot fetch collection %s", id.c_str()));
throwError(SE_HERE, StringPrintf("cannot fetch collection %s", id.c_str()));
}
Collection::List collections = fetchJob->collections();
if (collections.isEmpty()) {
throwError(StringPrintf("collection %s not found", id.c_str()));
throwError(SE_HERE, StringPrintf("collection %s not found", id.c_str()));
}
m_collection = collections.front();
@ -213,7 +213,7 @@ void AkonadiSyncSource::open()
}
}
if (m_contentMimeType.isEmpty()) {
throwError(StringPrintf("Resource %s cannot store items of type(s) %s. It can only store %s.",
throwError(SE_HERE, StringPrintf("Resource %s cannot store items of type(s) %s. It can only store %s.",
id.c_str(),
m_mimeTypes.join(",").toUtf8().constData(),
collectionMimeTypes.join(",").toUtf8().constData()));
@ -230,7 +230,7 @@ void AkonadiSyncSource::listAllItems(SyncSourceRevisions::RevisionMap_t &revisio
// copy all local IDs and the corresponding revision
std::auto_ptr<ItemFetchJob> fetchJob(DisableAutoDelete(new ItemFetchJob(m_collection)));
if (!fetchJob->exec()) {
throwError("listing items");
throwError(SE_HERE, "listing items");
}
BOOST_FOREACH (const Item &item, fetchJob->items()) {
// Filter out items which don't have the right type (for example, VTODO when
@ -262,7 +262,7 @@ TrackingSyncSource::InsertItemResult AkonadiSyncSource::insertItem(const std::st
item.setPayloadFromData(QByteArray(data.c_str()));
std::auto_ptr<ItemCreateJob> createJob(DisableAutoDelete(new ItemCreateJob(item, m_collection)));
if (!createJob->exec()) {
throwError(string("storing new item ") + luid);
throwError(SE_HERE, string("storing new item ") + luid);
return InsertItemResult("", "", ITEM_OKAY);
}
item = createJob->item();
@ -270,7 +270,7 @@ TrackingSyncSource::InsertItemResult AkonadiSyncSource::insertItem(const std::st
Entity::Id syncItemId = QByteArray(luid.c_str()).toLongLong();
std::auto_ptr<ItemFetchJob> fetchJob(DisableAutoDelete(new ItemFetchJob(Item(syncItemId))));
if (!fetchJob->exec()) {
throwError(string("checking item ") + luid);
throwError(SE_HERE, string("checking item ") + luid);
}
item = fetchJob->items().first();
item.setPayloadFromData(QByteArray(data.c_str()));
@ -279,7 +279,7 @@ TrackingSyncSource::InsertItemResult AkonadiSyncSource::insertItem(const std::st
// we are updating.
// TODO: check that the item has not been updated in the meantime
if (!modifyJob->exec()) {
throwError(string("updating item ") + luid);
throwError(SE_HERE, string("updating item ") + luid);
return InsertItemResult("", "", ITEM_OKAY);
}
item = modifyJob->item();
@ -306,7 +306,7 @@ void AkonadiSyncSource::removeItem(const string &luid)
// TODO: check that the revision is right (need revision from SyncEvolution)
std::auto_ptr<ItemDeleteJob> deleteJob(DisableAutoDelete(new ItemDeleteJob(Item(syncItemId))));
if (!deleteJob->exec()) {
throwError(string("deleting item " ) + luid);
throwError(SE_HERE, string("deleting item " ) + luid);
}
}
@ -323,13 +323,13 @@ void AkonadiSyncSource::readItem(const std::string &luid, std::string &data, boo
fetchJob->fetchScope().fetchFullPayload();
if (fetchJob->exec()) {
if (fetchJob->items().empty()) {
throwError(STATUS_NOT_FOUND, string("extracting item ") + luid);
throwError(SE_HERE, STATUS_NOT_FOUND, string("extracting item ") + luid);
}
QByteArray payload = fetchJob->items().first().payloadData();
data.assign(payload.constData(),
payload.size());
} else {
throwError(string("extracting item " ) + luid);
throwError(SE_HERE, string("extracting item " ) + luid);
}
}

View file

@ -28,7 +28,7 @@ using namespace std;
// include first, it sets HANDLE_LIBICAL_MEMORY for us
#include <syncevo/icalstrdup.h>
#include <syncevo/SyncContext.h>
#include <syncevo/Exception.h>
#include <syncevo/SmartPtr.h>
#include <syncevo/Logging.h>
@ -128,7 +128,7 @@ EvolutionCalendarSource::EvolutionCalendarSource(EvolutionCalendarSourceType typ
#endif
break;
default:
SyncContext::throwError("internal error, invalid calendar type");
Exception::throwError(SE_HERE, "internal error, invalid calendar type");
break;
}
}
@ -153,7 +153,7 @@ SyncSource::Databases EvolutionCalendarSource::getDatabases()
if (!gerror) {
tmp = NULL;
} else {
throwError("unable to access backend databases", gerror);
throwError(SE_HERE, "unable to access backend databases", gerror);
}
}
ESourceListCXX sources(tmp, TRANSFER_REF);
@ -238,7 +238,7 @@ void EvolutionCalendarSource::open()
ESourceList *tmp;
if (!e_cal_get_sources(&tmp, sourceType(), gerror)) {
throwError("unable to access backend databases", gerror);
throwError(SE_HERE, "unable to access backend databases", gerror);
}
ESourceListCXX sources(tmp, TRANSFER_REF);
@ -263,7 +263,7 @@ void EvolutionCalendarSource::open()
} else if (!id.compare(0, 7, "file://")) {
m_calendar.set(e_cal_new_from_uri(id.c_str(), sourceType()), (string("creating ") + m_typeName).c_str());
} else {
throwError(string("not found: '") + id + "'");
throwError(SE_HERE, string("not found: '") + id + "'");
}
created = true;
onlyIfExists = false;
@ -279,10 +279,10 @@ void EvolutionCalendarSource::open()
gerror.clear();
sleep(5);
if (!e_cal_open(m_calendar, onlyIfExists, gerror)) {
throwError(string("opening ") + m_typeName, gerror);
throwError(SE_HERE, string("opening ") + m_typeName, gerror);
}
} else {
throwError(string("opening ") + m_typeName, gerror);
throwError(SE_HERE, string("opening ") + m_typeName, gerror);
}
}
}
@ -291,7 +291,7 @@ void EvolutionCalendarSource::open()
g_signal_connect_after(m_calendar,
"backend-died",
G_CALLBACK(SyncContext::fatalError),
G_CALLBACK(Exception::fatalError),
(void *)"Evolution Data Server has died unexpectedly, database no longer available.");
}
@ -387,7 +387,7 @@ void EvolutionCalendarSource::listAllItems(RevisionMap_t &revisions)
ECalClientView *view;
if (!e_cal_client_get_view_sync (m_calendar, "#t", &view, NULL, gerror)) {
throwError( "getting the view" , gerror);
throwError(SE_HERE, "getting the view" , gerror);
}
ECalClientViewCXX viewPtr = ECalClientViewCXX::steal(view);
@ -395,7 +395,7 @@ void EvolutionCalendarSource::listAllItems(RevisionMap_t &revisions)
ECalClientViewSyncHandler handler(viewPtr, boost::bind(list_revisions, _1, &revisions));
if (!handler.processSync(gerror)) {
throwError("watching view", gerror);
throwError(SE_HERE, "watching view", gerror);
}
// Update m_allLUIDs
@ -412,7 +412,7 @@ void EvolutionCalendarSource::listAllItems(RevisionMap_t &revisions)
"#t",
&nextItem,
gerror)) {
throwError("reading all items", gerror);
throwError(SE_HERE, "reading all items", gerror);
}
eptr<GList> listptr(nextItem);
while (nextItem) {
@ -507,7 +507,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
eptr<icalcomponent> icomp(icalcomponent_new_from_string((char *)data.c_str()));
if( !icomp ) {
throwError(string("failure parsing ical") + data);
throwError(SE_HERE, string("failure parsing ical") + data);
}
GErrorCXX gerror;
@ -529,7 +529,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
gerror)
#endif
) {
throwError(string("fixing timezones") + data,
throwError(SE_HERE, string("fixing timezones") + data,
gerror);
}
@ -555,7 +555,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
#endif
;
if (!success) {
throwError(string("error adding VTIMEZONE ") + tzid,
throwError(SE_HERE, string("error adding VTIMEZONE ") + tzid,
gerror);
}
}
@ -567,7 +567,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
icalcomponent *subcomp = icalcomponent_get_first_component(icomp,
getCompType());
if (!subcomp) {
throwError("extracting event");
throwError(SE_HERE, "extracting event");
}
// Remove LAST-MODIFIED: the Evolution Exchange Connector does not
@ -645,7 +645,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
modTime = getItemModTime(newid);
m_allLUIDs.insertLUID(newid);
} else {
throwError("storing new item", gerror);
throwError(SE_HERE, "storing new item", gerror);
}
// Recreate any children removed earlier: when we get here,
@ -662,7 +662,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
gerror)
#endif
) {
throwError(string("recreating item ") + newluid, gerror);
throwError(SE_HERE, string("recreating item ") + newluid, gerror);
}
}
}
@ -734,7 +734,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
!e_cal_create_object(m_calendar, subcomp, (char **)&uid, gerror)
#endif
) {
throwError(string("creating updated item ") + luid, gerror);
throwError(SE_HERE, string("creating updated item ") + luid, gerror);
}
#ifdef USE_EDS_CLIENT
PlainGStr owner((gchar *)uid);
@ -754,7 +754,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
gerror)
#endif
) {
throwError(string("recreating item ") + luid, gerror);
throwError(SE_HERE, string("recreating item ") + luid, gerror);
}
}
} else {
@ -770,7 +770,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
gerror)
#endif
) {
throwError(string("updating item ") + luid, gerror);
throwError(SE_HERE, string("updating item ") + luid, gerror);
}
}
} else {
@ -786,7 +786,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionCalendarSource::insertItem(co
gerror)
#endif
) {
throwError(string("updating item ") + luid, gerror);
throwError(SE_HERE, string("updating item ") + luid, gerror);
}
}
@ -835,10 +835,10 @@ EvolutionCalendarSource::ICalComps_t EvolutionCalendarSource::removeEvents(const
SE_LOG_DEBUG(getDisplayName(), "%s: request to delete non-existant item ignored",
uid.c_str());
if (!ignoreNotFound) {
throwError(STATUS_NOT_FOUND, string("delete item: ") + uid);
throwError(SE_HERE, STATUS_NOT_FOUND, string("delete item: ") + uid);
}
} else {
throwError(string("deleting item " ) + uid, gerror);
throwError(SE_HERE, string("deleting item " ) + uid, gerror);
}
}
@ -874,7 +874,7 @@ void EvolutionCalendarSource::removeItem(const string &luid)
!e_cal_create_object(m_calendar, *icalcomp, &uid, gerror)
#endif
) {
throwError(string("recreating first item ") + luid, gerror);
throwError(SE_HERE, string("recreating first item ") + luid, gerror);
}
#ifdef USE_EDS_CLIENT
PlainGStr owner((gchar *)uid);
@ -892,7 +892,7 @@ void EvolutionCalendarSource::removeItem(const string &luid)
gerror)
#endif
) {
throwError(string("recreating following item ") + luid, gerror);
throwError(SE_HERE, string("recreating following item ") + luid, gerror);
}
}
}
@ -922,9 +922,9 @@ void EvolutionCalendarSource::removeItem(const string &luid)
(!success && IsCalObjNotFound(gerror))) {
SE_LOG_DEBUG(getDisplayName(), "%s: request to delete non-existant item",
luid.c_str());
throwError(STATUS_NOT_FOUND, string("delete item: ") + id.getLUID());
throwError(SE_HERE, STATUS_NOT_FOUND, string("delete item: ") + id.getLUID());
} else if (!success) {
throwError(string("deleting item " ) + luid, gerror);
throwError(SE_HERE, string("deleting item " ) + luid, gerror);
}
}
m_allLUIDs.eraseLUID(id);
@ -973,13 +973,13 @@ icalcomponent *EvolutionCalendarSource::retrieveItem(const ItemID &id)
#endif
) {
if (IsCalObjNotFound(gerror)) {
throwError(STATUS_NOT_FOUND, string("retrieving item: ") + id.getLUID());
throwError(SE_HERE, STATUS_NOT_FOUND, string("retrieving item: ") + id.getLUID());
} else {
throwError(string("retrieving item: ") + id.getLUID(), gerror);
throwError(SE_HERE, string("retrieving item: ") + id.getLUID(), gerror);
}
}
if (!comp) {
throwError(string("retrieving item: ") + id.getLUID());
throwError(SE_HERE, string("retrieving item: ") + id.getLUID());
}
eptr<icalcomponent> ptr(comp);
@ -991,7 +991,7 @@ icalcomponent *EvolutionCalendarSource::retrieveItem(const ItemID &id)
if (id.m_rid.empty()) {
struct icaltimetype rid = icalcomponent_get_recurrenceid(comp);
if (!icaltime_is_null_time(rid)) {
throwError(string("retrieving item: got child instead of parent: ") + id.m_uid);
throwError(SE_HERE, string("retrieving item: got child instead of parent: ") + id.m_uid);
}
}
@ -1032,7 +1032,7 @@ string EvolutionCalendarSource::retrieveItemAsString(const ItemID &id)
icalstr = e_cal_get_component_as_string(m_calendar, comp);
#endif
if (!icalstr) {
throwError(string("could not encode item as iCalendar: ") + id.getLUID());
throwError(SE_HERE, string("could not encode item as iCalendar: ") + id.getLUID());
} else {
SE_LOG_DEBUG(getDisplayName(), "had to remove TZIDs because e_cal_get_component_as_string() failed for:\n%s", icalstr.get());
}

View file

@ -30,10 +30,9 @@ using namespace std;
#ifdef ENABLE_EBOOK
#include <syncevo/SyncContext.h>
#include "EvolutionContactSource.h"
#include <syncevo/util.h>
#include <syncevo/Exception.h>
#include <syncevo/Logging.h>
#ifdef USE_EDS_CLIENT
@ -124,7 +123,7 @@ EvolutionSyncSource::Databases EvolutionContactSource::getDatabases()
#else
ESourceList *sources = NULL;
if (!e_book_get_addressbooks(&sources, NULL)) {
SyncContext::throwError("unable to access address books");
Exception::throwError(SE_HERE, "unable to access address books");
}
Databases secondary;
@ -205,7 +204,7 @@ void EvolutionContactSource::open()
// therefore failed in some cases
ESourceList *tmp;
if (!e_book_get_addressbooks(&tmp, gerror)) {
throwError("unable to access address books", gerror);
throwError(SE_HERE, "unable to access address books", gerror);
}
ESourceListCXX sources(tmp, TRANSFER_REF);
@ -221,7 +220,7 @@ void EvolutionContactSource::open()
} else if (boost::starts_with(id, "file://")) {
m_addressbook.set(e_book_new_from_uri(id.c_str(), gerror), "creating address book");
} else {
throwError(string(getName()) + ": no such address book: '" + id + "'");
throwError(SE_HERE, string(getName()) + ": no such address book: '" + id + "'");
}
created = true;
} else {
@ -233,10 +232,10 @@ void EvolutionContactSource::open()
// opening newly created address books often fails, try again once more
sleep(5);
if (!e_book_open(m_addressbook, onlyIfExists, gerror)) {
throwError("opening address book", gerror);
throwError(SE_HERE, "opening address book", gerror);
}
} else {
throwError("opening address book", gerror);
throwError(SE_HERE, "opening address book", gerror);
}
}
@ -248,7 +247,7 @@ void EvolutionContactSource::open()
if (identity.wasSet() || passwd.wasSet()) {
GList *authmethod;
if (!e_book_get_supported_auth_methods(m_addressbook, &authmethod, gerror)) {
throwError("getting authentication methods", gerror);
throwError(SE_HERE, "getting authentication methods", gerror);
}
while (authmethod) {
// map identity + password to plain username/password credentials
@ -274,7 +273,7 @@ void EvolutionContactSource::open()
g_signal_connect_after(m_addressbook,
"backend-died",
G_CALLBACK(SyncContext::fatalError),
G_CALLBACK(Exception::fatalError),
(void *)"Evolution Data Server has died unexpectedly, contacts no longer available.");
#endif
}
@ -389,7 +388,7 @@ void EvolutionContactSource::listAllItems(RevisionMap_t &revisions)
}
if (!e_book_client_get_view_sync(m_addressbook, sexp, &view, NULL, gerror)) {
throwError( "getting the view" , gerror);
throwError(SE_HERE, "getting the view" , gerror);
}
EBookClientViewCXX viewPtr = EBookClientViewCXX::steal(view);
@ -405,32 +404,32 @@ void EvolutionContactSource::listAllItems(RevisionMap_t &revisions)
EBookClientViewSyncHandler handler(viewPtr, boost::bind(list_revisions, _1, &revisions));
if (!handler.process(gerror)) {
throwError("watching view", gerror);
throwError(SE_HERE, "watching view", gerror);
}
#else
GErrorCXX gerror;
eptr<EBookQuery> allItemsQuery(e_book_query_any_field_contains(""), "query");
GList *nextItem;
if (!e_book_get_contacts(m_addressbook, allItemsQuery, &nextItem, gerror)) {
throwError( "reading all items", gerror );
throwError(SE_HERE, "reading all items", gerror );
}
eptr<GList> listptr(nextItem);
while (nextItem) {
EContact *contact = E_CONTACT(nextItem->data);
if (!contact) {
throwError("contact entry without data");
throwError(SE_HERE, "contact entry without data");
}
pair<string, string> revmapping;
const char *uid = (const char *)e_contact_get_const(contact,
E_CONTACT_UID);
if (!uid || !uid[0]) {
throwError("contact entry without UID");
throwError(SE_HERE, "contact entry without UID");
}
revmapping.first = uid;
const char *rev = (const char *)e_contact_get_const(contact,
E_CONTACT_REV);
if (!rev || !rev[0]) {
throwError(string("contact entry without REV: ") + revmapping.first);
throwError(SE_HERE, string("contact entry without REV: ") + revmapping.first);
}
revmapping.second = rev;
revisions.insert(revmapping);
@ -467,9 +466,9 @@ string EvolutionContactSource::getRevision(const string &luid)
#endif
) {
if (IsContactNotFound(gerror)) {
throwError(STATUS_NOT_FOUND, string("retrieving item: ") + luid);
throwError(SE_HERE, STATUS_NOT_FOUND, string("retrieving item: ") + luid);
} else {
throwError(string("reading contact ") + luid,
throwError(SE_HERE, string("reading contact ") + luid,
gerror);
}
}
@ -477,7 +476,7 @@ string EvolutionContactSource::getRevision(const string &luid)
const char *rev = (const char *)e_contact_get_const(contact,
E_CONTACT_REV);
if (!rev || !rev[0]) {
throwError(string("contact entry without REV: ") + luid);
throwError(SE_HERE, string("contact entry without REV: ") + luid);
}
return rev;
}
@ -535,7 +534,7 @@ void EvolutionContactSource::checkCacheForError(boost::shared_ptr<ContactCache>
GErrorCXX gerror;
std::swap(gerror, cache->m_gerror);
cache.reset();
throwError(StringPrintf("reading contacts %s", cache->m_name.c_str()), gerror);
throwError(SE_HERE, StringPrintf("reading contacts %s", cache->m_name.c_str()), gerror);
}
}
@ -862,9 +861,9 @@ void EvolutionContactSource::readItem(const string &luid, std::string &item, boo
#endif
) {
if (IsContactNotFound(gerror)) {
throwError(STATUS_NOT_FOUND, string("reading contact: ") + luid);
throwError(SE_HERE, STATUS_NOT_FOUND, string("reading contact: ") + luid);
} else {
throwError(string("reading contact ") + luid,
throwError(SE_HERE, string("reading contact ") + luid,
gerror);
}
}
@ -883,7 +882,7 @@ void EvolutionContactSource::readItem(const string &luid, std::string &item, boo
) {
#if defined(EVOLUTION_COMPATIBILITY) || defined(HAVE_E_CONTACT_INLINE_LOCAL_PHOTOS)
if (!e_contact_inline_local_photos(contactptr, gerror)) {
throwError(string("inlining PHOTO file data in ") + luid, gerror);
throwError(SE_HERE, string("inlining PHOTO file data in ") + luid, gerror);
}
#endif
}
@ -891,7 +890,7 @@ void EvolutionContactSource::readItem(const string &luid, std::string &item, boo
eptr<char> vcardstr(e_vcard_to_string(&contactptr->parent,
EVC_FORMAT_VCARD_30));
if (!vcardstr) {
throwError(string("failure extracting contact from Evolution " ) + luid);
throwError(SE_HERE, string("failure extracting contact from Evolution " ) + luid);
}
item = vcardstr.get();
@ -905,7 +904,7 @@ TrackingSyncSource::InsertItemResult EvolutionContactSource::checkBatchedInsert(
return TrackingSyncSource::InsertItemResult(boost::bind(&EvolutionContactSource::checkBatchedInsert, this, pending));
}
if (pending->m_gerror) {
pending->m_gerror.throwError(pending->m_name);
pending->m_gerror.throwError(SE_HERE, pending->m_name);
}
string newrev = getRevision(pending->m_uid);
return TrackingSyncSource::InsertItemResult(pending->m_uid, newrev, ITEM_OKAY);
@ -1044,14 +1043,14 @@ EvolutionContactSource::insertItem(const string &uid, const std::string &item, b
if (uid.empty()) {
gchar* newuid;
if (!e_book_client_add_contact_sync(m_addressbook, contact, &newuid, NULL, gerror)) {
throwError("add new contact", gerror);
throwError(SE_HERE, "add new contact", gerror);
}
PlainGStr newuidPtr(newuid);
string newrev = getRevision(newuid);
return InsertItemResult(newuid, newrev, ITEM_OKAY);
} else {
if (!e_book_client_modify_contact_sync(m_addressbook, contact, NULL, gerror)) {
throwError("updating contact "+ uid, gerror);
throwError(SE_HERE, "updating contact "+ uid, gerror);
}
string newrev = getRevision(uid);
return InsertItemResult(uid, newrev, ITEM_OKAY);
@ -1083,19 +1082,19 @@ EvolutionContactSource::insertItem(const string &uid, const std::string &item, b
e_book_commit_contact(m_addressbook, contact, gerror)) {
const char *newuid = (const char *)e_contact_get_const(contact, E_CONTACT_UID);
if (!newuid) {
throwError("no UID for contact");
throwError(SE_HERE, "no UID for contact");
}
string newrev = getRevision(newuid);
return InsertItemResult(newuid, newrev, ITEM_OKAY);
} else {
throwError(uid.empty() ?
throwError(SE_HERE, uid.empty() ?
"storing new contact" :
string("updating contact ") + uid,
gerror);
}
#endif
} else {
throwError(string("failure parsing vcard " ) + item);
throwError(SE_HERE, string("failure parsing vcard " ) + item);
}
// not reached!
return InsertItemResult("", "", ITEM_OKAY);
@ -1113,9 +1112,9 @@ void EvolutionContactSource::removeItem(const string &uid)
#endif
) {
if (IsContactNotFound(gerror)) {
throwError(STATUS_NOT_FOUND, string("deleting contact: ") + uid);
throwError(SE_HERE, STATUS_NOT_FOUND, string("deleting contact: ") + uid);
} else {
throwError( string( "deleting contact " ) + uid,
throwError(SE_HERE, string( "deleting contact " ) + uid,
gerror);
}
}
@ -1138,7 +1137,7 @@ std::string EvolutionContactSource::getDescription(const string &luid)
gerror)
#endif
) {
throwError(string("reading contact ") + luid,
throwError(SE_HERE, string("reading contact ") + luid,
gerror);
}
eptr<EContact, GObject> contactptr(contact, "contact");

View file

@ -166,7 +166,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionMemoSource::insertItem(const
0));
if( !subcomp ) {
throwError(string("failure creating vjournal " ) + summary);
throwError(SE_HERE, string("failure creating vjournal " ) + summary);
}
GErrorCXX gerror;
@ -199,10 +199,10 @@ EvolutionCalendarSource::InsertItemResult EvolutionMemoSource::insertItem(const
state = ITEM_NEEDS_MERGE;
uid = icalcomponent_get_uid(subcomp);
if (!uid) {
throwError("storing new memo item, no UID set", gerror);
throwError(SE_HERE, "storing new memo item, no UID set", gerror);
}
} else {
throwError("storing new memo item", gerror);
throwError(SE_HERE, "storing new memo item", gerror);
}
}
#ifdef USE_EDS_CLIENT
@ -231,7 +231,7 @@ EvolutionCalendarSource::InsertItemResult EvolutionMemoSource::insertItem(const
!e_cal_modify_object(m_calendar, subcomp, CALOBJ_MOD_ALL, gerror)
#endif
) {
throwError(string("updating memo item ") + luid, gerror);
throwError(SE_HERE, string("updating memo item ") + luid, gerror);
}
ItemID newid = getItemID(subcomp);
newluid = newid.getLUID();

View file

@ -20,7 +20,7 @@
#include "EvolutionSyncSource.h"
#include <syncevo/SmartPtr.h>
#include <syncevo/SyncContext.h>
#include <syncevo/Exception.h>
#include <syncevo/GLibSupport.h>
#ifdef USE_EDS_CLIENT
@ -76,7 +76,7 @@ EClientCXX EvolutionSyncSource::openESource(const char *extension,
// TODO: create source
// m_calendar = ECalClientCXX::steal(e_cal_client_new_from_uri(id.c_str(), sourceType(), gerror));
} else {
throwError(string("database not found: '") + id + "'");
throwError(SE_HERE, string("database not found: '") + id + "'");
}
created = true;
} else {
@ -84,14 +84,14 @@ EClientCXX EvolutionSyncSource::openESource(const char *extension,
}
if (!client) {
throwError("accessing database", gerror);
throwError(SE_HERE, "accessing database", gerror);
}
// Listen for errors
g_signal_connect (client, "backend-error", G_CALLBACK(handleErrorCB), this);
g_signal_connect_after(client,
"backend-died",
G_CALLBACK(SyncContext::fatalError),
G_CALLBACK(Exception::fatalError),
(void *)"Evolution Data Server has died unexpectedly.");
@ -109,7 +109,7 @@ EClientCXX EvolutionSyncSource::openESource(const char *extension,
gerror.clear();
sleep(5);
} else {
throwError("opening database", gerror);
throwError(SE_HERE, "opening database", gerror);
}
} else {
// Success!
@ -153,16 +153,16 @@ SyncSource::Database EvolutionSyncSource::createDatabase(const Database &databas
GKeyFileCXX keyfile(g_key_file_new(), TRANSFER_REF);
GErrorCXX gerror;
if (!g_key_file_load_from_data(keyfile, ini, len, G_KEY_FILE_NONE, gerror)) {
gerror.throwError("parsing ESource .ini data");
gerror.throwError(SE_HERE, "parsing ESource .ini data");
}
PlainGStrArray keys(g_key_file_get_keys(keyfile, mainSection, NULL, gerror));
if (!keys) {
gerror.throwError("listing keys in main section");
gerror.throwError(SE_HERE, "listing keys in main section");
}
for (int i = 0; keys.at(i); i++) {
if (boost::starts_with(keys.at(i), "DisplayName[")) {
if (!g_key_file_remove_key(keyfile, mainSection, keys.at(i), gerror)) {
gerror.throwError("remove key");
gerror.throwError(SE_HERE, "remove key");
}
}
}
@ -231,7 +231,7 @@ SyncSource::Database EvolutionSyncSource::createDatabase(const Database &databas
// sources,
// NULL,
// gerror)) {
// gerror.throwError(StringPrintf("creating EDS database of type %s with name '%s'%s%s",
// gerror.throwError(SE_HERE, StringPrintf("creating EDS database of type %s with name '%s'%s%s",
// sourceExtension(),
// database.m_name.c_str(),
// database.m_uri.empty() ? "" : " and URI ",
@ -248,12 +248,12 @@ void EvolutionSyncSource::deleteDatabase(const std::string &uri, RemoveData remo
ESourceRegistryCXX registry = EDSRegistryLoader::getESourceRegistry();
ESourceCXX source(e_source_registry_ref_source(registry, uri.c_str()), TRANSFER_REF);
if (!source) {
throwError(StringPrintf("EDS database with URI '%s' cannot be deleted, does not exist",
uri.c_str()));
throwError(SE_HERE, StringPrintf("EDS database with URI '%s' cannot be deleted, does not exist",
uri.c_str()));
}
GErrorCXX gerror;
if (!e_source_remove_sync(source, NULL, gerror)) {
throwError(StringPrintf("deleting EDS database with URI '%s'", uri.c_str()),
throwError(SE_HERE, StringPrintf("deleting EDS database with URI '%s'", uri.c_str()),
gerror);
}
if (removeData == REMOVE_DATA_FORCE) {
@ -332,7 +332,7 @@ ESource *EvolutionSyncSource::findSource(const ESourceListCXX &list, const strin
return NULL;
}
void EvolutionSyncSource::throwError(const string &action, GErrorCXX &gerror)
void EvolutionSyncSource::throwError(const SourceLocation &where, const string &action, GErrorCXX &gerror)
{
string gerrorstr;
if (gerror) {
@ -342,7 +342,7 @@ void EvolutionSyncSource::throwError(const string &action, GErrorCXX &gerror)
gerrorstr = ": failure";
}
throwError(action + gerrorstr);
throwError(where, action + gerrorstr);
}
#endif // HAVE_EDS

View file

@ -110,7 +110,8 @@ class EvolutionSyncSource : public TrackingSyncSource
* @param gerror a more detailed description of the failure,
* may be empty
*/
void throwError(const string &action,
void throwError(const SourceLocation &where,
const string &action,
GErrorCXX &gerror);
#endif
};

View file

@ -45,7 +45,6 @@
#include <sstream>
#include <fstream>
#include <syncevo/SyncContext.h>
#include <syncevo/declarations.h>
SE_BEGIN_CXX
@ -56,7 +55,7 @@ FileSyncSource::FileSyncSource(const SyncSourceParams &params,
m_entryCounter(0)
{
if (dataformat.empty()) {
throwError("a database format must be specified");
throwError(SE_HERE, "a database format must be specified");
}
}
@ -110,7 +109,7 @@ void FileSyncSource::open()
if (errno == ENOENT && createDir) {
mkdir_p(basedir.c_str());
} else {
throwError(basedir, errno);
throwError(SE_HERE, basedir, errno);
}
}
@ -126,7 +125,7 @@ bool FileSyncSource::isEmpty()
try {
dir = opendir(m_basedir.c_str());
if (!dir) {
SyncContext::throwError(m_basedir, errno);
Exception::throwError(SE_HERE, m_basedir, errno);
}
errno = 0;
struct dirent *entry = readdir(dir);
@ -139,7 +138,7 @@ bool FileSyncSource::isEmpty()
entry = readdir(dir);
}
if (errno) {
SyncContext::throwError(m_basedir, errno);
Exception::throwError(SE_HERE, m_basedir, errno);
}
} catch(...) {
if (dir) {
@ -195,7 +194,7 @@ void FileSyncSource::readItem(const string &uid, std::string &item, bool raw)
string filename = createFilename(uid);
if (!ReadFile(filename, item)) {
throwError(filename + ": reading failed", errno);
throwError(SE_HERE, filename + ": reading failed", errno);
}
}
@ -233,7 +232,7 @@ TrackingSyncSource::InsertItemResult FileSyncSource::insertItem(const string &ui
newuid = buff.str();
break;
} else {
throwError(filename, errno);
throwError(SE_HERE, filename, errno);
}
}
@ -246,7 +245,7 @@ TrackingSyncSource::InsertItemResult FileSyncSource::insertItem(const string &ui
out.write(item.c_str(), item.size());
out.close();
if (!out.good()) {
throwError(filename + ": writing failed", errno);
throwError(SE_HERE, filename + ": writing failed", errno);
}
return InsertItemResult(newuid,
@ -260,7 +259,7 @@ void FileSyncSource::removeItem(const string &uid)
string filename = createFilename(uid);
if (unlink(filename.c_str())) {
throwError(filename, errno);
throwError(SE_HERE, filename, errno);
}
}
@ -268,7 +267,7 @@ string FileSyncSource::getATimeString(const string &filename)
{
struct stat buf;
if (stat(filename.c_str(), &buf)) {
throwError(filename, errno);
throwError(SE_HERE, filename, errno);
}
time_t mtime = buf.st_mtime;
int mnsec = buf.st_mtim.tv_nsec;

View file

@ -27,7 +27,8 @@ extern "C" {
#include "GNOMEPlatform.h"
#include <syncevo/SyncContext.h>
#include <syncevo/Exception.h>
#include <syncevo/UserInterface.h>
#include <syncevo/SyncConfig.h>
#include <syncevo/declarations.h>
@ -200,7 +201,7 @@ bool GNOMESavePasswordSlot(const InitStateTri &keyring,
} while (result != GNOME_KEYRING_RESULT_OK &&
(Timespec::monotonic() - start).duration() < GNOMEKeyringRetryDuration);
if (result != GNOME_KEYRING_RESULT_OK) {
SyncContext::throwError(StringPrintf("%s: saving password '%s' in GNOME keyring failed: %s",
Exception::throwError(SE_HERE, StringPrintf("%s: saving password '%s' in GNOME keyring failed: %s",
key.description.c_str(),
key.toString().c_str(),
gnome_keyring_result_to_message(result)));

View file

@ -173,7 +173,7 @@ KCalCore::Incidence::Ptr KCalExtendedData::findIncidence(const string &luid)
QString uid = id.getIDString();
KDateTime rid = id.getDateTime();
// if (!m_storage->load(uid, rid)) {
// m_parent->throwError(string("failed to load incidence ") + luid);
// m_parent->throwError(SE_HERE, string("failed to load incidence ") + luid);
// }
KCalCore::Incidence::Ptr incidence = m_calendar->incidence(uid, rid);
return incidence;
@ -212,7 +212,7 @@ KCalExtendedSource::KCalExtendedSource(const SyncSourceParams &params, Type type
m_operations);
break;
default:
throwError("invalid calendar type");
throwError(SE_HERE, "invalid calendar type");
break;
}
@ -261,7 +261,7 @@ void KCalExtendedSource::open()
m_data->m_storage = mKCal::ExtendedCalendar::defaultStorage(m_data->m_calendar);
}
if (!m_data->m_storage->open()) {
throwError("failed to open storage");
throwError(SE_HERE, "failed to open storage");
}
#ifdef ENABLE_MAEMO
mKCal::Notebook::Ptr defaultNotebook;
@ -279,7 +279,7 @@ void KCalExtendedSource::open()
mKCal::Notebook::Ptr defaultNotebook = m_data->m_storage->defaultNotebook();
#endif
if (!defaultNotebook) {
throwError("no default Notebook");
throwError(SE_HERE, "no default Notebook");
}
m_data->m_notebookUID = defaultNotebook->uid();
#ifdef ENABLE_MAEMO
@ -287,13 +287,13 @@ void KCalExtendedSource::open()
// if databaseID has a "uid:" prefix, open existing notebook with given ID in default storage
m_data->m_storage = mKCal::ExtendedCalendar::defaultStorage(m_data->m_calendar);
if (!m_data->m_storage->open()) {
throwError("failed to open storage");
throwError(SE_HERE, "failed to open storage");
}
QString uid = databaseID.c_str() + strlen("uid:");
mKCal::Notebook::Ptr notebook = m_data->m_storage->notebook(uid);
if ( !notebook ) {
throwError(string("no such notebook with UID \"") + uid.toStdString() + string("\" in default storage"));
throwError(SE_HERE, string("no such notebook with UID \"") + uid.toStdString() + string("\" in default storage"));
}
m_data->m_notebookUID = notebook->uid();
#endif
@ -304,7 +304,7 @@ void KCalExtendedSource::open()
// 2) without a special prefix, throw an error
m_data->m_storage = mKCal::ExtendedCalendar::defaultStorage(m_data->m_calendar);
if (!m_data->m_storage->open()) {
throwError("failed to open storage");
throwError(SE_HERE, "failed to open storage");
}
QString name = databaseID.c_str();
mKCal::Notebook::Ptr notebook;
@ -320,11 +320,11 @@ void KCalExtendedSource::open()
if ( boost::starts_with(databaseID, "SyncEvolution_Test_") ) {
notebook = mKCal::Notebook::Ptr ( new mKCal::Notebook(QString(), name, QString(), QString(), false, true, false, false,true) );
if ( !notebook ) {
throwError("failed to create notebook");
throwError(SE_HERE, "failed to create notebook");
}
m_data->m_storage->addNotebook(notebook, false);
} else {
throwError(string("no such notebook with name \"") + string(databaseID) + string("\" in default storage"));
throwError(SE_HERE, string("no such notebook with name \"") + string(databaseID) + string("\" in default storage"));
}
} else {
notebook = *it;
@ -336,7 +336,7 @@ void KCalExtendedSource::open()
// issues with it (BMC #6061); the load() calls elsewhere in this
// file are commented out
if (!m_data->m_storage->loadNotebookIncidences(m_data->m_notebookUID)) {
throwError("failed to load calendar");
throwError(SE_HERE, "failed to load calendar");
}
}
@ -384,7 +384,7 @@ KCalExtendedSource::Databases KCalExtendedSource::getDatabases()
m_data->m_calendar = mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
m_data->m_storage = mKCal::ExtendedCalendar::defaultStorage(m_data->m_calendar);
if (!m_data->m_storage->open()) {
throwError("failed to open storage");
throwError(SE_HERE, "failed to open storage");
}
mKCal::Notebook::List notebookList = m_data->m_storage->notebooks();
mKCal::Notebook::List::Iterator it;
@ -417,7 +417,7 @@ void KCalExtendedSource::beginSync(const std::string &lastToken, const std::stri
// return all items
incidences = m_data->m_calendar->incidences();
// if (!m_data->m_storage->allIncidences(&incidences, m_data->m_notebookUID)) {
// throwError("allIncidences() failed");
// throwError(SE_HERE, "allIncidences() failed");
// }
m_data->extractIncidences(incidences, SyncSourceChanges::ANY, *this);
if (*anchor) {
@ -425,13 +425,13 @@ void KCalExtendedSource::beginSync(const std::string &lastToken, const std::stri
KDateTime endSyncTime(QDateTime::fromString(QString(anchor), Qt::ISODate), KDateTime::Spec::UTC());
KCalCore::Incidence::List added, modified, deleted;
if (!m_data->m_storage->insertedIncidences(&added, endSyncTime, m_data->m_notebookUID)) {
throwError("insertedIncidences() failed");
throwError(SE_HERE, "insertedIncidences() failed");
}
if (!m_data->m_storage->modifiedIncidences(&modified, endSyncTime, m_data->m_notebookUID)) {
throwError("modifiedIncidences() failed");
throwError(SE_HERE, "modifiedIncidences() failed");
}
if (!m_data->m_storage->deletedIncidences(&deleted, endSyncTime, m_data->m_notebookUID)) {
throwError("deletedIncidences() failed");
throwError(SE_HERE, "deletedIncidences() failed");
}
// It is guaranteed that modified and inserted items are
// returned as inserted, so no need to check that.
@ -445,7 +445,7 @@ std::string KCalExtendedSource::endSync(bool success)
{
if (m_data->m_modified) {
if (!m_data->m_storage->save()) {
throwError("could not save calendar");
throwError(SE_HERE, "could not save calendar");
}
time_t modtime = time(NULL);
// Saving set the modified time stamps of all items needed
@ -471,7 +471,7 @@ void KCalExtendedSource::readItem(const string &uid, std::string &item)
{
KCalCore::Incidence::Ptr incidence(m_data->findIncidence(uid));
if (!incidence) {
throwError(string("failure extracting ") + uid);
throwError(SE_HERE, string("failure extracting ") + uid);
}
KCalCore::Calendar::Ptr calendar(new KCalCore::MemoryCalendar(KDateTime::Spec::LocalZone()));
calendar->addIncidence(incidence);
@ -490,7 +490,7 @@ TestingSyncSource::InsertItemResult KCalExtendedSource::insertItem(const string
// deleted yet. To avoid the problem, make sure we save between
// the deletes and the inserts.
if (!m_data->m_storage->save()) {
throwError("could not save calendar");
throwError(SE_HERE, "could not save calendar");
}
m_delete_run = 0;
m_insert_run = 0;
@ -499,11 +499,11 @@ TestingSyncSource::InsertItemResult KCalExtendedSource::insertItem(const string
KCalCore::Calendar::Ptr calendar(new KCalCore::MemoryCalendar(KDateTime::Spec::LocalZone()));
KCalCore::ICalFormat parser;
if (!parser.fromString(calendar, std2qstring(item))) {
throwError("error parsing iCalendar 2.0 item");
throwError(SE_HERE, "error parsing iCalendar 2.0 item");
}
KCalCore::Incidence::List incidences = calendar->rawIncidences();
if (incidences.empty()) {
throwError("iCalendar 2.0 item empty?!");
throwError(SE_HERE, "iCalendar 2.0 item empty?!");
}
InsertItemResultState updated;
string newUID;
@ -542,7 +542,7 @@ TestingSyncSource::InsertItemResult KCalExtendedSource::insertItem(const string
updated = ITEM_OKAY;
if (!m_data->m_calendar->addIncidence(incidence)) {
throwError("could not add incidence");
throwError(SE_HERE, "could not add incidence");
}
m_data->m_calendar->setNotebook(incidence, m_data->m_notebookUID);
newUID = m_data->getItemID(incidence).getLUID();
@ -552,10 +552,10 @@ TestingSyncSource::InsertItemResult KCalExtendedSource::insertItem(const string
newUID = oldUID;
KCalCore::Incidence::Ptr original = m_data->findIncidence(oldUID);
if (!original) {
throwError("incidence to be updated not found");
throwError(SE_HERE, "incidence to be updated not found");
}
if (original->type() != incidence->type()) {
throwError("cannot update incidence, wrong type?!");
throwError(SE_HERE, "cannot update incidence, wrong type?!");
}
// preserve UID and RECURRENCE-ID, because this must not change
@ -590,13 +590,13 @@ void KCalExtendedSource::deleteItem(const string &uid)
{
KCalCore::Incidence::Ptr incidence = m_data->findIncidence(uid);
if (!incidence) {
// throwError(string("incidence ") + uid + " not found");
// throwError(SE_HERE, string("incidence ") + uid + " not found");
// don't treat this as error, it can happen, for example
// when the master event was removed before (MBC #6061)
return;
}
if (!m_data->m_calendar->deleteIncidence(incidence)) {
throwError(string("could not delete incidence") + uid);
throwError(SE_HERE, string("could not delete incidence") + uid);
}
m_data->m_modified = true;
m_delete_run++;
@ -607,7 +607,7 @@ void KCalExtendedSource::listAllItems(RevisionMap_t &revisions)
KCalCore::Incidence::List incidences;
incidences = m_data->m_calendar->incidences();
// if (!m_data->m_storage->allIncidences(&incidences, m_data->m_notebookUID)) {
// throwError("allIncidences() failed");
// throwError(SE_HERE, "allIncidences() failed");
// }
foreach (KCalCore::Incidence::Ptr incidence, incidences) {
if (incidence->type() == m_data->m_type) {

View file

@ -24,7 +24,8 @@
#include "KDEPlatform.h"
#include <syncevo/SyncContext.h>
#include <syncevo/Exception.h>
#include <syncevo/UserInterface.h>
#include <syncevo/SyncConfig.h>
// Qt headers may define "signals" as preprocessor symbol,
@ -232,7 +233,7 @@ bool KWalletSavePasswordSlot(const InitStateTri &keyring,
}
if (!write_success) {
SyncContext::throwError("Saving " + passwordName + " in KWallet failed.");
Exception::throwError(SE_HERE, "Saving " + passwordName + " in KWallet failed.");
}
SE_LOG_DEBUG(NULL, "stored password in KWallet using %s",
key.toString().c_str());

View file

@ -63,14 +63,14 @@ MaemoCalendarSource::MaemoCalendarSource(int EntryType, int EntryFormat,
m_operations);
break;
default:
throwError("invalid calendar type");
throwError(SE_HERE, "invalid calendar type");
break;
}
mc = CMulticalendar::MCInstance();
cal = NULL;
conv = NULL;
if (!mc) {
throwError("Could not connect to Maemo Calendar backend");
throwError(SE_HERE, "Could not connect to Maemo Calendar backend");
}
}
@ -135,7 +135,7 @@ void MaemoCalendarSource::open()
}
if (!cal) {
throwError(string("not found: ") + id);
throwError(SE_HERE, string("not found: ") + id);
}
conv = new ICalConverter;
conv->setSyncing(true); // not sure what this does, but may as well tell the truth
@ -223,7 +223,7 @@ void MaemoCalendarSource::listAllItems(RevisionMap_t &revisions)
CComponent *c = cal->getEntry(id, entry_type, err);
if (!c)
{
throwError(string("retrieving item: ") + id);
throwError(SE_HERE, string("retrieving item: ") + id);
}
revisions[id] = get_revision(c);
delete c;
@ -236,7 +236,7 @@ void MaemoCalendarSource::readItem(const string &uid, std::string &item, bool ra
int err;
CComponent * c = cal->getEntry(uid, entry_type, err);
if (!c) {
throwError(string("retrieving item: ") + uid);
throwError(SE_HERE, string("retrieving item: ") + uid);
}
if (entry_format == -1) {
item = c->getSummary();
@ -246,7 +246,7 @@ void MaemoCalendarSource::readItem(const string &uid, std::string &item, bool ra
}
delete c;
if (err != CALENDAR_OPERATION_SUCCESSFUL) {
throwError(string("generating ical for item: ") + uid);
throwError(SE_HERE, string("generating ical for item: ") + uid);
}
}
@ -260,7 +260,7 @@ TrackingSyncSource::InsertItemResult MaemoCalendarSource::insertItem(const strin
if (cal->getCalendarType() == BIRTHDAY_CALENDAR) {
// stubbornly refuse to try this
throwError(string("can't sync smart calendar ") + cal->getCalendarName());
throwError(SE_HERE, string("can't sync smart calendar ") + cal->getCalendarName());
}
if (entry_format == -1) {
@ -273,9 +273,9 @@ TrackingSyncSource::InsertItemResult MaemoCalendarSource::insertItem(const strin
// barely-legal input (mostly on todo entries), yet a component is returned
if (!comps.size()) {
if (err != CALENDAR_OPERATION_SUCCESSFUL) {
throwError(string("parsing ical: ") + item);
throwError(SE_HERE, string("parsing ical: ") + item);
} else {
throwError(string("no events in ical: ") + item);
throwError(SE_HERE, string("no events in ical: ") + item);
}
}
vector< CComponent * >::iterator it = comps.begin();
@ -283,7 +283,7 @@ TrackingSyncSource::InsertItemResult MaemoCalendarSource::insertItem(const strin
for (; it != comps.end(); ++it) {
delete (*it);
}
throwError(string("too many events in ical: ") + item);
throwError(SE_HERE, string("too many events in ical: ") + item);
}
c = *it;
}
@ -301,7 +301,7 @@ TrackingSyncSource::InsertItemResult MaemoCalendarSource::insertItem(const strin
default: r = false; err = CALENDAR_SYSTEM_ERROR;
}
if (!r) {
throwError(string("updating item ") + uid);
throwError(SE_HERE, string("updating item ") + uid);
}
} else {
switch (entry_type) {
@ -311,7 +311,7 @@ TrackingSyncSource::InsertItemResult MaemoCalendarSource::insertItem(const strin
default: r = false; err = CALENDAR_SYSTEM_ERROR;
}
if (!r) {
throwError(string("creating item "));
throwError(SE_HERE, string("creating item "));
}
if (err == CALENDAR_ENTRY_DUPLICATED) {
u = ITEM_REPLACED;
@ -330,12 +330,12 @@ void MaemoCalendarSource::removeItem(const string &uid)
if (cal->getCalendarType() == BIRTHDAY_CALENDAR) {
// stubbornly refuse to try this
throwError(string("can't sync smart calendar ") + cal->getCalendarName());
throwError(SE_HERE, string("can't sync smart calendar ") + cal->getCalendarName());
}
cal->deleteComponent(uid, err);
if (err != CALENDAR_OPERATION_SUCCESSFUL) {
throwError(string("deleting item: ") + uid);
throwError(SE_HERE, string("deleting item: ") + uid);
}
}

View file

@ -39,6 +39,7 @@
#include <syncevo/GLibSupport.h> // PBAP backend does not compile without GLib.
#include <syncevo/util.h>
#include <syncevo/BoostHelper.h>
#include <src/syncevo/SynthesisEngine.h>
#include "gdbus-cxx-bridge.h"
@ -47,7 +48,6 @@
#include <synthesis/SDK_util.h>
#include <syncevo/SyncContext.h>
#include <syncevo/declarations.h>
SE_BEGIN_CXX
@ -341,7 +341,7 @@ void PbapSession::initSession(const std::string &address, const std::string &for
std::string properties;
const pcrecpp::RE re("(?:(2\\.1|3\\.0):?)?(\\^?)([-a-zA-Z,]*)");
if (!re.FullMatch(format, &version, &tmp, &properties)) {
m_parent.throwError(StringPrintf("invalid specification of PBAP vCard format (databaseFormat): %s",
m_parent.throwError(SE_HERE, StringPrintf("invalid specification of PBAP vCard format (databaseFormat): %s",
format.c_str()));
}
char negated = tmp.c_str()[0];
@ -350,7 +350,7 @@ void PbapSession::initSession(const std::string &address, const std::string &for
version = "2.1";
}
if (version != "2.1" && version != "3.0") {
m_parent.throwError(StringPrintf("invalid vCard version prefix in PBAP vCard format specification (databaseFormat): %s",
m_parent.throwError(SE_HERE, StringPrintf("invalid vCard version prefix in PBAP vCard format specification (databaseFormat): %s",
format.c_str()));
}
std::set<std::string> keywords;
@ -413,7 +413,7 @@ void PbapSession::initSession(const std::string &address, const std::string &for
}
if (session.empty()) {
m_parent.throwError("PBAP: failed to create session");
m_parent.throwError(SE_HERE, "PBAP: failed to create session");
}
if (m_obexAPI != OBEXD_OLD) {
@ -505,7 +505,7 @@ void PbapSession::initSession(const std::string &address, const std::string &for
boost::bind(&boost::iequals<std::string,std::string>, _1, prop, std::locale()));
if (entry == m_filterFields.end()) {
m_parent.throwError(StringPrintf("invalid property name in PBAP vCard format specification (databaseFormat): %s",
m_parent.throwError(SE_HERE, StringPrintf("invalid property name in PBAP vCard format specification (databaseFormat): %s",
prop.c_str()));
}
@ -647,7 +647,7 @@ void PbapSession::checkForError()
Transfers::const_iterator it = m_transfers.find(m_currentTransfer);
if (it != m_transfers.end()) {
if (!it->second.m_transferErrorCode.empty()) {
m_parent.throwError(StringPrintf("%s: %s",
m_parent.throwError(SE_HERE, StringPrintf("%s: %s",
it->second.m_transferErrorCode.c_str(),
it->second.m_transferErrorMsg.c_str()));
}
@ -870,7 +870,7 @@ PbapSyncSource::PbapSyncSource(const SyncSourceParams &params) :
boost::iequals(PBAPSyncMode, "incremental") ? PBAP_SYNC_INCREMENTAL :
boost::iequals(PBAPSyncMode, "text") ? PBAP_SYNC_TEXT :
boost::iequals(PBAPSyncMode, "all") ? PBAP_SYNC_NORMAL :
(throwError(StringPrintf("invalid value for SYNCEVOLUTION_PBAP_SYNC: %s", PBAPSyncMode)), PBAP_SYNC_NORMAL);
(throwError(SE_HERE, StringPrintf("invalid value for SYNCEVOLUTION_PBAP_SYNC: %s", PBAPSyncMode)), PBAP_SYNC_NORMAL);
m_isFirstCycle = true;
m_hadContacts = false;
}
@ -885,7 +885,7 @@ void PbapSyncSource::open()
const string prefix("obex-bt://");
if (!boost::starts_with(database, prefix)) {
throwError("database should specifiy device address (obex-bt://<bt-addr>)");
throwError(SE_HERE, "database should specifiy device address (obex-bt://<bt-addr>)");
}
std::string address = database.substr(prefix.size());
@ -896,7 +896,7 @@ void PbapSyncSource::open()
void PbapSyncSource::beginSync(const std::string &lastToken, const std::string &resumeToken)
{
if (!lastToken.empty()) {
throwError(STATUS_SLOW_SYNC_508, std::string("PBAP cannot do change detection"));
throwError(SE_HERE, STATUS_SLOW_SYNC_508, std::string("PBAP cannot do change detection"));
}
}
@ -987,7 +987,7 @@ sysync::TSyError PbapSyncSource::readNextItem(sysync::ItemID aID,
PULL_AS_CONFIGURED);
}
if (!m_pullAll) {
throwError("logic error: readNextItem without aFirst=true before");
throwError(SE_HERE, "logic error: readNextItem without aFirst=true before");
}
std::string id = m_pullAll->getNextID();
if (id.empty()) {
@ -1010,7 +1010,7 @@ sysync::TSyError PbapSyncSource::readNextItem(sysync::ItemID aID,
sysync::TSyError PbapSyncSource::readItemAsKey(sysync::cItemID aID, sysync::KeyH aItemKey)
{
if (!m_pullAll) {
throwError("logic error: readItemAsKey() without preceeding readNextItem()");
throwError(SE_HERE, "logic error: readItemAsKey() without preceeding readNextItem()");
}
pcrecpp::StringPiece vcard;
if (m_pullAll->getContact(atoi(aID->item), vcard)) {
@ -1022,20 +1022,20 @@ sysync::TSyError PbapSyncSource::readItemAsKey(sysync::cItemID aID, sysync::KeyH
SyncSourceRaw::InsertItemResult PbapSyncSource::insertItemRaw(const std::string &luid, const std::string &item)
{
throwError("writing via PBAP is not supported");
throwError(SE_HERE, "writing via PBAP is not supported");
return InsertItemResult();
}
void PbapSyncSource::readItemRaw(const std::string &luid, std::string &item)
{
if (!m_pullAll) {
throwError("logic error: readItemRaw() without preceeding readNextItem()");
throwError(SE_HERE, "logic error: readItemRaw() without preceeding readNextItem()");
}
pcrecpp::StringPiece vcard;
if (m_pullAll->getContact(atoi(luid.c_str()), vcard)) {
item.assign(vcard.data(), vcard.size());
} else {
throwError(STATUS_NOT_FOUND, string("retrieving item: ") + luid);
throwError(SE_HERE, STATUS_NOT_FOUND, string("retrieving item: ") + luid);
}
}

View file

@ -350,7 +350,7 @@ public:
void checkError(const char *op, T &req)
{
if (req.error()) {
m_parent->throwError(StringPrintf("%s: failed with error %d", op, req.error()));
m_parent->throwError(SE_HERE, StringPrintf("%s: failed with error %d", op, req.error()));
}
}
template<class T>
@ -365,7 +365,7 @@ public:
foreach (int index, errors.keys()) {
res.push_back(StringPrintf("entry #%d failed with error %d", index, errors[index]));
}
m_parent->throwError(StringPrintf("%s: failed with error %d, ", op, req.error()) +
m_parent->throwError(SE_HERE, StringPrintf("%s: failed with error %d, ", op, req.error()) +
boost::join(res, ", "));
}
}
@ -398,7 +398,7 @@ void QtContactsSource::open()
cxxptr<QContactManager> manager(QContactManager::fromUri(m_data->m_managerURI),
"QTContactManager");
if (manager->error()) {
throwError(StringPrintf("failed to open QtContact database %s, error code %d",
throwError(SE_HERE, StringPrintf("failed to open QtContact database %s, error code %d",
m_data->m_managerURI.toLocal8Bit().constData(),
manager->error()));
}
@ -528,12 +528,12 @@ void QtContactsSource::readItem(const string &uid, std::string &item, bool raw)
QVersitContactExporter exporter(profiles);
exporter.setDetailHandler(&handler);
if (!exporter.exportContacts(contacts, QVersitDocument::VCard30Type)) {
throwError(uid + ": encoding as vCard 3.0 failed");
throwError(SE_HERE, uid + ": encoding as vCard 3.0 failed");
}
QByteArray vcard;
QVersitWriter writer(&vcard);
if (!writer.startWriting(exporter.documents())) {
throwError(uid + ": writing as vCard 3.0 failed");
throwError(SE_HERE, uid + ": writing as vCard 3.0 failed");
}
writer.waitForFinished();
item = vcard.constData();
@ -544,7 +544,7 @@ TrackingSyncSource::InsertItemResult QtContactsSource::insertItem(const string &
{
QVersitReader reader(QByteArray(item.c_str()));
if (!reader.startReading()) {
throwError("reading vCard failed");
throwError(SE_HERE, "reading vCard failed");
}
reader.waitForFinished();
m_data->checkError("decoding vCard", reader);
@ -559,7 +559,7 @@ TrackingSyncSource::InsertItemResult QtContactsSource::insertItem(const string &
QVersitContactImporter importer(profiles);
importer.setPropertyHandler(&handler);
if (!importer.importDocuments(reader.results())) {
throwError("importing vCard failed");
throwError(SE_HERE, "importing vCard failed");
}
QList<QContact> contacts = importer.contacts();

View file

@ -239,7 +239,7 @@ boost::shared_ptr<AuthProvider> createSignonAuthProvider(const InitStateString &
GErrorCXX gerror;
AgAccountCXX account(ag_manager_load_account(manager, accountID, gerror), TRANSFER_REF);
if (!account) {
gerror.throwError(StringPrintf("loading account with ID %d from %s failed",
gerror.throwError(SE_HERE, StringPrintf("loading account with ID %d from %s failed",
accountID,
username.c_str()));
}
@ -312,7 +312,7 @@ boost::shared_ptr<AuthProvider> createSignonAuthProvider(const InitStateString &
SYNCEVO_GLIB_CALL_SYNC(res, gerror, ag_account_store_async,
account, NULL);
if (!res) {
gerror.throwError("failed to store account");
gerror.throwError(SE_HERE, "failed to store account");
}
authData = AgAuthDataCXX::steal(ag_account_service_get_auth_data(accountService));

View file

@ -199,7 +199,7 @@ void SQLiteContactSource::getSynthesisInfo(SynthesisInfo &info, XMLConfigFragmen
" <use datatype='vCard21' mode='rw'/>\n";
}
} else {
throwError(string("configured MIME type not supported: ") + type);
throwError(SE_HERE, string("configured MIME type not supported: ") + type);
}
}
@ -241,7 +241,7 @@ sysync::TSyError SQLiteContactSource::readItemAsKey(sysync::cItemID aID, sysync:
sqliteptr contact(m_sqlite.prepareSQL("SELECT * FROM ABPerson WHERE ROWID = '%s';", uid.c_str()));
if (m_sqlite.checkSQL(sqlite3_step(contact)) != SQLITE_ROW) {
throwError(STATUS_NOT_FOUND, string("contact not found: ") + uid);
throwError(SE_HERE, STATUS_NOT_FOUND, string("contact not found: ") + uid);
}
for (int i = 0; i<LAST_COL; i++) {

View file

@ -33,7 +33,7 @@
#include <syncevo/declarations.h>
SE_BEGIN_CXX
void SQLiteUtil::throwError(const string &operation)
void SQLiteUtil::throwError(const SourceLocation &here, const string &operation)
{
string descr = m_name + ": '" + m_fileid + "': " + operation + " failed";
@ -43,7 +43,7 @@ void SQLiteUtil::throwError(const string &operation)
descr += error ? error : "unspecified error";
}
throw runtime_error(descr);
Exception::throwError(here, descr);
}
sqlite3_stmt *SQLiteUtil::prepareSQLWrapper(const char *sql, const char **nextsql)
@ -151,14 +151,14 @@ void SQLiteUtil::open(const string &name,
} else if (res == SQLITE_ROW) {
// continue
} else {
throwError("creating database");\
throwError(SE_HERE, "creating database");\
}
}
}
break;
}
default:
throwError("checking content");
throwError(SE_HERE, "checking content");
break;
}

View file

@ -24,6 +24,7 @@
#include <sqlite3.h>
#include <syncevo/SmartPtr.h>
#include <syncevo/Exception.h>
#include <string>
#include <stdio.h>
@ -78,7 +79,7 @@ class SQLiteUtil
* throw error for a specific sqlite3 operation on m_db
* @param operation a description of the operation which failed
*/
void throwError(const string &operation);
void throwError(const SourceLocation &where, const string &operation);
/**
* wrapper around sqlite3_prepare() which operates on the current
@ -101,7 +102,7 @@ class SQLiteUtil
/** checks the result of an sqlite3 call, throws an error if faulty, otherwise returns the result */
int checkSQL(int res, const char *operation = "SQLite call") {
if (res != SQLITE_OK && res != SQLITE_ROW && res != SQLITE_DONE) {
throwError(operation);
throwError(SE_HERE, operation);
}
return res;
}

View file

@ -898,7 +898,7 @@ std::string CalDAVSource::removeSubItem(const string &davLUID, const std::string
EventCache::iterator it = m_cache.find(davLUID);
if (it == m_cache.end()) {
// gone already
throwError(STATUS_NOT_FOUND, "deleting item: " + davLUID);
throwError(SE_HERE, STATUS_NOT_FOUND, "deleting item: " + davLUID);
return "";
}
// use item as it is, load only if it is not going to be removed entirely
@ -911,7 +911,7 @@ std::string CalDAVSource::removeSubItem(const string &davLUID, const std::string
davLUID.c_str(),
SubIDName(subid).c_str(),
SubIDName(*event.m_subids.begin()).c_str());
throwError(STATUS_NOT_FOUND, "remove sub-item: " + SubIDName(subid) + " in " + davLUID);
throwError(SE_HERE, STATUS_NOT_FOUND, "remove sub-item: " + SubIDName(subid) + " in " + davLUID);
return event.m_etag;
} else {
try {
@ -991,7 +991,7 @@ std::string CalDAVSource::removeSubItem(const string &davLUID, const std::string
}
}
if (!found) {
throwError(STATUS_NOT_FOUND, "remove sub-item: " + SubIDName(subid) + " in " + davLUID);
throwError(SE_HERE, STATUS_NOT_FOUND, "remove sub-item: " + SubIDName(subid) + " in " + davLUID);
return event.m_etag;
}
event.m_subids.erase(subid);
@ -1120,7 +1120,7 @@ CalDAVSource::Event &CalDAVSource::findItem(const std::string &davLUID)
{
EventCache::iterator it = m_cache.find(davLUID);
if (it == m_cache.end()) {
throwError(STATUS_NOT_FOUND, "finding item: " + davLUID);
throwError(SE_HERE, STATUS_NOT_FOUND, "finding item: " + davLUID);
}
return *it->second;
}

View file

@ -571,7 +571,7 @@ void WebDAVSource::contactServer()
boost::ref(m_calendar),
_1, _2));
if (m_calendar.empty()) {
throwError("no database found");
throwError(SE_HERE, "no database found");
}
SE_LOG_DEBUG(NULL, "picked final path %s", m_calendar.m_path.c_str());
@ -641,7 +641,7 @@ bool WebDAVSource::findCollections(const boost::function<bool (const std::string
size_t pos = username.find('@');
if (pos == username.npos) {
// throw authentication error to indicate that the credentials are wrong
throwError(STATUS_UNAUTHORIZED, StringPrintf("syncURL not configured and username %s does not contain a domain", username.c_str()));
throwError(SE_HERE, STATUS_UNAUTHORIZED, StringPrintf("syncURL not configured and username %s does not contain a domain", username.c_str()));
}
std::string domain = username.substr(pos + 1);
@ -655,7 +655,7 @@ bool WebDAVSource::findCollections(const boost::function<bool (const std::string
domain.c_str()).c_str(),
"r");
if (!in) {
throwError("syncURL not configured and starting syncevo-webdav-lookup for DNS SRV lookup failed", errno);
throwError(SE_HERE, "syncURL not configured and starting syncevo-webdav-lookup for DNS SRV lookup failed", errno);
}
// ridicuously long URLs are truncated...
char buffer[1024];
@ -673,10 +673,10 @@ bool WebDAVSource::findCollections(const boost::function<bool (const std::string
case 0:
break;
case 2:
throwError(StringPrintf("syncURL not configured and syncevo-webdav-lookup did not find a DNS utility to search for %s in %s", serviceType().c_str(), domain.c_str()));
throwError(SE_HERE, StringPrintf("syncURL not configured and syncevo-webdav-lookup did not find a DNS utility to search for %s in %s", serviceType().c_str(), domain.c_str()));
break;
case 3:
throwError(StringPrintf("syncURL not configured and DNS SRV search for %s in %s did not find the service", serviceType().c_str(), domain.c_str()));
throwError(SE_HERE, StringPrintf("syncURL not configured and DNS SRV search for %s in %s did not find the service", serviceType().c_str(), domain.c_str()));
break;
default: {
Timespec now = Timespec::monotonic();
@ -693,7 +693,7 @@ bool WebDAVSource::findCollections(const boost::function<bool (const std::string
}
// probably network problem
throwError(STATUS_TRANSPORT_FAILURE, StringPrintf("syncURL not configured and DNS SRV search for %s in %s failed", serviceType().c_str(), domain.c_str()));
throwError(SE_HERE, STATUS_TRANSPORT_FAILURE, StringPrintf("syncURL not configured and DNS SRV search for %s in %s failed", serviceType().c_str(), domain.c_str()));
break;
}
}
@ -1196,7 +1196,7 @@ bool WebDAVSource::findCollections(const boost::function<bool (const std::string
counter++;
if (counter > limit) {
throwError(StringPrintf("giving up search for collection after %d attempts", limit));
throwError(SE_HERE, StringPrintf("giving up search for collection after %d attempts", limit));
}
path = next;
}

View file

@ -36,11 +36,11 @@ XMLRPCSyncSource::XMLRPCSyncSource(const SyncSourceParams &params,
TrackingSyncSource(params)
{
if (dataformat.empty()) {
throwError("a data format must be specified");
throwError(SE_HERE, "a data format must be specified");
}
size_t sep = dataformat.find(':');
if (sep == dataformat.npos) {
throwError(string("data format not specified as <mime type>:<mime version>: " + dataformat));
throwError(SE_HERE, string("data format not specified as <mime type>:<mime version>: " + dataformat));
}
m_mimeType.assign(dataformat, 0, sep);
m_mimeVersion = dataformat.substr(sep + 1);

View file

@ -139,7 +139,7 @@ int main(int argc, char **argv, char **envp)
bool success = g_option_context_parse(context, &argc, &argv, gerror);
PlainGStr durationOwner(durationString);
if (!success) {
gerror.throwError("parsing command line options");
gerror.throwError(SE_HERE, "parsing command line options");
}
if (durationString && !parseDuration(duration, durationString)) {
SE_THROW(StringPrintf("invalid parameter value '%s' for --duration/-d: must be positive number of seconds or 'unlimited'", durationString));

View file

@ -347,7 +347,7 @@ void IndividualAggregator::addContactDone(const GError *gerror,
try {
// Handle result of folks_persona_store_add_persona_from_details().
if (!persona || gerror) {
GErrorCXX::throwError("add contact", gerror);
GErrorCXX::throwError(SE_HERE, "add contact", gerror);
}
const gchar *uid = folks_persona_get_uid(persona);
@ -422,7 +422,7 @@ void IndividualAggregator::removeContactDone(const GError *gerror,
{
try {
if (gerror) {
GErrorCXX::throwError("remove contact", gerror);
GErrorCXX::throwError(SE_HERE, "remove contact", gerror);
}
result.done();
} catch (...) {
@ -488,7 +488,7 @@ void IndividualAggregator::runWithAddressBookPrepared(const GError *gerror,
try {
// Called after EDS system store is prepared, successfully or unsuccessfully.
if (gerror) {
GErrorCXX::throwError("prepare EDS system address book", gerror);
GErrorCXX::throwError(SE_HERE, "prepare EDS system address book", gerror);
}
operation();
} catch (...) {

View file

@ -692,7 +692,7 @@ static void Details2PersonaStep(const GError *gerror, const boost::shared_ptr<Pe
{
try {
if (gerror) {
GErrorCXX::throwError("modifying property", gerror);
GErrorCXX::throwError(SE_HERE, "modifying property", gerror);
}
size_t current = pending->m_current++;
if (current < pending->m_changes.size()) {

View file

@ -888,7 +888,7 @@ void Manager::searchWithRegistry(const ESourceRegistryCXX &registry,
{
try {
if (!registry) {
GErrorCXX::throwError("create ESourceRegistry", gerror);
GErrorCXX::throwError(SE_HERE, "create ESourceRegistry", gerror);
}
doSearch(registry,
result,

View file

@ -133,7 +133,7 @@ int main(int argc, char **argv, char **envp)
g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
bool success = g_option_context_parse(context, &argc, &argv, gerror);
if (!success) {
gerror.throwError("parsing command line options");
gerror.throwError(SE_HERE, "parsing command line options");
}
if (debug) {

View file

@ -314,7 +314,7 @@ boost::shared_ptr<DBusServerCXX> DBusServerCXX::listen(const NewConnection_t &ne
gerror),
false);
if (!connection) {
gerror.throwError("creating GIO D-Bus connection");
gerror.throwError(SE_HERE, "creating GIO D-Bus connection");
}
// A fake DBusServerCXX which does nothing more than return the address, aka

View file

@ -277,7 +277,7 @@ bool Cmdline::parse(vector<string> &parsed)
dir = ".";
}
if (!relToAbs(dir)) {
SyncContext::throwError(dir, errno);
Exception::throwError(SE_HERE, dir, errno);
}
m_itemPath = dir + "/" + file;
}
@ -688,7 +688,7 @@ static void ExportLUID(SyncSourceRaw *raw,
file << item;
file.close();
if (file.bad()) {
SyncContext::throwError(fullPath, errno);
Exception::throwError(SE_HERE, fullPath, errno);
}
} else {
std::string delimiter;
@ -920,7 +920,7 @@ bool Cmdline::run() {
return false;
}
if (m_dryrun) {
SyncContext::throwError("--dry-run not supported for configuration changes");
Exception::throwError(SE_HERE, "--dry-run not supported for configuration changes");
}
// name of renamed config ("foo.old") after migration
@ -1279,7 +1279,7 @@ bool Cmdline::run() {
// abort if the user explicitly asked for the sync source
// and it cannot be enabled, otherwise disable it silently
if (selected) {
SyncContext::throwError(source + ": " + disable);
Exception::throwError(SE_HERE, source + ": " + disable);
}
syncMode = "disabled";
} else if (selected) {
@ -1295,7 +1295,7 @@ bool Cmdline::run() {
}
if (!sources.empty()) {
SyncContext::throwError(string("no such source(s): ") + boost::join(sources, " "));
Exception::throwError(SE_HERE, string("no such source(s): ") + boost::join(sources, " "));
}
}
@ -1316,7 +1316,7 @@ bool Cmdline::run() {
return false;
}
if (m_dryrun) {
SyncContext::throwError("--dry-run not supported for removing configurations");
Exception::throwError(SE_HERE, "--dry-run not supported for removing configurations");
}
// extra sanity check
@ -1328,7 +1328,7 @@ bool Cmdline::run() {
boost::shared_ptr<SyncConfig> config;
config.reset(new SyncConfig(m_server));
if (!config->exists()) {
SyncContext::throwError(string("no such configuration: ") + m_server);
Exception::throwError(SE_HERE, string("no such configuration: ") + m_server);
}
config->remove();
m_configModified = true;
@ -1376,7 +1376,7 @@ bool Cmdline::run() {
if (!sourceConfig.getBackend().wasSet()) {
explanation.push_back("backend property not set");
}
SyncContext::throwError(SyncMLStatus(sysync::LOCERR_CFGPARSE),
Exception::throwError(SE_HERE, SyncMLStatus(sysync::LOCERR_CFGPARSE),
boost::join(explanation, "\n"));
} else {
throw;
@ -1397,7 +1397,7 @@ bool Cmdline::run() {
SyncSourceLogging *logging = dynamic_cast<SyncSourceLogging *>(source.get());
if (!ops.m_startDataRead ||
!ops.m_readNextItem) {
source->throwError("reading items not supported");
source->throwError(SE_HERE, "reading items not supported");
}
err = ops.m_startDataRead(*source, "", "");
@ -1406,7 +1406,7 @@ bool Cmdline::run() {
processLUIDs(source, boost::bind(ShowLUID, logging, _1));
} else if (m_deleteItems) {
if (!ops.m_deleteItem) {
source->throwError("deleting items not supported");
source->throwError(SE_HERE, "deleting items not supported");
}
list<string> luids;
bool deleteAll = std::find(m_luids.begin(), m_luids.end(), "*") != m_luids.end();
@ -1440,7 +1440,7 @@ bool Cmdline::run() {
} else {
SyncSourceRaw *raw = dynamic_cast<SyncSourceRaw *>(source.get());
if (!raw) {
source->throwError("reading/writing items directly not supported");
source->throwError(SE_HERE, "reading/writing items directly not supported");
}
if (m_import || m_update) {
err = ops.m_startDataRead(*source, "", "");
@ -1462,12 +1462,12 @@ bool Cmdline::run() {
if (m_itemPath == "-") {
context->getUserInterfaceNonNull().readStdin(content);
} else if (!ReadFile(m_itemPath, content)) {
SyncContext::throwError(m_itemPath, errno);
Exception::throwError(SE_HERE, m_itemPath, errno);
}
if (m_delimiter == "none") {
if (m_update) {
if (m_luids.size() != 1) {
SyncContext::throwError("need exactly one LUID parameter");
Exception::throwError(SE_HERE, "need exactly one LUID parameter");
} else {
luid = *m_luids.begin();
}
@ -1489,7 +1489,7 @@ bool Cmdline::run() {
total++;
}
if (total != m_luids.size()) {
SyncContext::throwError(StringPrintf("%lu items != %lu luids, must match => aborting",
Exception::throwError(SE_HERE, StringPrintf("%lu items != %lu luids, must match => aborting",
total, (unsigned long)m_luids.size()));
}
}
@ -1502,7 +1502,7 @@ bool Cmdline::run() {
if (m_update) {
if (luidit == m_luids.end()) {
// was checked above
SyncContext::throwError("internal error, not enough luids");
Exception::throwError(SE_HERE, "internal error, not enough luids");
}
luid = *luidit;
++luidit;
@ -1522,7 +1522,7 @@ bool Cmdline::run() {
string content;
string path = m_itemPath + "/" + entry;
if (!ReadFile(path, content)) {
SyncContext::throwError(path, errno);
Exception::throwError(SE_HERE, path, errno);
}
std::string luid;
if (m_update) {
@ -1580,7 +1580,7 @@ bool Cmdline::run() {
if (outFile) {
outFile->close();
if (outFile->bad()) {
SyncContext::throwError(m_itemPath, errno);
Exception::throwError(SE_HERE, m_itemPath, errno);
}
}
}
@ -1650,7 +1650,7 @@ bool Cmdline::run() {
// check whether there were any sources specified which do not exist
if (!unmatchedSources.empty()) {
context->throwError(string("no such source(s): ") + boost::join(unmatchedSources, " "));
Exception::throwError(SE_HERE, string("no such source(s): ") + boost::join(unmatchedSources, " "));
}
if (m_status) {
@ -2045,7 +2045,7 @@ void Cmdline::checkForPeerProps()
// legacy "sync" property, which applies to both shared and unshared
// properties => cannot determine that here anymore, so ignore it
} else {
SyncContext::throwError(string("per-peer (unshared) properties not allowed: ") +
Exception::throwError(SE_HERE, string("per-peer (unshared) properties not allowed: ") +
props);
}
}

View file

@ -62,7 +62,7 @@ string CmdlineSyncClient::askPassword(const string &passwordName,
}
password = std::string(buffer);
} else {
throwError(string("could not read password for ") + descr);
Exception::throwError(SE_HERE, string("could not read password for ") + descr);
}
return password;
@ -84,7 +84,7 @@ bool CmdlineSyncClient::savePassword(const string &passwordName,
void CmdlineSyncClient::readStdin(string &content)
{
if (!ReadFile(cin, content)) {
throwError("stdin", errno);
Exception::throwError(SE_HERE, "stdin", errno);
}
}

View file

@ -140,7 +140,7 @@ class EDSRegistryLoader : private boost::noncopyable
return m_registry;
}
if (m_gerror) {
m_gerror.throwError("creating source registry");
m_gerror.throwError(SE_HERE, "creating source registry");
}
return m_registry;
}

164
src/syncevo/Exception.cpp Normal file
View file

@ -0,0 +1,164 @@
/*
* Copyright (C) 2008-2009 Patrick Ohly <patrick.ohly@gmx.de>
* Copyright (C) 2014 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#include <syncevo/Exception.h>
#include <src/syncevo/SynthesisEngine.h>
#include <synthesis/syerror.h>
#include "gdbus-cxx-bridge.h"
#include <pcrecpp.h>
#include <errno.h>
SE_BEGIN_CXX
static const char * const TRANSPORT_PROBLEM = "transport problem: ";
static const char * const SYNTHESIS_PROBLEM = "error code from Synthesis engine ";
static const char * const SYNCEVOLUTION_PROBLEM = "error code from SyncEvolution ";
SyncMLStatus Exception::handle(SyncMLStatus *status,
const std::string *logPrefix,
std::string *explanation,
Logger::Level level,
HandleExceptionFlags flags)
{
// any problem here is a fatal local problem, unless set otherwise
// by the specific exception
SyncMLStatus new_status = SyncMLStatus(STATUS_FATAL + sysync::LOCAL_STATUS_CODE);
std::string error;
try {
throw;
} catch (const TransportException &ex) {
SE_LOG_DEBUG(logPrefix, "TransportException thrown at %s:%d",
ex.m_file.c_str(), ex.m_line);
error = std::string(TRANSPORT_PROBLEM) + ex.what();
new_status = SyncMLStatus(sysync::LOCERR_TRANSPFAIL);
} catch (const BadSynthesisResult &ex) {
new_status = SyncMLStatus(ex.result());
error = StringPrintf("%s%s",
SYNTHESIS_PROBLEM,
Status2String(new_status).c_str());
} catch (const StatusException &ex) {
new_status = ex.syncMLStatus();
SE_LOG_DEBUG(logPrefix, "exception thrown at %s:%d",
ex.m_file.c_str(), ex.m_line);
error = StringPrintf("%s%s: %s",
SYNCEVOLUTION_PROBLEM,
Status2String(new_status).c_str(), ex.what());
if (new_status == STATUS_NOT_FOUND &&
(flags & HANDLE_EXCEPTION_404_IS_OKAY)) {
level = Logger::DEBUG;
}
} catch (const Exception &ex) {
SE_LOG_DEBUG(logPrefix, "exception thrown at %s:%d",
ex.m_file.c_str(), ex.m_line);
error = ex.what();
} catch (const std::exception &ex) {
error = ex.what();
} catch (...) {
error = "unknown error";
}
if (flags & HANDLE_EXCEPTION_FATAL) {
level = Logger::ERROR;
}
if (flags & HANDLE_EXCEPTION_NO_ERROR) {
level = Logger::DEBUG;
}
SE_LOG(logPrefix, level, "%s", error.c_str());
if (flags & HANDLE_EXCEPTION_FATAL) {
// Something unexpected went wrong, can only shut down.
::abort();
}
if (explanation) {
*explanation = error;
}
if (status && *status == STATUS_OK) {
*status = new_status;
}
return status ? *status : new_status;
}
void Exception::tryRethrow(const std::string &explanation, bool mustThrow)
{
static const std::string statusre = ".* \\((?:local|remote), status (\\d+)\\)";
int status;
if (boost::starts_with(explanation, TRANSPORT_PROBLEM)) {
SE_THROW_EXCEPTION(TransportException, explanation.substr(strlen(TRANSPORT_PROBLEM)));
} else if (boost::starts_with(explanation, SYNTHESIS_PROBLEM)) {
static const pcrecpp::RE re(statusre);
if (re.FullMatch(explanation.substr(strlen(SYNTHESIS_PROBLEM)), &status)) {
SE_THROW_EXCEPTION_1(BadSynthesisResult, "Synthesis engine failure", (sysync::TSyErrorEnum)status);
}
} else if (boost::starts_with(explanation, SYNCEVOLUTION_PROBLEM)) {
static const pcrecpp::RE re(statusre + ": (.*)",
pcrecpp::RE_Options().set_dotall(true));
std::string details;
if (re.FullMatch(explanation.substr(strlen(SYNCEVOLUTION_PROBLEM)), &status, &details)) {
SE_THROW_EXCEPTION_STATUS(StatusException, details, (SyncMLStatus)status);
}
}
if (mustThrow) {
throw std::runtime_error(explanation);
}
}
void Exception::tryRethrowDBus(const std::string &error)
{
static const pcrecpp::RE re("(org\\.syncevolution(?:\\.\\w+)+): (.*)",
pcrecpp::RE_Options().set_dotall(true));
std::string exName, explanation;
if (re.FullMatch(error, &exName, &explanation)) {
// found SyncEvolution exception explanation, parse it
tryRethrow(explanation);
// explanation not parsed, fall back to D-Bus exception
throw GDBusCXX::dbus_error(exName, explanation);
}
}
void Exception::throwError(const SourceLocation &where, const std::string &error)
{
throwError(where, SyncMLStatus(STATUS_FATAL + sysync::LOCAL_STATUS_CODE), error);
}
void Exception::throwError(const SourceLocation &where, SyncMLStatus status, const std::string &error)
{
throw StatusException(where.m_file, where.m_line, error, status);
}
void Exception::throwError(const SourceLocation &where, const std::string &action, int error)
{
std::string what = action + ": " + strerror(error);
// be as specific if we can be: relevant for the file backend,
// which is expected to return STATUS_NOT_FOUND == 404 for "file
// not found"
if (error == ENOENT) {
throwError(where, STATUS_NOT_FOUND, what);
} else {
throwError(where, what);
}
}
void Exception::fatalError(void *object, const char *error)
{
SE_LOG_ERROR(NULL, "%s", error);
exit(1);
}
SE_END_CXX

228
src/syncevo/Exception.h Normal file
View file

@ -0,0 +1,228 @@
/*
* Copyright (C) 2008-2009 Patrick Ohly <patrick.ohly@gmx.de>
* Copyright (C) 2014 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) version 3.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*/
#ifndef INCL_SYNCEVOLUTION_EXCEPTION
# define INCL_SYNCEVOLUTION_EXCEPTION
#include <syncevo/Logging.h>
#include <syncevo/SyncML.h>
#include <string>
#include <syncevo/declarations.h>
SE_BEGIN_CXX
/** Encapsulates source information. */
class SourceLocation
{
public:
const char *m_file;
int m_line;
SourceLocation(const char *file, int line) :
m_file(file),
m_line(line)
{}
};
/** Convenience macro to create a SourceLocation for the current location. */
#define SE_HERE SyncEvo::SourceLocation(__FILE__, __LINE__)
enum HandleExceptionFlags {
HANDLE_EXCEPTION_FLAGS_NONE = 0,
/**
* a 404 status error is possible and must not be logged as ERROR
*/
HANDLE_EXCEPTION_404_IS_OKAY = 1 << 0,
HANDLE_EXCEPTION_FATAL = 1 << 1,
/**
* don't log exception as ERROR
*/
HANDLE_EXCEPTION_NO_ERROR = 1 << 2,
HANDLE_EXCEPTION_MAX = 1 << 3,
};
/**
* an exception which records the source file and line
* where it was thrown
*
* @TODO add function name
*/
class Exception : public std::runtime_error
{
public:
Exception(const std::string &file,
int line,
const std::string &what) :
std::runtime_error(what),
m_file(file),
m_line(line)
{}
~Exception() throw() {}
const std::string m_file;
const int m_line;
/**
* Convenience function, to be called inside a catch(..) block.
*
* Rethrows the exception to determine what it is, then logs it
* at the chosen level (error by default).
*
* Turns certain known exceptions into the corresponding
* status code if status still was STATUS_OK when called.
* Returns updated status code.
*
* @param logPrefix passed to SE_LOG* messages
* @retval explanation set to explanation for problem, if non-NULL
* @param level level to be used for logging
*/
static SyncMLStatus handle(SyncMLStatus *status = NULL, const std::string *logPrefix = NULL, std::string *explanation = NULL, Logger::Level = Logger::ERROR, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE);
static SyncMLStatus handle(const std::string &logPrefix, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE) { return handle(NULL, &logPrefix, NULL, Logger::ERROR, flags); }
static SyncMLStatus handle(std::string &explanation, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE) { return handle(NULL, NULL, &explanation, Logger::ERROR, flags); }
static void handle(HandleExceptionFlags flags) { handle(NULL, NULL, NULL, Logger::ERROR, flags); }
static void log() { handle(NULL, NULL, NULL, Logger::DEBUG); }
/**
* Tries to identify exception class based on explanation string created by
* handle(). If successful, that exception is throw with the same
* attributes as in the original exception.
*
* If not, tryRethrow() returns (mustThrow false) or throws a std::runtime_error
* with the explanation as text.
*/
static void tryRethrow(const std::string &explanation, bool mustThrow = false);
/**
* Same as tryRethrow() for strings with a 'org.syncevolution.xxxx:' prefix,
* as passed as D-Bus error strings.
*/
static void tryRethrowDBus(const std::string &error);
/**
* throws a StatusException with a local, fatal error with the given string
* or (on the iPhone, where exception handling is not
* supported by the toolchain) prints an error directly
* and aborts
*
* output format: <error>
*
* @param error a string describing the error
*/
static void throwError(const SourceLocation &where, const std::string &error) SE_NORETURN;
/**
* throw an exception with a specific status code after an operation failed and
* remember that this instance has failed
*
* output format: <failure>
*
* @param status a more specific status code; other throwError() variants
* use STATUS_FATAL + sysync::LOCAL_STATUS_CODE, which is interpreted
* as a fatal local error
* @param action a string describing what was attempted *and* how it failed
*/
static void throwError(const SourceLocation &where, SyncMLStatus status, const std::string &failure) SE_NORETURN;
/**
* throw an exception after an operation failed and
* remember that this instance has failed
*
* output format: <action>: <error string>
*
* @Param action a string describing the operation or object involved
* @param error the errno error code for the failure
*/
static void throwError(const SourceLocation &where, const std::string &action, int error) SE_NORETURN;
/**
* An error handler which prints the error message and then
* stops the program. Never returns.
*
* The API was chosen so that it can be used as libebook/libecal
* "backend-dies" signal handler.
*/
static void fatalError(void *object, const char *error) SE_NORETURN;
};
/**
* StatusException by wrapping a SyncML status
*/
class StatusException : public Exception
{
public:
StatusException(const std::string &file,
int line,
const std::string &what,
SyncMLStatus status)
: Exception(file, line, what), m_status(status)
{}
SyncMLStatus syncMLStatus() const { return m_status; }
protected:
SyncMLStatus m_status;
};
class TransportException : public Exception
{
public:
TransportException(const std::string &file,
int line,
const std::string &what) :
Exception(file, line, what) {}
~TransportException() throw() {}
};
class TransportStatusException : public StatusException
{
public:
TransportStatusException(const std::string &file,
int line,
const std::string &what,
SyncMLStatus status) :
StatusException(file, line, what, status) {}
~TransportStatusException() throw() {}
};
/** throw a normal SyncEvolution Exception, including source information */
#define SE_THROW(_what) \
SE_THROW_EXCEPTION(Exception, _what)
/** throw a class which accepts file, line, what parameters */
#define SE_THROW_EXCEPTION(_class, _what) \
throw _class(__FILE__, __LINE__, _what)
/** throw a class which accepts file, line, what plus 1 additional parameter */
#define SE_THROW_EXCEPTION_1(_class, _what, _x1) \
throw _class(__FILE__, __LINE__, (_what), (_x1))
/** throw a class which accepts file, line, what plus 2 additional parameters */
#define SE_THROW_EXCEPTION_2(_class, _what, _x1, _x2) \
throw _class(__FILE__, __LINE__, (_what), (_x1), (_x2))
/** throw a class which accepts file, line, what plus 2 additional parameters */
#define SE_THROW_EXCEPTION_3(_class, _what, _x1, _x2, _x3) \
throw _class(__FILE__, __LINE__, (_what), (_x1), (_x2), (_x3))
/** throw a class which accepts file, line, what plus 2 additional parameters */
#define SE_THROW_EXCEPTION_4(_class, _what, _x1, _x2, _x3, _x4) \
throw _class(__FILE__, __LINE__, (_what), (_x1), (_x2), (_x3), (_x4))
/** throw a class which accepts file, line, what parameters and status parameters*/
#define SE_THROW_EXCEPTION_STATUS(_class, _what, _status) \
throw _class(__FILE__, __LINE__, _what, _status)
SE_END_CXX
#endif // INCL_SYNCEVOLUTION_EXCEPTION

View file

@ -18,7 +18,7 @@
*/
#include <syncevo/FilterConfigNode.h>
#include <syncevo/SyncContext.h>
#include <syncevo/Exception.h>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/join.hpp>
@ -41,7 +41,7 @@ FilterConfigNode::FilterConfigNode(const boost::shared_ptr<const ConfigNode> &no
{
}
void FilterConfigNode::addFilter(const string &property,
void FilterConfigNode::addFilter(const std::string &property,
const InitStateString &value)
{
m_filter[property] = value;
@ -52,7 +52,7 @@ void FilterConfigNode::setFilter(const ConfigFilter &filter)
m_filter = filter;
}
InitStateString FilterConfigNode::readProperty(const string &property) const
InitStateString FilterConfigNode::readProperty(const std::string &property) const
{
ConfigFilter::const_iterator it = m_filter.find(property);
@ -63,14 +63,14 @@ InitStateString FilterConfigNode::readProperty(const string &property) const
}
}
void FilterConfigNode::writeProperty(const string &property,
void FilterConfigNode::writeProperty(const std::string &property,
const InitStateString &value,
const string &comment)
const std::string &comment)
{
ConfigFilter::iterator it = m_filter.find(property);
if (!m_node.get()) {
SyncContext::throwError(getName() + ": read-only, setting properties not allowed");
Exception::throwError(SE_HERE, getName() + ": read-only, setting properties not allowed");
}
if (it != m_filter.end()) {
@ -89,12 +89,12 @@ void FilterConfigNode::readProperties(ConfigProps &props) const
}
}
void FilterConfigNode::removeProperty(const string &property)
void FilterConfigNode::removeProperty(const std::string &property)
{
ConfigFilter::iterator it = m_filter.find(property);
if (!m_node.get()) {
SyncContext::throwError(getName() + ": read-only, removing properties not allowed");
Exception::throwError(SE_HERE, getName() + ": read-only, removing properties not allowed");
}
if (it != m_filter.end()) {
@ -112,7 +112,7 @@ void FilterConfigNode::clear()
void FilterConfigNode::flush()
{
if (!m_node.get()) {
SyncContext::throwError(getName() + ": read-only, flushing not allowed");
Exception::throwError(SE_HERE, getName() + ": read-only, flushing not allowed");
}
m_node->flush();
}

View file

@ -257,7 +257,7 @@ void ForkExecParent::start()
(m_mergedStdoutStderr || !m_onStderr.empty()) ? &err : NULL,
gerror)) {
m_childPid = 0;
gerror.throwError("spawning child");
gerror.throwError(SE_HERE, "spawning child");
}
// set up output redirection, ignoring failures
setupPipe(m_err, m_errID, err);

View file

@ -18,7 +18,7 @@
*/
#include <syncevo/GLibSupport.h>
#include <syncevo/util.h>
#include <syncevo/Exception.h>
#include <syncevo/SmartPtr.h>
#ifdef ENABLE_UNIT_TESTS
#include "test.h"
@ -155,12 +155,12 @@ GLibSelectResult GLibSelect(GMainLoop *loop, int fd, int direction, Timespec *ti
return instance.run();
}
void GErrorCXX::throwError(const string &action)
void GErrorCXX::throwError(const SourceLocation &where, const string &action)
{
throwError(action, m_gerror);
throwError(where, action, m_gerror);
}
void GErrorCXX::throwError(const string &action, const GError *err)
void GErrorCXX::throwError(const SourceLocation &where, const string &action, const GError *err)
{
string gerrorstr = action;
if (!gerrorstr.empty()) {
@ -174,7 +174,7 @@ void GErrorCXX::throwError(const string &action, const GError *err)
gerrorstr = "failure";
}
SE_THROW(gerrorstr);
throw Exception(where.m_file, where.m_line, gerrorstr);
}
static void changed(GFileMonitor *monitor,
@ -198,7 +198,7 @@ GLibNotify::GLibNotify(const char *file,
GFileMonitorCXX monitor(g_file_monitor_file(filecxx.get(), G_FILE_MONITOR_NONE, NULL, gerror), TRANSFER_REF);
m_monitor.swap(monitor);
if (!m_monitor) {
gerror.throwError(std::string("monitoring ") + file);
gerror.throwError(SE_HERE, std::string("monitoring ") + file);
}
g_signal_connect_after(m_monitor.get(),
"changed",

View file

@ -336,6 +336,8 @@ class GLibNotify : public boost::noncopyable
callback_t m_callback;
};
class SourceLocation; // Exception.h
/**
* Wraps GError. Where a GError** is expected, simply pass
* a GErrorCXX instance.
@ -420,8 +422,8 @@ struct GErrorCXX {
* always throws an exception, including information from GError if available:
* <action>: <error message>|failure
*/
void throwError(const std::string &action);
static void throwError(const std::string &action, const GError *err);
void throwError(const SourceLocation &where, const std::string &action);
static void throwError(const SourceLocation &where, const std::string &action, const GError *err);
};
template<class T> void NoopDestructor(T *) {}

View file

@ -19,6 +19,7 @@
#include <syncevo/IdentityProvider.h>
#include <syncevo/SyncConfig.h>
#include <syncevo/Exception.h>
#include <algorithm>

View file

@ -827,10 +827,10 @@ class LocalTransportAgentChild : public TransportAgent
if (!targetNodes.dataConfigExists()) {
if (targetName.empty()) {
m_client->throwError("missing URI for one of the sources");
Exception::throwError(SE_HERE, "missing URI for one of the sources");
} else {
m_client->throwError(StringPrintf("%s: source not configured",
fullTargetName.c_str()));
Exception::throwError(SE_HERE, StringPrintf("%s: source not configured",
fullTargetName.c_str()));
}
}
@ -839,9 +839,10 @@ class LocalTransportAgentChild : public TransportAgent
// be written. If a sync mode was set, it must have been
// done before in this loop => error in original config.
if (!targetSource.isDisabled()) {
m_client->throwError(StringPrintf("%s: source targetted twice by %s",
fullTargetName.c_str(),
serverConfig.first.c_str()));
Exception::throwError(SE_HERE,
StringPrintf("%s: source targetted twice by %s",
fullTargetName.c_str(),
serverConfig.first.c_str()));
}
// invert data direction
if (mode == SYNC_REFRESH_FROM_LOCAL) {

View file

@ -21,7 +21,6 @@
#include "config.h"
#include <syncevo/LogRedirect.h>
#include <syncevo/Logging.h>
#include <syncevo/SyncContext.h>
#include "test.h"
#include <syncevo/util.h>
#include <sys/types.h>
@ -32,9 +31,12 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include <boost/algorithm/string/find_iterator.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/noncopyable.hpp>
#include <boost/foreach.hpp>
#include <algorithm>
#include <iostream>
@ -413,7 +415,7 @@ bool LogRedirect::process(FDs &fds) throw()
break;
} else {
// Give up.
SyncContext::throwError("out of memory");
Exception::throwError(SE_HERE, "out of memory");
return false;
}
} else {
@ -433,7 +435,7 @@ bool LogRedirect::process(FDs &fds) throw()
// pretend that data was read, so that caller invokes us again
return true;
} else {
SyncContext::throwError("reading output", errno);
Exception::throwError(SE_HERE, "reading output", errno);
return false;
}
} else {
@ -601,7 +603,7 @@ void LogRedirect::process()
switch (res) {
case -1:
// fatal, cannot continue
SyncContext::throwError("waiting for output", errno);
Exception::throwError(SE_HERE, "waiting for output", errno);
return;
break;
case 0:

View file

@ -178,7 +178,7 @@ void MapSyncSource::detectChanges(SyncSourceRevisions::ChangeMode mode)
break;
default:
// ?!
throwError("unknown change mode");
throwError(SE_HERE, "unknown change mode");
break;
}

View file

@ -18,7 +18,7 @@
*/
#include <syncevo/PrefixConfigNode.h>
#include <syncevo/SyncContext.h>
#include <syncevo/Exception.h>
#include <boost/foreach.hpp>
#include <boost/algorithm/string/predicate.hpp>
@ -26,7 +26,7 @@
#include <syncevo/declarations.h>
SE_BEGIN_CXX
PrefixConfigNode::PrefixConfigNode(const string prefix,
PrefixConfigNode::PrefixConfigNode(const std::string prefix,
const boost::shared_ptr<ConfigNode> &node) :
m_prefix(prefix),
m_node(node),
@ -34,21 +34,21 @@ PrefixConfigNode::PrefixConfigNode(const string prefix,
{
}
PrefixConfigNode::PrefixConfigNode(const string prefix,
PrefixConfigNode::PrefixConfigNode(const std::string prefix,
const boost::shared_ptr<const ConfigNode> &node) :
m_prefix(prefix),
m_readOnlyNode(node)
{
}
InitStateString PrefixConfigNode::readProperty(const string &property) const
InitStateString PrefixConfigNode::readProperty(const std::string &property) const
{
return m_readOnlyNode->readProperty(m_prefix + property);
}
void PrefixConfigNode::writeProperty(const string &property,
void PrefixConfigNode::writeProperty(const std::string &property,
const InitStateString &value,
const string &comment)
const std::string &comment)
{
m_node->writeProperty(m_prefix + property,
value,
@ -61,8 +61,8 @@ void PrefixConfigNode::readProperties(ConfigProps &props) const
m_readOnlyNode->readProperties(original);
BOOST_FOREACH(const StringPair &prop, original) {
string key = prop.first;
string value = prop.second;
std::string key = prop.first;
std::string value = prop.second;
if (boost::starts_with(key, m_prefix)) {
props[key.substr(m_prefix.size())] = value;
@ -75,14 +75,14 @@ void PrefixConfigNode::clear()
ConfigProps original;
m_readOnlyNode->readProperties(original);
BOOST_FOREACH(const StringPair &prop, original) {
string key = prop.first;
std::string key = prop.first;
if (boost::starts_with(key, m_prefix)) {
m_node->removeProperty(key);
}
}
}
void PrefixConfigNode::removeProperty(const string &property)
void PrefixConfigNode::removeProperty(const std::string &property)
{
m_node->removeProperty(m_prefix + property);
}
@ -90,7 +90,7 @@ void PrefixConfigNode::removeProperty(const string &property)
void PrefixConfigNode::flush()
{
if (!m_node.get()) {
SyncContext::throwError(getName() + ": read-only, flushing not allowed");
Exception::throwError(SE_HERE, getName() + ": read-only, flushing not allowed");
}
m_node->flush();
}

View file

@ -18,7 +18,7 @@
*/
#include <syncevo/SafeConfigNode.h>
#include <syncevo/SyncContext.h>
#include <syncevo/Exception.h>
#include <boost/foreach.hpp>
@ -38,15 +38,15 @@ SafeConfigNode::SafeConfigNode(const boost::shared_ptr<const ConfigNode> &node)
{
}
InitStateString SafeConfigNode::readProperty(const string &property) const
InitStateString SafeConfigNode::readProperty(const std::string &property) const
{
InitStateString res = m_readOnlyNode->readProperty(escape(property));
return InitStateString(unescape(res.get()), res.wasSet());
}
void SafeConfigNode::writeProperty(const string &property,
void SafeConfigNode::writeProperty(const std::string &property,
const InitStateString &value,
const string &comment)
const std::string &comment)
{
m_node->writeProperty(escape(property),
InitStateString(escape(value.get()), value.wasSet()),
@ -59,14 +59,14 @@ void SafeConfigNode::readProperties(ConfigProps &props) const
m_readOnlyNode->readProperties(original);
BOOST_FOREACH(const StringPair &prop, original) {
string key = unescape(prop.first);
string value = unescape(prop.second);
std::string key = unescape(prop.first);
std::string value = unescape(prop.second);
props[key] = value;
}
}
void SafeConfigNode::removeProperty(const string &property)
void SafeConfigNode::removeProperty(const std::string &property)
{
m_node->removeProperty(escape(property));
}
@ -74,7 +74,7 @@ void SafeConfigNode::removeProperty(const string &property)
void SafeConfigNode::flush()
{
if (!m_node.get()) {
SyncContext::throwError(getName() + ": read-only, flushing not allowed");
Exception::throwError(SE_HERE, getName() + ": read-only, flushing not allowed");
}
m_node->flush();
}

View file

@ -18,7 +18,9 @@
*/
#include <syncevo/SafeOstream.h>
#include <syncevo/SyncContext.h>
#include <syncevo/Exception.h>
#include <errno.h>
#include <syncevo/declarations.h>
SE_BEGIN_CXX
@ -43,7 +45,7 @@ SafeOstream::~SafeOstream()
close();
if (bad() ||
rename(m_tmpFilename.c_str(), m_filename.c_str())) {
SyncContext::throwError(m_tmpFilename, errno);
Exception::throwError(SE_HERE, m_tmpFilename, errno);
}
}

View file

@ -202,7 +202,7 @@ void ConfigProperty::splitComment(const string &comment, list<string> &commentLi
void ConfigProperty::throwValueError(const ConfigNode &node, const string &name, const string &value, const string &error) const
{
SyncContext::throwError(node.getName() + ": " + name + " = " + value + ": " + error);
Exception::throwError(SE_HERE, node.getName() + ": " + name + " = " + value + ": " + error);
}
std::string ConfigProperty::sharing2str(Sharing sharing)
@ -2062,7 +2062,7 @@ void PasswordConfigProperty::checkPassword(UserInterface &ui,
const char *envval = getenv(envname.c_str());
SE_LOG_DEBUG(NULL, "using password from env var %s", envname.c_str());
if (!envval) {
SyncContext::throwError(string("the environment variable '") +
Exception::throwError(SE_HERE, string("the environment variable '") +
envname +
"' for the '" +
descr +

View file

@ -573,7 +573,7 @@ public:
if (mkdir(m_path.c_str(), S_IRWXU) &&
errno != EEXIST) {
SE_LOG_DEBUG(NULL, "%s: %s", m_path.c_str(), strerror(errno));
SyncContext::throwError(m_path, errno);
Exception::throwError(SE_HERE, m_path, errno);
}
}
m_logfile = m_path + "/" + LogfileBasename + ".html";
@ -850,7 +850,7 @@ public:
struct stat buf;
string fullpath = first + "/" + name;
if (stat(fullpath.c_str(), &buf)) {
SyncContext::throwError(fullpath, errno);
Exception::throwError(SE_HERE, fullpath, errno);
}
firstInodes.insert(buf.st_ino);
}
@ -858,7 +858,7 @@ public:
struct stat buf;
string fullpath = second + "/" + name;
if (stat(fullpath.c_str(), &buf)) {
SyncContext::throwError(fullpath, errno);
Exception::throwError(SE_HERE, fullpath, errno);
}
set<ino_t>::iterator it = firstInodes.find(buf.st_ino);
if (it == firstInodes.end()) {
@ -1261,7 +1261,7 @@ public:
string dir = databaseName(source, suffix);
boost::shared_ptr<ConfigNode> node = ConfigNode::createFileNode(dir + ".ini");
if (!node->exists()) {
SyncContext::throwError(dir + ": no such database backup found");
Exception::throwError(SE_HERE, dir + ": no such database backup found");
}
if (source.getOperations().m_restoreData) {
source.getOperations().m_restoreData(SyncSource::Operations::ConstBackupInfo(SyncSource::Operations::BackupInfo::BACKUP_OTHER, dir, node),
@ -2127,48 +2127,6 @@ bool SyncContext::displaySourceProgress(SyncSource &source,
return false;
}
void SyncContext::throwError(const string &error)
{
throwError(SyncMLStatus(STATUS_FATAL + sysync::LOCAL_STATUS_CODE), error);
}
void SyncContext::throwError(SyncMLStatus status, const string &error)
{
#ifdef IPHONE
/*
* Catching the runtime_exception fails due to a toolchain problem,
* so do the error handling now and abort: because there is just
* one sync source this is probably the only thing that can be done.
* Still, it's not nice on the server...
*/
fatalError(NULL, error.c_str());
#else
SE_THROW_EXCEPTION_STATUS(StatusException, error, status);
#endif
}
void SyncContext::throwError(const string &action, int error)
{
std::string what = action + ": " + strerror(error);
// be as specific if we can be: relevant for the file backend,
// which is expected to return STATUS_NOT_FOUND == 404 for "file
// not found"
if (error == ENOENT) {
throwError(STATUS_NOT_FOUND, what);
} else {
throwError(what);
}
}
void SyncContext::fatalError(void *object, const char *error)
{
SE_LOG_ERROR(NULL, "%s", error);
if (m_activeContext && m_activeContext->m_sourceListPtr) {
m_activeContext->m_sourceListPtr->syncDone(STATUS_FATAL, NULL);
}
exit(1);
}
/*
* There have been segfaults inside glib in the background
* thread which ran the second event loop. Disabled it again,
@ -2265,12 +2223,14 @@ void SyncContext::initSources(SourceList &sourceList)
boost::shared_ptr<PersistentSyncSourceConfig> source_config
= getSyncSourceConfig(source);
if (!source_config || !source_config->exists()) {
throwError(StringPrintf("Virtual data source \"%s\" references a nonexistent datasource \"%s\".", name.c_str(), source.c_str()));
Exception::throwError(SE_HERE,
StringPrintf("Virtual data source \"%s\" references a nonexistent datasource \"%s\".", name.c_str(), source.c_str()));
}
pair< map<string, string>::iterator, bool > res = subSources.insert(make_pair(source, name));
if (!res.second) {
throwError(StringPrintf("Data source \"%s\" included in the virtual sources \"%s\" and \"%s\". It can only be included in one virtual source at a time.",
source.c_str(), res.first->second.c_str(), name.c_str()));
Exception::throwError(SE_HERE,
StringPrintf("Data source \"%s\" included in the virtual sources \"%s\" and \"%s\". It can only be included in one virtual source at a time.",
source.c_str(), res.first->second.c_str(), name.c_str()));
}
}
@ -2303,7 +2263,7 @@ void SyncContext::initSources(SourceList &sourceList)
contextName);
cxxptr<SyncSource> syncSource(SyncSource::createSource(params));
if (!syncSource) {
throwError(name + ": type unknown" );
Exception::throwError(SE_HERE, name + ": type unknown" );
}
if (subSources.find(name) != subSources.end()) {
syncSource->recordVirtualSource(subSources[name]);
@ -2911,7 +2871,7 @@ void SyncContext::getConfigXML(string &xml, string &configname)
}
if (mappedSources.size() !=2) {
vSource->throwError ("virtual data source currently only supports events+tasks combinations");
vSource->throwError(SE_HERE, "virtual data source currently only supports events+tasks combinations");
}
string name = vSource->getName();
@ -3336,7 +3296,7 @@ void SyncContext::checkConfig(const std::string &operation) const
} else {
SE_LOG_INFO(NULL, "Configuration \"%s\" does not exist.", m_server.c_str());
}
throwError(StringPrintf("Cannot proceed with %s without a configuration.", operation.c_str()));
Exception::throwError(SE_HERE, StringPrintf("Cannot proceed with %s without a configuration.", operation.c_str()));
}
}
@ -3388,7 +3348,7 @@ SyncMLStatus SyncContext::sync(SyncReport *report)
if ( getPeerIsClient()) {
m_serverMode = true;
} else if (m_localSync && !m_agent) {
throwError("configuration error, syncURL = local can only be used in combination with peerIsClient = 1");
Exception::throwError(SE_HERE, "configuration error, syncURL = local can only be used in combination with peerIsClient = 1");
}
// create a Synthesis engine, used purely for logging purposes
@ -3410,7 +3370,7 @@ SyncMLStatus SyncContext::sync(SyncReport *report)
// instantiate backends, but do not open them yet
initSources(sourceList);
if (sourceList.empty()) {
throwError("no sources active, check configuration");
Exception::throwError(SE_HERE, "no sources active, check configuration");
}
// request all config properties once: throwing exceptions
@ -3813,11 +3773,11 @@ SyncMLStatus SyncContext::doSync()
version = 11;
if (!sendSAN (version)) {
// return a proper error code
throwError ("Server Alerted Sync init failed");
Exception::throwError(SE_HERE, "Server Alerted Sync init failed");
}
} else {
// return a proper error code
throwError ("Server Alerted Sync init failed");
Exception::throwError(SE_HERE, "Server Alerted Sync init failed");
}
}
}
@ -3908,7 +3868,7 @@ SyncMLStatus SyncContext::doSync()
slow = 0;
direction = 2;
} else {
source->throwError(string("invalid sync mode: ") + sync);
source->throwError(SE_HERE, string("invalid sync mode: ") + sync);
}
m_engine.SetInt32Value(target, "forceslow", slow);
m_engine.SetInt32Value(target, "syncmode", direction);
@ -4149,7 +4109,7 @@ SyncMLStatus SyncContext::doSync()
progressInfo.extra3),
false);
} else {
throwError(std::string("unknown target ") + s);
Exception::throwError(SE_HERE, std::string("unknown target ") + s);
}
target.reset();
break;

View file

@ -88,8 +88,7 @@ class SyncContext : public SyncConfig {
boost::shared_ptr<UserInterface> m_userInterface;
/**
* a pointer to the active SourceList instance for this context if one exists;
* used for error handling in throwError() on the iPhone
* a pointer to the active SourceList instance for this context if one exists
*/
SourceList *m_sourceListPtr;
@ -372,51 +371,6 @@ class SyncContext : public SyncConfig {
*/
void checkStatus(SyncReport &report);
/**
* throws a StatusException with a local, fatal error with the given string
* or (on the iPhone, where exception handling is not
* supported by the toolchain) prints an error directly
* and aborts
*
* output format: <error>
*
* @param error a string describing the error
*/
static void throwError(const string &error) SE_NORETURN;
/**
* throw an exception with a specific status code after an operation failed and
* remember that this instance has failed
*
* output format: <failure>
*
* @param status a more specific status code; other throwError() variants
* use STATUS_FATAL + sysync::LOCAL_STATUS_CODE, which is interpreted
* as a fatal local error
* @param action a string describing what was attempted *and* how it failed
*/
static void throwError(SyncMLStatus status, const string &failure) SE_NORETURN;
/**
* throw an exception after an operation failed and
* remember that this instance has failed
*
* output format: <action>: <error string>
*
* @Param action a string describing the operation or object involved
* @param error the errno error code for the failure
*/
static void throwError(const string &action, int error) SE_NORETURN;
/**
* An error handler which prints the error message and then
* stops the program. Never returns.
*
* The API was chosen so that it can be used as libebook/libecal
* "backend-dies" signal handler.
*/
static void fatalError(void *object, const char *error) SE_NORETURN;
/**
* When using Evolution this function starts a background thread
* which drives the default event loop. Without that loop

View file

@ -52,27 +52,27 @@
#include <syncevo/declarations.h>
SE_BEGIN_CXX
void SyncSourceBase::throwError(const string &action, int error)
void SyncSourceBase::throwError(const SourceLocation &where, const string &action, int error)
{
std::string what = action + ": " + strerror(error);
// be as specific if we can be: relevant for the file backend,
// which is expected to return STATUS_NOT_FOUND == 404 for "file
// not found"
if (error == ENOENT) {
throwError(STATUS_NOT_FOUND, what);
throwError(where, STATUS_NOT_FOUND, what);
} else {
throwError(what);
throwError(where, what);
}
}
void SyncSourceBase::throwError(const string &failure)
void SyncSourceBase::throwError(const SourceLocation &where, const string &failure)
{
SyncContext::throwError(string(getDisplayName()) + ": " + failure);
Exception::throwError(where, string(getDisplayName()) + ": " + failure);
}
void SyncSourceBase::throwError(SyncMLStatus status, const string &failure)
void SyncSourceBase::throwError(const SourceLocation &where, SyncMLStatus status, const string &failure)
{
SyncContext::throwError(status, getDisplayName() + ": " + failure);
Exception::throwError(where, status, getDisplayName() + ": " + failure);
}
SyncMLStatus SyncSourceBase::handleException(HandleExceptionFlags flags)
@ -267,10 +267,10 @@ public:
virtual bool isInactive() const { return true; }
virtual void enableServerMode() {}
virtual bool serverModeEnabled() const { return false; }
virtual void getSynthesisInfo(SyncEvo::SyncSourceBase::SynthesisInfo&, SyncEvo::XMLConfigFragments&) { throwError("inactive"); }
virtual Databases getDatabases() { throwError("inactive"); return Databases(); }
virtual void open() { throwError("inactive"); }
virtual void close() { throwError("inactive"); }
virtual void getSynthesisInfo(SyncEvo::SyncSourceBase::SynthesisInfo&, SyncEvo::XMLConfigFragments&) { throwError(SE_HERE, "inactive"); }
virtual Databases getDatabases() { throwError(SE_HERE, "inactive"); return Databases(); }
virtual void open() { throwError(SE_HERE, "inactive"); }
virtual void close() { throwError(SE_HERE, "inactive"); }
virtual std::string getPeerMimeType() const { return ""; }
};
@ -417,7 +417,7 @@ SyncSource *SyncSource::createSource(const SyncSourceParams &params, bool error,
SyncSource *source = NULL;
source = new VirtualSyncSource(params, config);
if (error && !source) {
SyncContext::throwError(params.getDisplayName() + ": virtual source cannot be instantiated");
Exception::throwError(SE_HERE, params.getDisplayName() + ": virtual source cannot be instantiated");
}
return source;
}
@ -428,7 +428,7 @@ SyncSource *SyncSource::createSource(const SyncSourceParams &params, bool error,
auto_ptr<SyncSource> nextSource(sourceInfos->m_create(params));
if (nextSource.get()) {
if (source.get()) {
SyncContext::throwError(params.getDisplayName() + ": backend " + sourceType.m_backend +
Exception::throwError(SE_HERE, params.getDisplayName() + ": backend " + sourceType.m_backend +
" is ambiguous, avoid the alias and pick a specific backend instead directly");
}
source = nextSource;
@ -453,7 +453,7 @@ SyncSource *SyncSource::createSource(const SyncSourceParams &params, bool error,
sourceType.m_backend.c_str(),
sourceType.m_localFormat.c_str(),
sourceType.m_format.c_str());
SyncContext::throwError(SyncMLStatus(sysync::LOCERR_CFGPARSE), problem);
Exception::throwError(SE_HERE, SyncMLStatus(sysync::LOCERR_CFGPARSE), problem);
}
return NULL;
@ -486,8 +486,8 @@ VirtualSyncSource::VirtualSyncSource(const SyncSourceParams &params, SyncConfig
std::string evoSyncSource = getDatabaseID();
BOOST_FOREACH(std::string name, getMappedSources()) {
if (name.empty()) {
throwError(StringPrintf("configuration of underlying sources contains empty source name: database = '%s'",
evoSyncSource.c_str()));
throwError(SE_HERE, StringPrintf("configuration of underlying sources contains empty source name: database = '%s'",
evoSyncSource.c_str()));
}
SyncSourceNodes source = config->getSyncSourceNodes(name);
SyncSourceParams params(name, source, boost::shared_ptr<SyncConfig>(config, SyncConfigNOP()));
@ -495,8 +495,8 @@ VirtualSyncSource::VirtualSyncSource(const SyncSourceParams &params, SyncConfig
m_sources.push_back(syncSource);
}
if (m_sources.size() != 2) {
throwError(StringPrintf("configuration of underlying sources must contain exactly one calendar and one todo source (like calendar+todo): database = '%s'",
evoSyncSource.c_str()));
throwError(SE_HERE, StringPrintf("configuration of underlying sources must contain exactly one calendar and one todo source (like calendar+todo): database = '%s'",
evoSyncSource.c_str()));
}
}
}
@ -716,7 +716,7 @@ void SyncSourceSerialize::getSynthesisInfo(SynthesisInfo &info,
info.m_fieldlist = "Note";
info.m_profile = "\"Note\", 2";
} else {
throwError(string("default MIME type not supported: ") + type);
throwError(SE_HERE, string("default MIME type not supported: ") + type);
}
SourceType sourceType = getSourceType();
@ -771,9 +771,9 @@ std::string SyncSourceBase::getDataTypeSupport(const std::string &type,
" <use datatype='note10' mode='rw' preferred='yes'/>\n"
" <use datatype='note11' mode='rw'/>\n";
} else if (type.empty()) {
throwError("no MIME type configured");
throwError(SE_HERE, "no MIME type configured");
} else {
throwError(string("configured MIME type not supported: ") + type);
throwError(SE_HERE, string("configured MIME type not supported: ") + type);
}
return datatypes;
@ -1127,7 +1127,7 @@ void SyncSourceRevisions::restoreData(const SyncSource::Operations::ConstBackupI
filename << oldBackup.m_dirname << "/" << counter;
string data;
if (!ReadFile(filename.str(), data)) {
throwError(StringPrintf("restoring %s from %s failed: could not read file",
throwError(SE_HERE, StringPrintf("restoring %s from %s failed: could not read file",
uid.c_str(),
filename.str().c_str()));
}
@ -1339,7 +1339,7 @@ void SyncSourceRevisions::updateRevision(ConfigNode &trackingNode,
trackingNode.removeProperty(old_luid);
}
if (new_luid.empty() || revision.empty()) {
throwError("need non-empty LUID and revision string");
throwError(SE_HERE, "need non-empty LUID and revision string");
}
trackingNode.setProperty(new_luid, revision);
}

View file

@ -1315,7 +1315,7 @@ class SyncSourceBase {
* @param action a string describing the operation or object involved
* @param error the errno error code for the failure
*/
void throwError(const string &action, int error) SE_NORETURN;
void throwError(const SourceLocation &where, const string &action, int error) SE_NORETURN;
/**
* throw an exception after an operation failed and
@ -1325,7 +1325,7 @@ class SyncSourceBase {
*
* @param action a string describing what was attempted *and* how it failed
*/
void throwError(const string &failure) SE_NORETURN;
void throwError(const SourceLocation &where, const string &failure) SE_NORETURN;
/**
* throw an exception with a specific status code after an operation failed and
@ -1336,7 +1336,7 @@ class SyncSourceBase {
* @param status a more specific status code; other throwError() variants use STATUS_FATAL
* @param action a string describing what was attempted *and* how it failed
*/
void throwError(SyncMLStatus status, const string &failure) SE_NORETURN;
void throwError(const SourceLocation &where, SyncMLStatus status, const string &failure) SE_NORETURN;
/**
* The Synthesis engine only counts items which are deleted by the
@ -1855,7 +1855,7 @@ class SyncSource : virtual public SyncSourceBase, public SyncSourceConfig, publi
* a specific URI.
* @return description of the new database
*/
virtual Database createDatabase(const Database &database) { throwError("creating databases is not supported by backend " + getBackend()); return Database("", ""); }
virtual Database createDatabase(const Database &database) { throwError(SE_HERE, "creating databases is not supported by backend " + getBackend()); return Database("", ""); }
/**
* Removing a database primarily removes the meta data about the
@ -1877,7 +1877,7 @@ class SyncSource : virtual public SyncSourceBase, public SyncSourceConfig, publi
* @param uri unique identifier for the database
* @param removeData describes what to do about the database content
*/
virtual void deleteDatabase(const std::string &uri, RemoveData removeData) { throwError("deleting databases is not supported by backend " + getBackend()); }
virtual void deleteDatabase(const std::string &uri, RemoveData removeData) { throwError(SE_HERE, "deleting databases is not supported by backend " + getBackend()); }
/**
* Actually opens the data source specified in the constructor,

View file

@ -19,7 +19,6 @@
#define EDS_ABI_WRAPPER_NO_REDEFINE 1
#include <syncevo/eds_abi_wrapper.h>
#include <syncevo/SyncContext.h>
#include <syncevo/util.h>
#include <string>

View file

@ -69,6 +69,9 @@ src_syncevo_sources = \
src/syncevo/LocalTransportAgent.h \
src/syncevo/LocalTransportAgent.cpp \
\
src/syncevo/Exception.h \
src/syncevo/Exception.cpp \
\
src/syncevo/util.cpp \
src/syncevo/util.h \
src/syncevo/BoostHelper.h \
@ -178,6 +181,7 @@ src_syncevo_libsyncevolution_include_HEADERS = \
src/syncevo/LogStdout.h \
src/syncevo/LogSyslog.h \
\
src/syncevo/Exception.h \
src/syncevo/FilterConfigNode.h \
src/syncevo/PrefixConfigNode.h \
src/syncevo/SafeConfigNode.h \

View file

@ -20,9 +20,9 @@
#include "config.h"
#include <syncevo/util.h>
#include <syncevo/Exception.h>
#include <syncevo/SyncContext.h>
#include <syncevo/TransportAgent.h>
#include <syncevo/SynthesisEngine.h>
#include <syncevo/Logging.h>
#include <syncevo/LogRedirect.h>
#include <syncevo/SuspendFlags.h>
@ -38,10 +38,6 @@
#include <fstream>
#include <iostream>
#include "gdbus-cxx-bridge.h"
#include <pcrecpp.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
@ -158,7 +154,7 @@ void mkdir_p(const string &path)
nextdir ? (R_OK|X_OK) : (R_OK|X_OK|W_OK)) &&
(errno != ENOENT ||
mkdir(dirs.get(), 0700))) {
SyncContext::throwError(string(dirs.get()), errno);
Exception::throwError(SE_HERE, string(dirs.get()), errno);
}
}
if (nextdir) {
@ -176,7 +172,7 @@ void rm_r(const string &path, boost::function<bool (const string &,
if (errno == ENOENT) {
return;
} else {
SyncContext::throwError(path, errno);
Exception::throwError(SE_HERE, path, errno);
}
}
@ -185,7 +181,7 @@ void rm_r(const string &path, boost::function<bool (const string &,
!unlink(path.c_str())) {
return;
} else {
SyncContext::throwError(path, errno);
Exception::throwError(SE_HERE, path, errno);
}
}
@ -195,7 +191,7 @@ void rm_r(const string &path, boost::function<bool (const string &,
}
if (filter(path, true) &&
rmdir(path.c_str())) {
SyncContext::throwError(path, errno);
Exception::throwError(SE_HERE, path, errno);
}
}
@ -232,7 +228,7 @@ bool isDir(const string &path)
closedir(dir);
return true;
} else if (errno != ENOTDIR && errno != ENOENT) {
SyncContext::throwError(path, errno);
Exception::throwError(SE_HERE, path, errno);
}
return false;
@ -376,7 +372,7 @@ ReadDir::ReadDir(const string &path, bool throwError) : m_path(path)
try {
dir = opendir(path.c_str());
if (!dir) {
SyncContext::throwError(path, errno);
Exception::throwError(SE_HERE, path, errno);
}
errno = 0;
struct dirent *entry = readdir(dir);
@ -388,7 +384,7 @@ ReadDir::ReadDir(const string &path, bool throwError) : m_path(path)
entry = readdir(dir);
}
if (errno) {
SyncContext::throwError(path, errno);
Exception::throwError(SE_HERE, path, errno);
}
std::sort(m_entries.begin(), m_entries.end());
} catch(...) {
@ -828,114 +824,6 @@ InitStateTri::Value InitStateTri::getValue() const
}
}
const char * const TRANSPORT_PROBLEM = "transport problem: ";
const char * const SYNTHESIS_PROBLEM = "error code from Synthesis engine ";
const char * const SYNCEVOLUTION_PROBLEM = "error code from SyncEvolution ";
SyncMLStatus Exception::handle(SyncMLStatus *status,
const std::string *logPrefix,
std::string *explanation,
Logger::Level level,
HandleExceptionFlags flags)
{
// any problem here is a fatal local problem, unless set otherwise
// by the specific exception
SyncMLStatus new_status = SyncMLStatus(STATUS_FATAL + sysync::LOCAL_STATUS_CODE);
std::string error;
try {
throw;
} catch (const TransportException &ex) {
SE_LOG_DEBUG(logPrefix, "TransportException thrown at %s:%d",
ex.m_file.c_str(), ex.m_line);
error = std::string(TRANSPORT_PROBLEM) + ex.what();
new_status = SyncMLStatus(sysync::LOCERR_TRANSPFAIL);
} catch (const BadSynthesisResult &ex) {
new_status = SyncMLStatus(ex.result());
error = StringPrintf("%s%s",
SYNTHESIS_PROBLEM,
Status2String(new_status).c_str());
} catch (const StatusException &ex) {
new_status = ex.syncMLStatus();
SE_LOG_DEBUG(logPrefix, "exception thrown at %s:%d",
ex.m_file.c_str(), ex.m_line);
error = StringPrintf("%s%s: %s",
SYNCEVOLUTION_PROBLEM,
Status2String(new_status).c_str(), ex.what());
if (new_status == STATUS_NOT_FOUND &&
(flags & HANDLE_EXCEPTION_404_IS_OKAY)) {
level = Logger::DEBUG;
}
} catch (const Exception &ex) {
SE_LOG_DEBUG(logPrefix, "exception thrown at %s:%d",
ex.m_file.c_str(), ex.m_line);
error = ex.what();
} catch (const std::exception &ex) {
error = ex.what();
} catch (...) {
error = "unknown error";
}
if (flags & HANDLE_EXCEPTION_FATAL) {
level = Logger::ERROR;
}
if (flags & HANDLE_EXCEPTION_NO_ERROR) {
level = Logger::DEBUG;
}
SE_LOG(logPrefix, level, "%s", error.c_str());
if (flags & HANDLE_EXCEPTION_FATAL) {
// Something unexpected went wrong, can only shut down.
::abort();
}
if (explanation) {
*explanation = error;
}
if (status && *status == STATUS_OK) {
*status = new_status;
}
return status ? *status : new_status;
}
void Exception::tryRethrow(const std::string &explanation, bool mustThrow)
{
static const std::string statusre = ".* \\((?:local|remote), status (\\d+)\\)";
int status;
if (boost::starts_with(explanation, TRANSPORT_PROBLEM)) {
SE_THROW_EXCEPTION(TransportException, explanation.substr(strlen(TRANSPORT_PROBLEM)));
} else if (boost::starts_with(explanation, SYNTHESIS_PROBLEM)) {
static const pcrecpp::RE re(statusre);
if (re.FullMatch(explanation.substr(strlen(SYNTHESIS_PROBLEM)), &status)) {
SE_THROW_EXCEPTION_1(BadSynthesisResult, "Synthesis engine failure", (sysync::TSyErrorEnum)status);
}
} else if (boost::starts_with(explanation, SYNCEVOLUTION_PROBLEM)) {
static const pcrecpp::RE re(statusre + ": (.*)",
pcrecpp::RE_Options().set_dotall(true));
std::string details;
if (re.FullMatch(explanation.substr(strlen(SYNCEVOLUTION_PROBLEM)), &status, &details)) {
SE_THROW_EXCEPTION_STATUS(StatusException, details, (SyncMLStatus)status);
}
}
if (mustThrow) {
throw std::runtime_error(explanation);
}
}
void Exception::tryRethrowDBus(const std::string &error)
{
static const pcrecpp::RE re("(org\\.syncevolution(?:\\.\\w+)+): (.*)",
pcrecpp::RE_Options().set_dotall(true));
std::string exName, explanation;
if (re.FullMatch(error, &exName, &explanation)) {
// found SyncEvolution exception explanation, parse it
tryRethrow(explanation);
// explanation not parsed, fall back to D-Bus exception
throw GDBusCXX::dbus_error(exName, explanation);
}
}
std::string SubstEnvironment(const std::string &str)
{
std::stringstream res;
@ -1029,7 +917,7 @@ std::string SyncEvolutionDataDir()
return dataDir;
}
ScopedEnvChange::ScopedEnvChange(const string &var, const string &value) :
ScopedEnvChange::ScopedEnvChange(const std::string &var, const std::string &value) :
m_var(var)
{
const char *oldval = getenv(var.c_str());

View file

@ -41,6 +41,7 @@
#include <syncevo/Timespec.h> // definitions used to be included in util.h,
// include it to avoid changing code using the time things
#include <syncevo/Exception.h> // same for Exception and SE_THROW*
#include <syncevo/declarations.h>
SE_BEGIN_CXX
@ -474,117 +475,6 @@ class InitStateTri : public InitStateString
Value getValue() const;
};
enum HandleExceptionFlags {
HANDLE_EXCEPTION_FLAGS_NONE = 0,
/**
* a 404 status error is possible and must not be logged as ERROR
*/
HANDLE_EXCEPTION_404_IS_OKAY = 1 << 0,
HANDLE_EXCEPTION_FATAL = 1 << 1,
/**
* don't log exception as ERROR
*/
HANDLE_EXCEPTION_NO_ERROR = 1 << 2,
HANDLE_EXCEPTION_MAX = 1 << 3,
};
/**
* an exception which records the source file and line
* where it was thrown
*
* @TODO add function name
*/
class Exception : public std::runtime_error
{
public:
Exception(const std::string &file,
int line,
const std::string &what) :
std::runtime_error(what),
m_file(file),
m_line(line)
{}
~Exception() throw() {}
const std::string m_file;
const int m_line;
/**
* Convenience function, to be called inside a catch(..) block.
*
* Rethrows the exception to determine what it is, then logs it
* at the chosen level (error by default).
*
* Turns certain known exceptions into the corresponding
* status code if status still was STATUS_OK when called.
* Returns updated status code.
*
* @param logPrefix passed to SE_LOG* messages
* @retval explanation set to explanation for problem, if non-NULL
* @param level level to be used for logging
*/
static SyncMLStatus handle(SyncMLStatus *status = NULL, const std::string *logPrefix = NULL, std::string *explanation = NULL, Logger::Level = Logger::ERROR, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE);
static SyncMLStatus handle(const std::string &logPrefix, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE) { return handle(NULL, &logPrefix, NULL, Logger::ERROR, flags); }
static SyncMLStatus handle(std::string &explanation, HandleExceptionFlags flags = HANDLE_EXCEPTION_FLAGS_NONE) { return handle(NULL, NULL, &explanation, Logger::ERROR, flags); }
static void handle(HandleExceptionFlags flags) { handle(NULL, NULL, NULL, Logger::ERROR, flags); }
static void log() { handle(NULL, NULL, NULL, Logger::DEBUG); }
/**
* Tries to identify exception class based on explanation string created by
* handle(). If successful, that exception is throw with the same
* attributes as in the original exception.
*
* If not, tryRethrow() returns (mustThrow false) or throws a std::runtime_error
* with the explanation as text.
*/
static void tryRethrow(const std::string &explanation, bool mustThrow = false);
/**
* Same as tryRethrow() for strings with a 'org.syncevolution.xxxx:' prefix,
* as passed as D-Bus error strings.
*/
static void tryRethrowDBus(const std::string &error);
};
/**
* StatusException by wrapping a SyncML status
*/
class StatusException : public Exception
{
public:
StatusException(const std::string &file,
int line,
const std::string &what,
SyncMLStatus status)
: Exception(file, line, what), m_status(status)
{}
SyncMLStatus syncMLStatus() const { return m_status; }
protected:
SyncMLStatus m_status;
};
class TransportException : public Exception
{
public:
TransportException(const std::string &file,
int line,
const std::string &what) :
Exception(file, line, what) {}
~TransportException() throw() {}
};
class TransportStatusException : public StatusException
{
public:
TransportStatusException(const std::string &file,
int line,
const std::string &what,
SyncMLStatus status) :
StatusException(file, line, what, status) {}
~TransportStatusException() throw() {}
};
/**
* replace ${} with environment variables, with
* XDG_DATA_HOME, XDG_CACHE_HOME and XDG_CONFIG_HOME having their normal
@ -649,35 +539,6 @@ class ScopedEnvChange
std::string getCurrentTime();
/** throw a normal SyncEvolution Exception, including source information */
#define SE_THROW(_what) \
SE_THROW_EXCEPTION(Exception, _what)
/** throw a class which accepts file, line, what parameters */
#define SE_THROW_EXCEPTION(_class, _what) \
throw _class(__FILE__, __LINE__, _what)
/** throw a class which accepts file, line, what plus 1 additional parameter */
#define SE_THROW_EXCEPTION_1(_class, _what, _x1) \
throw _class(__FILE__, __LINE__, (_what), (_x1))
/** throw a class which accepts file, line, what plus 2 additional parameters */
#define SE_THROW_EXCEPTION_2(_class, _what, _x1, _x2) \
throw _class(__FILE__, __LINE__, (_what), (_x1), (_x2))
/** throw a class which accepts file, line, what plus 2 additional parameters */
#define SE_THROW_EXCEPTION_3(_class, _what, _x1, _x2, _x3) \
throw _class(__FILE__, __LINE__, (_what), (_x1), (_x2), (_x3))
/** throw a class which accepts file, line, what plus 2 additional parameters */
#define SE_THROW_EXCEPTION_4(_class, _what, _x1, _x2, _x3, _x4) \
throw _class(__FILE__, __LINE__, (_what), (_x1), (_x2), (_x3), (_x4))
/** throw a class which accepts file, line, what parameters and status parameters*/
#define SE_THROW_EXCEPTION_STATUS(_class, _what, _status) \
throw _class(__FILE__, __LINE__, _what, _status)
// GRunWhile(), GRunInMain(), GRunIsMain() depend on glib support,
// which pretty much is a hard requirement of SyncEvolution these days.
// Different implementations would be possible and the APIs do not depend

View file

@ -267,7 +267,7 @@ int main(int argc, char **argv)
bool success = g_option_context_parse(opt_context, &argc, &argv, gerror);
g_option_context_free(opt_context);
if (!success) {
gerror.throwError("parsing command line options");
gerror.throwError(SE_HERE, "parsing command line options");
}
// if (!opt_server && opt_allow_anonymous) {
// throw stdruntime_error("The --allow-anonymous option only makes sense when used with --server.");