Always use our own exception tree

This commit is contained in:
emeric
2018-07-26 10:26:49 +02:00
parent 853bcbe008
commit a31fb3c062
9 changed files with 27 additions and 20 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ static std::string averror_to_string(int error)
}
MediaFileException::MediaFileException(int avError)
: LmsException("MediaFileException: " + averror_to_string(avError))
: AvException("MediaFileException: " + averror_to_string(avError))
{
}
+7 -1
View File
@@ -57,7 +57,13 @@ struct StreamInfo
std::size_t bitrate;
};
class MediaFileException : public LmsException
class AvException : public LmsException
{
public:
AvException(const std::string& msg) : LmsException(msg) {}
};
class MediaFileException : public AvException
{
public:
MediaFileException(int avError);
+4 -4
View File
@@ -52,7 +52,7 @@ std::string encodingToMimetype(Encoding encoding)
return encodingInfo.mimetype;
}
throw std::logic_error("encoding_to_mimetype failed!");
throw AvException("Invalid encoding");
}
int encodingToInt(Encoding encoding)
@@ -63,7 +63,7 @@ int encodingToInt(Encoding encoding)
return encodingInfo.id;
}
throw std::logic_error("encoding_to_int failed!");
throw AvException("Invalid encoding");
}
Encoding encodingFromInt(int encodingId)
@@ -74,7 +74,7 @@ Encoding encodingFromInt(int encodingId)
return encodingInfo.encoding;
}
throw std::logic_error("encoding_from_int failed!");
throw AvException("Invalid encodingId");
}
// TODO, parametrize?
@@ -104,7 +104,7 @@ Transcoder::init()
if (!avConvPath.empty())
LMS_LOG(TRANSCODE, INFO) << "Using transcoder " << avConvPath.string();
else
throw std::runtime_error("Cannot find any transcoder binary!");
throw AvException("Cannot find any transcoder binary!");
}
Transcoder::Transcoder(boost::filesystem::path filePath, TranscodeParameters parameters)
+2 -4
View File
@@ -20,9 +20,8 @@
#include "SqlQuery.hpp"
#include <algorithm>
#include <cassert>
#include <sstream>
#include <stdexcept>
WhereClause&
WhereClause::And(const WhereClause& otherClause)
@@ -70,8 +69,7 @@ WhereClause::get(void) const
WhereClause&
WhereClause::bind(const std::string& bindArg)
{
if (_bindArgs.size() >= static_cast<std::size_t>( std::count(_clause.begin(), _clause.end(), '?') ))
throw std::runtime_error("Too many bind args!");
assert(_bindArgs.size() < static_cast<std::size_t>(std::count(_clause.begin(), _clause.end(), '?')));
_bindArgs.push_back(bindArg);
+2 -2
View File
@@ -288,7 +288,7 @@ LmsApplication::handleAuthEvent()
catch (std::exception& e)
{
LMS_LOG(UI, ERROR) << "Error while handling auth event: " << e.what();
throw std::runtime_error("Internal error");
throw LmsException("Internal error"); // Do not put details here at it appears on the user rendered html
}
}
@@ -483,7 +483,7 @@ LmsApplication::notify(const Wt::WEvent& event)
catch (std::exception& e)
{
LMS_LOG(UI, ERROR) << "Caught exception: " << e.what();
throw std::runtime_error("Internal error");
throw LmsException("Internal error"); // Do not put details here at it appears on the user rendered html
}
}
+2 -1
View File
@@ -24,6 +24,7 @@
#include <Wt/WPushButton.h>
#include <Wt/Auth/Identity.h>
#include "utils/Exception.hpp"
#include "utils/Logger.hpp"
#include "common/Validators.hpp"
@@ -58,7 +59,7 @@ class InitWizardModel : public Wt::WFormModel
// Check if a user already exist
// If it's the case, just do nothing
if (!Database::User::getAll(LmsApp->getDboSession()).empty())
throw std::runtime_error("Admin user already created");
throw LmsException("Admin user already created");
// Create user
Wt::Auth::User authUser = LmsApp->getDb().getUserDatabase().registerNew();
+3 -2
View File
@@ -30,8 +30,9 @@
#include <Wt/WStringListModel.h>
#include "common/Validators.hpp"
#include "utils/Utils.hpp"
#include "utils/Exception.hpp"
#include "utils/Logger.hpp"
#include "utils/Utils.hpp"
#include "LmsApplication.hpp"
@@ -79,7 +80,7 @@ class UserModel : public Wt::WFormModel
Database::User::pointer user = LmsApp->getDb().getUser(authUser);
if (user == LmsApp->getUser())
throw std::runtime_error("Cannot edit ourselves");
throw LmsException("Cannot edit ourselves");
auto bitrate = getBitrateLimitRow(user->getMaxAudioBitrate());
if (bitrate)
+3 -2
View File
@@ -22,6 +22,7 @@
#include <Wt/WApplication.h>
#include <Wt/Http/Response.h>
#include "utils/Exception.hpp"
#include "utils/Logger.hpp"
#include "utils/Utils.hpp"
@@ -58,7 +59,7 @@ ImageResource::getDefaultCover(std::size_t size)
Image::Image image;
if (!image.load( Wt::WApplication::instance()->docRoot() + unknownCoverPath ))
throw std::runtime_error("Cannot read default cover file");
throw LmsException("Cannot read default cover file");
image.scale(size);
@@ -80,7 +81,7 @@ ImageResource::getDefaultArtistImage(std::size_t size)
Image::Image image;
if (!image.load( Wt::WApplication::instance()->docRoot() + unknownArtistImagePath))
throw std::runtime_error("Cannot read default artist image file");
throw LmsException("Cannot read default artist image file");
image.scale(size);
+3 -3
View File
@@ -21,11 +21,11 @@
#include <array>
#include <fstream>
#include <stdexcept>
#include <boost/crc.hpp> // for boost::crc_32_type
#include <boost/tokenizer.hpp>
#include "utils/Exception.hpp"
#include "utils/Logger.hpp"
boost::filesystem::path searchExecPath(std::string filename)
@@ -34,7 +34,7 @@ boost::filesystem::path searchExecPath(std::string filename)
path = ::getenv("PATH");
if (path.empty())
throw std::runtime_error("Environment variable PATH not found");
throw LmsException("Environment variable PATH not found");
std::string result;
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
@@ -75,7 +75,7 @@ void computeCrc(const boost::filesystem::path& p, std::vector<unsigned char>& cr
else
{
LMS_LOG(DBUPDATER, ERROR) << "Failed to open file '" << p.string() << "'";
throw std::runtime_error("Failed to open file '" + p.string() + "'" );
throw LmsException("Failed to open file '" + p.string() + "'" );
}
// Copy back result into the vector