catch some exceptions

This commit is contained in:
Martin Rotter 2021-03-10 06:19:48 +01:00
parent bf5d182f2a
commit 93da8822ef
6 changed files with 32 additions and 12 deletions

View File

@ -30,7 +30,7 @@
<url type="donation">https://martinrotter.github.io/donate/</url>
<content_rating type="oars-1.1" />
<releases>
<release version="3.9.0" date="2021-03-09"/>
<release version="3.9.0" date="2021-03-10"/>
</releases>
<content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute>

View File

@ -157,7 +157,6 @@ QList<ServiceRoot*> DatabaseQueries::getAccounts(const QSqlDatabase& db, const Q
ServiceRoot* root = new T();
// Load common data.
//root->setId(query.value(QSL("id")).toInt());
root->setAccountId(query.value(QSL("id")).toInt());
QNetworkProxy proxy(QNetworkProxy::ProxyType(query.value(QSL("proxy_type")).toInt()),

View File

@ -161,6 +161,9 @@ class RSSGUARD_DLLSPEC RootItem : public QObject {
// This ALWAYS represents primary column number/ID under which
// the item is stored in DB.
int id() const;
// WARNING: Do not EVER call this method if your "this" object is derived
// from "ServiceRoot";
void setId(int id);
// Each item has its title.

View File

@ -5,8 +5,9 @@
#include "3rd-party/boolinq/boolinq.h"
#include "core/feedsmodel.h"
#include "core/messagesmodel.h"
#include "miscellaneous/application.h"
#include "database/databasequeries.h"
#include "exceptions/applicationexception.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/textfactory.h"
#include "services/abstract/cacheforserviceroot.h"
@ -281,7 +282,12 @@ ServiceRoot::LabelOperation ServiceRoot::supportedLabelOperations() const {
void ServiceRoot::saveAccountDataToDatabase() {
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
DatabaseQueries::createOverwriteAccount(database, this);
try {
DatabaseQueries::createOverwriteAccount(database, this);
}
catch (const ApplicationException& ex) {
qFatal("Account was not saved into database: '%s'.", qPrintable(ex.message()));
}
}
QVariantHash ServiceRoot::customDatabaseData() const {

View File

@ -215,7 +215,7 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
QString feed_type = child_element.attribute(QSL("version"), DEFAULT_FEED_TYPE).toUpper();
QString feed_description = child_element.attribute(QSL("description"));
QIcon feed_icon = qApp->icons()->fromByteArray(child_element.attribute(QSL("rssguard:icon")).toLocal8Bit());
QString source_type = child_element.attribute(QSL("rssguard:xmlUrlType"));
StandardFeed::SourceType source_type = StandardFeed::SourceType(child_element.attribute(QSL("rssguard:xmlUrlType")).toInt());
QString post_process = child_element.attribute(QSL("rssguard:postProcess"));
auto* new_feed = new StandardFeed(active_model_item);
@ -224,6 +224,8 @@ void FeedsImportExportModel::importAsOPML20(const QByteArray& data, bool fetch_m
new_feed->setEncoding(feed_encoding);
new_feed->setSource(feed_url);
new_feed->setCreationDate(QDateTime::currentDateTime());
new_feed->setSourceType(source_type);
new_feed->setPostProcessScript(post_process);
if (!feed_icon.isNull()) {
new_feed->setIcon(feed_icon);

View File

@ -318,7 +318,9 @@ QList<QAction*> StandardServiceRoot::getContextMenuForFeed(StandardFeed* feed) {
return m_feedContextMenu;
}
bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel* model, RootItem* target_root_node, QString& output_message) {
bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel* model,
RootItem* target_root_node,
QString& output_message) {
QStack<RootItem*> original_parents;
original_parents.push(target_root_node);
@ -385,17 +387,25 @@ bool StandardServiceRoot::mergeImportExportModel(FeedsImportExportModel* model,
auto* new_feed = new StandardFeed(*source_feed);
QSqlDatabase database = qApp->database()->driver()->connection(metaObject()->className());
DatabaseQueries::createOverwriteFeed(database,
new_feed,
target_root_node->getParentServiceRoot()->accountId(),
target_parent->id());
requestItemReassignment(new_feed, target_parent);
try {
DatabaseQueries::createOverwriteFeed(database,
new_feed,
target_root_node->getParentServiceRoot()->accountId(),
target_parent->id());
requestItemReassignment(new_feed, target_parent);
}
catch (const ApplicationException& ex) {
qCriticalNN << LOGSEC_CORE
<< "Cannot import feed:"
<< QUOTE_W_SPACE_DOT(ex.message());
some_feed_category_error = true;
}
}
}
}
if (some_feed_category_error) {
output_message = tr("Import successful, but some feeds/categories were not imported due to error.");
output_message = tr("Some feeds/categories were not imported due to error, check debug log for more details.");
}
else {
output_message = tr("Import was completely successful.");