Skip to content

Commit

Permalink
cmd: Replace the use of qFatal
Browse files Browse the repository at this point in the history
qFatal appears as a crash on unix platforms
  • Loading branch information
TheOneRing committed Mar 24, 2023
1 parent 7af6bc8 commit f6c73ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/10637
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: More user friendly error handling in the cmd client

https://github.com/owncloud/client/pull/10637
56 changes: 30 additions & 26 deletions src/cmd/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,24 +162,22 @@ void sync(const SyncCTX &ctx)
abort(false);
} else {
if (dir == SyncFileItem::Down) {
std::cout << "All files in the sync folder '" << qPrintable(ctx.options.remoteFolder) << "' folder were deleted on the server.\n"
<< "These deletes will be synchronized to your local sync folder, making such files "
<< "unavailable unless you have a right to restore. \n"
<< "If you decide to keep the files, they will be re-synced with the server if you have rights to do so.\n"
<< "If you decide to delete the files, they will be unavailable to you, unless you are the owner."
<< std::endl;
qInfo() << "All files in the sync folder '" << ctx.options.remoteFolder << "' folder were deleted on the server.";
qInfo() << "These deletes will be synchronized to your local sync folder, making such files "
<< "unavailable unless you have a right to restore.";
qInfo() << "If you decide to keep the files, they will be re-synced with the server if you have rights to do so.";
qInfo() << "If you decide to delete the files, they will be unavailable to you, unless you are the owner.";


} else {
std::cout << "All the files in your local sync folder '" << qPrintable(ctx.options.source_dir) << "' were deleted. These deletes will be "
<< "synchronized with your server, making such files unavailable unless restored.\n"
<< "Are you sure you want to sync those actions with the server?\n"
<< "If this was an accident and you decide to keep your files, they will be re-synced from the server."
<< std::endl;
qInfo() << "All the files in your local sync folder '" << ctx.options.source_dir << "' were deleted. These deletes will be "
<< "synchronized with your server, making such files unavailable unless restored.";
qInfo() << "Are you sure you want to sync those actions with the server?";
qInfo() << "If this was an accident and you decide to keep your files, they will be re-synced from the server.";
}
std::string s;
while (true) {
std::cout << "Remove all files?[y,n]";
qInfo() << "Remove all files?[y,n]";
std::getline(std::cin, s);
if (s == "y") {
abort(false);
Expand Down Expand Up @@ -213,7 +211,8 @@ void sync(const SyncCTX &ctx)
}

if (!engine->excludedFiles().reloadExcludeFiles()) {
qFatal("Cannot load system exclude list or list supplied via --exclude");
qCritical() << "Cannot load system exclude list or list supplied via --exclude";
exit(1);
}
engine->startSync();
}
Expand Down Expand Up @@ -262,13 +261,15 @@ void setupCredentials(SyncCTX &ctx)

port = pList.at(2).toUInt(&ok);
if (!ok || port > std::numeric_limits<uint16_t>::max()) {
qFatal("Invalid port number");
qCritical() << "Invalid port number";
exit(1);
}

QNetworkProxyFactory::setUseSystemConfiguration(false);
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, host, static_cast<uint16_t>(port)));
} else {
qFatal("Could not read httpproxy. The proxy should have the format \"http://hostname:port\".");
qCritical() << "Could not read httpproxy. The proxy should have the format \"http://hostname:port\".";
exit(1);
}
}

Expand All @@ -278,9 +279,8 @@ void setupCredentials(SyncCTX &ctx)
// also fail
QFile f(ctx.options.unsyncedfolders);
if (!f.open(QFile::ReadOnly)) {
qFatal("Cannot read unsyncedfolders file '%s': %s",
qPrintable(ctx.options.unsyncedfolders),
qPrintable(f.errorString()));
qCritical() << "Cannot read unsyncedfolders file '" << ctx.options.unsyncedfolders << "': " << f.errorString();
exit(1);
}
f.close();
}
Expand All @@ -298,7 +298,8 @@ void setupCredentials(SyncCTX &ctx)
for (const auto &e : errors) {
qCritical() << e.errorString();
}
qFatal("If you trust the certificate and want to ignore the errors, use the --trust option.");
qCritical() << "If you trust the certificate and want to ignore the errors, use the --trust option.";
exit(1);
});
}
}
Expand Down Expand Up @@ -354,7 +355,7 @@ CmdOptions parseOptions(const QStringList &app_args)
options.source_dir = [arg = args[0]] {
QFileInfo fi(arg);
if (!fi.exists()) {
std::cerr << "Source dir '" << qPrintable(arg) << "' does not exist." << std::endl;
qCritical() << "Source dir '" << arg << "' does not exist.";
exit(1);
}
QString sourceDir = fi.absoluteFilePath();
Expand Down Expand Up @@ -439,7 +440,8 @@ int main(int argc, char **argv)
ctx.account = Account::create();

if (!ctx.account) {
qFatal("Could not initialize account!");
qCritical() << "Could not initialize account!";
exit(1);
}

setupCredentials(ctx);
Expand Down Expand Up @@ -486,11 +488,13 @@ int main(int argc, char **argv)
qWarning() << "Failed to detect server version";
break;
case Account::ServerSupportLevel::Unsupported:
qFatal("Error unsupported server");
qCritical() << "Error unsupported server";
exit(1);
}

if (capabilitiesJob->reply()->error() != QNetworkReply::NoError) {
qFatal("Error connecting to server");
qCritical() << "Error connecting to server";
exit(1);
}

auto userJob = new JsonApiJob(ctx.account, QStringLiteral("ocs/v1.php/cloud/user"), {}, {}, nullptr);
Expand All @@ -509,11 +513,11 @@ int main(int argc, char **argv)
} else {
switch (checkServerJob->reply()->error()) {
case QNetworkReply::OperationCanceledError:
qFatal("Looking up %s timed out.", qPrintable(ctx.account->url().toString()));
break;
qCritical() << "Looking up " << ctx.account->url().toString() << " timed out.";
default:
qFatal("Failed to resolve %s Error: %s.", qPrintable(ctx.account->url().toString()), qPrintable(checkServerJob->reply()->errorString()));
qCritical() << "Failed to resolve " << ctx.account->url().toString() << " Error: " << checkServerJob->reply()->errorString();
}
exit(1);
}
});

Expand Down

0 comments on commit f6c73ee

Please sign in to comment.