mirror of https://github.com/odrling/Aegisub
Remove some exceptions not used for much of anything
This commit is contained in:
parent
cfd2698b03
commit
789ff25f27
|
@ -37,12 +37,11 @@ ConfigVisitor::ConfigVisitor(OptionValueMap &val, const std::string &member_name
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class ErrorType>
|
|
||||||
void ConfigVisitor::Error(const char *message) {
|
void ConfigVisitor::Error(const char *message) {
|
||||||
if (ignore_errors)
|
if (ignore_errors)
|
||||||
LOG_E("option/load/config_visitor") << "Error loading option from user configuration: " << message;
|
LOG_E("option/load/config_visitor") << "Error loading option from user configuration: " << message;
|
||||||
else
|
else
|
||||||
throw ErrorType(message);
|
throw OptionJsonValueError(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigVisitor::Visit(const json::Object& object) {
|
void ConfigVisitor::Visit(const json::Object& object) {
|
||||||
|
@ -62,11 +61,11 @@ std::unique_ptr<OptionValue> ConfigVisitor::ReadArray(json::Array const& src, st
|
||||||
|
|
||||||
for (json::Object const& obj : src) {
|
for (json::Object const& obj : src) {
|
||||||
if (obj.size() != 1) {
|
if (obj.size() != 1) {
|
||||||
Error<OptionJsonValueArray>("Invalid array member");
|
Error("Invalid array member");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (obj.begin()->first != array_type) {
|
if (obj.begin()->first != array_type) {
|
||||||
Error<OptionJsonValueArray>("Attempt to insert value into array of wrong type");
|
Error("Attempt to insert value into array of wrong type");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,13 +77,13 @@ std::unique_ptr<OptionValue> ConfigVisitor::ReadArray(json::Array const& src, st
|
||||||
|
|
||||||
void ConfigVisitor::Visit(const json::Array& array) {
|
void ConfigVisitor::Visit(const json::Array& array) {
|
||||||
if (array.empty()) {
|
if (array.empty()) {
|
||||||
Error<OptionJsonValueArray>("Cannot infer the type of an empty array");
|
Error("Cannot infer the type of an empty array");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
json::Object const& front = array.front();
|
json::Object const& front = array.front();
|
||||||
if (front.size() != 1) {
|
if (front.size() != 1) {
|
||||||
Error<OptionJsonValueArray>("Invalid array member");
|
Error("Invalid array member");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,7 +100,7 @@ void ConfigVisitor::Visit(const json::Array& array) {
|
||||||
else if (array_type == "color")
|
else if (array_type == "color")
|
||||||
AddOptionValue(ReadArray<OptionValueListColor>(array, array_type));
|
AddOptionValue(ReadArray<OptionValueListColor>(array, array_type));
|
||||||
else
|
else
|
||||||
Error<OptionJsonValueArray>("Array type not handled");
|
Error("Array type not handled");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigVisitor::Visit(const json::Integer& number) {
|
void ConfigVisitor::Visit(const json::Integer& number) {
|
||||||
|
@ -130,7 +129,7 @@ void ConfigVisitor::Visit(const json::Boolean& boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigVisitor::Visit(const json::Null& null) {
|
void ConfigVisitor::Visit(const json::Null& null) {
|
||||||
Error<OptionJsonValueNull>("Attempt to read null value");
|
Error("Attempt to read null value");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigVisitor::AddOptionValue(std::unique_ptr<OptionValue>&& opt) {
|
void ConfigVisitor::AddOptionValue(std::unique_ptr<OptionValue>&& opt) {
|
||||||
|
@ -148,7 +147,7 @@ void ConfigVisitor::AddOptionValue(std::unique_ptr<OptionValue>&& opt) {
|
||||||
try {
|
try {
|
||||||
values[name]->Set(opt.get());
|
values[name]->Set(opt.get());
|
||||||
}
|
}
|
||||||
catch (agi::OptionValueError const& e) {
|
catch (agi::InternalError const& e) {
|
||||||
if (ignore_errors)
|
if (ignore_errors)
|
||||||
LOG_E("option/load/config_visitor") << "Error loading option from user configuration: " << e.GetMessage();
|
LOG_E("option/load/config_visitor") << "Error loading option from user configuration: " << e.GetMessage();
|
||||||
else
|
else
|
||||||
|
|
|
@ -26,9 +26,6 @@
|
||||||
namespace agi {
|
namespace agi {
|
||||||
|
|
||||||
DEFINE_EXCEPTION(OptionJsonValueError, Exception);
|
DEFINE_EXCEPTION(OptionJsonValueError, Exception);
|
||||||
DEFINE_EXCEPTION(OptionJsonValueArray, OptionJsonValueError);
|
|
||||||
DEFINE_EXCEPTION(OptionJsonValueSingle, OptionJsonValueError);
|
|
||||||
DEFINE_EXCEPTION(OptionJsonValueNull, OptionJsonValueError);
|
|
||||||
|
|
||||||
class ConfigVisitor final : public json::ConstVisitor {
|
class ConfigVisitor final : public json::ConstVisitor {
|
||||||
/// Option map being populated
|
/// Option map being populated
|
||||||
|
@ -42,7 +39,6 @@ class ConfigVisitor final : public json::ConstVisitor {
|
||||||
/// default value is changed to the new one
|
/// default value is changed to the new one
|
||||||
bool replace;
|
bool replace;
|
||||||
|
|
||||||
template<class ErrorType>
|
|
||||||
void Error(const char *message);
|
void Error(const char *message);
|
||||||
|
|
||||||
template<class OptionValueType>
|
template<class OptionValueType>
|
||||||
|
|
|
@ -35,7 +35,6 @@ namespace agi {
|
||||||
|
|
||||||
DEFINE_EXCEPTION(OptionError, Exception);
|
DEFINE_EXCEPTION(OptionError, Exception);
|
||||||
DEFINE_EXCEPTION(OptionErrorNotFound, OptionError);
|
DEFINE_EXCEPTION(OptionErrorNotFound, OptionError);
|
||||||
DEFINE_EXCEPTION(OptionErrorDuplicateKey, OptionError);
|
|
||||||
|
|
||||||
class OptionValue;
|
class OptionValue;
|
||||||
|
|
||||||
|
|
|
@ -27,9 +27,6 @@
|
||||||
#undef Bool
|
#undef Bool
|
||||||
|
|
||||||
namespace agi {
|
namespace agi {
|
||||||
DEFINE_EXCEPTION(OptionValueError, Exception);
|
|
||||||
DEFINE_EXCEPTION(OptionValueErrorInvalidType, OptionValueError);
|
|
||||||
|
|
||||||
/// Option type
|
/// Option type
|
||||||
/// No bitsets here.
|
/// No bitsets here.
|
||||||
enum class OptionType {
|
enum class OptionType {
|
||||||
|
@ -67,8 +64,8 @@ class OptionValue {
|
||||||
throw agi::InternalError("Invalid option type");
|
throw agi::InternalError("Invalid option type");
|
||||||
}
|
}
|
||||||
|
|
||||||
OptionValueErrorInvalidType TypeError(OptionType type) const {
|
InternalError TypeError(OptionType type) const {
|
||||||
return OptionValueErrorInvalidType("Invalid type for option " + name + ": expected " + TypeToString(type) + ", got " + TypeToString(GetType()));
|
return InternalError("Invalid type for option " + name + ": expected " + TypeToString(type) + ", got " + TypeToString(GetType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
@ -206,8 +206,8 @@ struct tool_translation_assistant final : public Command {
|
||||||
try {
|
try {
|
||||||
c->dialog->ShowModal<DialogTranslation>(c);
|
c->dialog->ShowModal<DialogTranslation>(c);
|
||||||
}
|
}
|
||||||
catch (agi::Exception const& e) {
|
catch (DialogTranslation::NothingToTranslate const&) {
|
||||||
wxMessageBox(to_wx(e.GetMessage()));
|
wxMessageBox(_("There is nothing to translate in the file."));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -159,7 +159,7 @@ DialogTranslation::DialogTranslation(agi::Context *c)
|
||||||
blocks = active_line->ParseTags();
|
blocks = active_line->ParseTags();
|
||||||
if (bad_block(blocks[0])) {
|
if (bad_block(blocks[0])) {
|
||||||
if (!NextBlock())
|
if (!NextBlock())
|
||||||
throw NothingToTranslate(from_wx(_("There is nothing to translate in the file.")));
|
throw NothingToTranslate();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
UpdateDisplay();
|
UpdateDisplay();
|
||||||
|
|
|
@ -75,5 +75,5 @@ public:
|
||||||
void Commit(bool next);
|
void Commit(bool next);
|
||||||
void InsertOriginal();
|
void InsertOriginal();
|
||||||
|
|
||||||
DEFINE_EXCEPTION(NothingToTranslate, agi::Exception);;
|
struct NothingToTranslate { };
|
||||||
};
|
};
|
||||||
|
|
|
@ -212,50 +212,50 @@ TEST_F(lagi_option, empty_array_decays_to_first_used_type) {
|
||||||
empty_arr_options opt;
|
empty_arr_options opt;
|
||||||
EXPECT_NO_THROW(opt.Get("arr")->GetListBool());
|
EXPECT_NO_THROW(opt.Get("arr")->GetListBool());
|
||||||
|
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
empty_arr_options opt;
|
empty_arr_options opt;
|
||||||
EXPECT_NO_THROW(opt.Get("arr")->GetListColor());
|
EXPECT_NO_THROW(opt.Get("arr")->GetListColor());
|
||||||
|
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
empty_arr_options opt;
|
empty_arr_options opt;
|
||||||
EXPECT_NO_THROW(opt.Get("arr")->GetListDouble());
|
EXPECT_NO_THROW(opt.Get("arr")->GetListDouble());
|
||||||
|
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
empty_arr_options opt;
|
empty_arr_options opt;
|
||||||
EXPECT_NO_THROW(opt.Get("arr")->GetListInt());
|
EXPECT_NO_THROW(opt.Get("arr")->GetListInt());
|
||||||
|
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListString(), agi::InternalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
empty_arr_options opt;
|
empty_arr_options opt;
|
||||||
EXPECT_NO_THROW(opt.Get("arr")->GetListString());
|
EXPECT_NO_THROW(opt.Get("arr")->GetListString());
|
||||||
|
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListBool(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListColor(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListDouble(), agi::InternalError);
|
||||||
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::OptionValueErrorInvalidType);
|
EXPECT_THROW(opt.Get("arr")->GetListInt(), agi::InternalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue