forked from mia/Aegisub
Throw typed exceptions in automation rather than strings
Originally committed to SVN as r5639.
This commit is contained in:
parent
6d0e44baad
commit
c09259c93d
4 changed files with 18 additions and 44 deletions
|
@ -293,7 +293,7 @@ namespace Automation4 {
|
||||||
FeatureFilter::FeatureFilter(const wxString &_name, const wxString &_description, int _priority)
|
FeatureFilter::FeatureFilter(const wxString &_name, const wxString &_description, int _priority)
|
||||||
: Feature(SCRIPTFEATURE_FILTER, _name)
|
: Feature(SCRIPTFEATURE_FILTER, _name)
|
||||||
, AssExportFilter(_name, _description, _priority)
|
, AssExportFilter(_name, _description, _priority)
|
||||||
, config_dialog(0)
|
, config_dialog(0)
|
||||||
{
|
{
|
||||||
AssExportFilterChain::Register(this);
|
AssExportFilterChain::Register(this);
|
||||||
}
|
}
|
||||||
|
@ -735,22 +735,12 @@ namespace Automation4 {
|
||||||
bool more = dir.GetFirst(&fn, wxEmptyString, wxDIR_FILES);
|
bool more = dir.GetFirst(&fn, wxEmptyString, wxDIR_FILES);
|
||||||
while (more) {
|
while (more) {
|
||||||
script_path.SetName(fn);
|
script_path.SetName(fn);
|
||||||
try {
|
wxString fullpath = script_path.GetFullPath();
|
||||||
wxString fullpath = script_path.GetFullPath();
|
if (ScriptFactory::CanHandleScriptFormat(fullpath)) {
|
||||||
if (ScriptFactory::CanHandleScriptFormat(fullpath)) {
|
Script *s = ScriptFactory::CreateFromFile(fullpath, true);
|
||||||
Script *s = ScriptFactory::CreateFromFile(fullpath, true);
|
Add(s);
|
||||||
Add(s);
|
if (!s->GetLoadedState()) error_count++;
|
||||||
if (!s->GetLoadedState()) error_count++;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (const char *e) {
|
|
||||||
error_count++;
|
|
||||||
wxLogError("Error loading Automation script: %s\n%s", fn, e);
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
error_count++;
|
|
||||||
wxLogError("Error loading Automation script: %s\nUnknown error.", fn);
|
|
||||||
}
|
|
||||||
more = dir.GetNext(&fn);
|
more = dir.GetNext(&fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -852,7 +842,7 @@ namespace Automation4 {
|
||||||
GetFactories();
|
GetFactories();
|
||||||
|
|
||||||
if (find(factories->begin(), factories->end(), factory) != factories->end())
|
if (find(factories->begin(), factories->end(), factory) != factories->end())
|
||||||
throw "Automation 4: Attempt to register the same script factory multiple times. This should never happen.";
|
throw agi::InternalError("Automation 4: Attempt to register the same script factory multiple times. This should never happen.", 0);
|
||||||
|
|
||||||
factories->push_back(factory);
|
factories->push_back(factory);
|
||||||
}
|
}
|
||||||
|
@ -939,7 +929,7 @@ namespace Automation4 {
|
||||||
/// @param filename
|
/// @param filename
|
||||||
///
|
///
|
||||||
UnknownScript::UnknownScript(const wxString &filename)
|
UnknownScript::UnknownScript(const wxString &filename)
|
||||||
: Script(filename)
|
: Script(filename)
|
||||||
{
|
{
|
||||||
wxFileName fn(filename);
|
wxFileName fn(filename);
|
||||||
name = fn.GetName();
|
name = fn.GetName();
|
||||||
|
|
|
@ -77,6 +77,9 @@ DECLARE_EVENT_TYPE(wxEVT_AUTOMATION_SCRIPT_COMPLETED, -1)
|
||||||
|
|
||||||
/// DOCME
|
/// DOCME
|
||||||
namespace Automation4 {
|
namespace Automation4 {
|
||||||
|
DEFINE_BASE_EXCEPTION_NOINNER(AutomationError, agi::Exception)
|
||||||
|
DEFINE_SIMPLE_EXCEPTION_NOINNER(ScriptLoadError, AutomationError, "automation/load/generic")
|
||||||
|
DEFINE_SIMPLE_EXCEPTION_NOINNER(MacroRunError, AutomationError, "automation/macro/generic")
|
||||||
|
|
||||||
// Calculate the extents of a text string given a style
|
// Calculate the extents of a text string given a style
|
||||||
bool CalculateTextExtents(AssStyle *style, wxString &text, double &width, double &height, double &descent, double &extlead);
|
bool CalculateTextExtents(AssStyle *style, wxString &text, double &width, double &height, double &descent, double &extlead);
|
||||||
|
|
|
@ -257,7 +257,7 @@ namespace Automation4 {
|
||||||
if (lua_load(L, script_reader.reader_func, &script_reader, GetPrettyFilename().mb_str(wxConvUTF8))) {
|
if (lua_load(L, script_reader.reader_func, &script_reader, GetPrettyFilename().mb_str(wxConvUTF8))) {
|
||||||
wxString err(lua_tostring(L, -1), wxConvUTF8);
|
wxString err(lua_tostring(L, -1), wxConvUTF8);
|
||||||
err.Prepend("Error loading Lua script \"" + GetPrettyFilename() + "\":\n\n");
|
err.Prepend("Error loading Lua script \"" + GetPrettyFilename() + "\":\n\n");
|
||||||
throw err;
|
throw ScriptLoadError(STD_STR(err));
|
||||||
}
|
}
|
||||||
_stackcheck.check_stack(1);
|
_stackcheck.check_stack(1);
|
||||||
// and execute it
|
// and execute it
|
||||||
|
@ -267,16 +267,14 @@ namespace Automation4 {
|
||||||
// error occurred, assumed to be on top of Lua stack
|
// error occurred, assumed to be on top of Lua stack
|
||||||
wxString err(lua_tostring(L, -1), wxConvUTF8);
|
wxString err(lua_tostring(L, -1), wxConvUTF8);
|
||||||
err.Prepend("Error initialising Lua script \"" + GetPrettyFilename() + "\":\n\n");
|
err.Prepend("Error initialising Lua script \"" + GetPrettyFilename() + "\":\n\n");
|
||||||
throw err;
|
throw ScriptLoadError(STD_STR(err));
|
||||||
}
|
}
|
||||||
_stackcheck.check_stack(0);
|
_stackcheck.check_stack(0);
|
||||||
lua_getglobal(L, "version");
|
lua_getglobal(L, "version");
|
||||||
if (lua_isnumber(L, -1)) {
|
if (lua_isnumber(L, -1)) {
|
||||||
if (lua_tointeger(L, -1) == 3) {
|
if (lua_tointeger(L, -1) == 3) {
|
||||||
lua_pop(L, 1); // just to avoid tripping the stackcheck in debug
|
lua_pop(L, 1); // just to avoid tripping the stackcheck in debug
|
||||||
// So this is an auto3 script...
|
throw ScriptLoadError("Attempted to load an Automation 3 script as an Automation 4 Lua script. Automation 3 is no longer supported.");
|
||||||
// Throw it as an exception, the script factory manager will catch this and use the auto3 script instead of this script object
|
|
||||||
throw "Attempted to load an Automation 3 script as an Automation 4 Lua script. Automation 3 is no longer supported.";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lua_getglobal(L, "script_name");
|
lua_getglobal(L, "script_name");
|
||||||
|
@ -302,31 +300,14 @@ namespace Automation4 {
|
||||||
_stackcheck.check_stack(0);
|
_stackcheck.check_stack(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (const char *e) {
|
catch (agi::Exception const& e) {
|
||||||
Destroy();
|
Destroy();
|
||||||
loaded = false;
|
loaded = false;
|
||||||
name = GetPrettyFilename();
|
name = GetPrettyFilename();
|
||||||
description = wxString(e, wxConvUTF8);
|
description = e.GetChainedMessage();
|
||||||
}
|
|
||||||
catch (const wxString& e) {
|
|
||||||
Destroy();
|
|
||||||
loaded = false;
|
|
||||||
name = GetPrettyFilename();
|
|
||||||
description = e;
|
|
||||||
}
|
|
||||||
catch (Script *s) {
|
|
||||||
// Be sure to properly propagate any scripts throw
|
|
||||||
throw s;
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
Destroy();
|
|
||||||
loaded = false;
|
|
||||||
name = GetPrettyFilename();
|
|
||||||
description = "Unknown error initialising Lua script";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// @brief DOCME
|
/// @brief DOCME
|
||||||
/// @return
|
/// @return
|
||||||
///
|
///
|
||||||
|
|
|
@ -107,7 +107,7 @@ namespace {
|
||||||
lua_setfield(L, -2, name);
|
lua_setfield(L, -2, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEFINE_SIMPLE_EXCEPTION_NOINNER(BadField, agi::Exception, "automation/macro/bad_field")
|
DEFINE_SIMPLE_EXCEPTION_NOINNER(BadField, Automation4::MacroRunError, "automation/macro/bad_field")
|
||||||
BadField bad_field(const char *expected_type, const char *name, const char *line_clasee)
|
BadField bad_field(const char *expected_type, const char *name, const char *line_clasee)
|
||||||
{
|
{
|
||||||
return BadField(std::string("Invalid ") + expected_type + " '" + name + "' field in '" + line_clasee + "' class subtitle line");
|
return BadField(std::string("Invalid ") + expected_type + " '" + name + "' field in '" + line_clasee + "' class subtitle line");
|
||||||
|
|
Loading…
Reference in a new issue