Don't throw exception in TorrentInfo::saveToFile()

This commit is contained in:
Vladimir Golovnev (Glassez)
2021-10-06 21:53:56 +03:00
parent 41fc0fd084
commit 78459fcb31
4 changed files with 13 additions and 20 deletions

View File

@@ -40,7 +40,6 @@
#include <QUrl>
#include <QVector>
#include "base/exceptions.h"
#include "base/global.h"
#include "base/utils/fs.h"
#include "base/utils/io.h"
@@ -153,10 +152,10 @@ nonstd::expected<TorrentInfo, QString> TorrentInfo::loadFromFile(const QString &
return load(data);
}
void TorrentInfo::saveToFile(const QString &path) const
nonstd::expected<void, QString> TorrentInfo::saveToFile(const QString &path) const
{
if (!isValid())
throw RuntimeError {tr("Invalid metadata")};
return nonstd::make_unexpected(tr("Invalid metadata"));
try
{
@@ -164,12 +163,14 @@ void TorrentInfo::saveToFile(const QString &path) const
const lt::entry torrentEntry = torrentCreator.generate();
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(path, torrentEntry);
if (!result)
throw RuntimeError(result.error());
return result.get_unexpected();
}
catch (const lt::system_error &err)
{
throw RuntimeError(QString::fromLocal8Bit(err.what()));
return nonstd::make_unexpected(QString::fromLocal8Bit(err.what()));
}
return {};
}
bool TorrentInfo::isValid() const