Improve script exception error message.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
7a452f96a7
commit
5bbb880700
|
@ -113,4 +113,5 @@ void AngelScripResolver::FinalizeModule() {
|
|||
void AngelScripResolver::CreateScript(ScriptCategory category, const char* scriptName) {
|
||||
auto scriptString = _loadFunc(category, scriptName);
|
||||
_mainModule->AddScriptSection(scriptName, scriptString);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
|
||||
ContextPool* GetContextPool() { return _ctxPool; }
|
||||
|
||||
#define CALL_HOOK(name, setup) \
|
||||
#define CALL_HOOK(name, setup) \
|
||||
auto s = _type->Get##name(); \
|
||||
if (!s.Exists) \
|
||||
return; \
|
||||
|
@ -45,7 +45,13 @@ public:
|
|||
ctx->SetObject(_obj); \
|
||||
setup; \
|
||||
auto scriptResult = ctx->Execute(); \
|
||||
if (scriptResult != 0) { \
|
||||
if (scriptResult != asEXECUTION_FINISHED) { \
|
||||
if (scriptResult == asEXECUTION_EXCEPTION) { \
|
||||
std::stringstream err; \
|
||||
err << "Script exception in script '" << GetName() << "', line " << ctx->GetExceptionLineNumber() \
|
||||
<< ". Message: '" << ctx->GetExceptionString() << "'."; \
|
||||
throw CreatureException(err.str()); \
|
||||
} \
|
||||
throw CreatureException("Script didn't finish properly; message " + std::to_string(scriptResult)); \
|
||||
} \
|
||||
if (newContext) { \
|
||||
|
|
|
@ -56,6 +56,9 @@ void StopBeforeAttack(ExecutingMove@ attack, bool& result) override{
|
|||
AS_CLASS(OnAfterHitsScript,
|
||||
"int value = 0; void OnAfterHits(ExecutingMove@ attack, Pokemon@ target) override { value++; } "
|
||||
"int GetValue() { return value; }"),
|
||||
AS_CLASS(throwScript,
|
||||
R"(void PreventAttack(ExecutingMove@ attack, bool& result) override{ throw("test exception"); })"),
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
@ -271,4 +274,21 @@ TEST_CASE("Invoke OnAfterHits script function") {
|
|||
delete script;
|
||||
}
|
||||
|
||||
TEST_CASE("Handle script exceptions.") {
|
||||
auto mainLib = TestLibrary::GetLibrary();
|
||||
auto script = GetScript(mainLib, "throwScript");
|
||||
bool b = false;
|
||||
bool hasThrown = false;
|
||||
try{
|
||||
script->PreventAttack(nullptr, &b);
|
||||
}
|
||||
catch (const CreatureException& e){
|
||||
hasThrown = true;
|
||||
REQUIRE(strcmp("Script exception in script 'throwScript', line 1. Message: 'test exception'.", e.what()) == 0);
|
||||
}
|
||||
REQUIRE(hasThrown);
|
||||
|
||||
delete script;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue