diff --git a/src/app/cli/default_cli_delegate.cpp b/src/app/cli/default_cli_delegate.cpp index 5ef2a1df1..806323873 100644 --- a/src/app/cli/default_cli_delegate.cpp +++ b/src/app/cli/default_cli_delegate.cpp @@ -129,7 +129,8 @@ void DefaultCliDelegate::execScript(const std::string& filename) #ifdef ENABLE_SCRIPTING script::StdoutEngineDelegate delegate; AppScripting engine(&delegate); - engine.evalFile(filename); + if (!engine.evalFile(filename)) + throw std::runtime_error("Error executing script"); #endif } diff --git a/src/script/engine.cpp b/src/script/engine.cpp index 8e8c35d26..ab39047fb 100644 --- a/src/script/engine.cpp +++ b/src/script/engine.cpp @@ -396,7 +396,7 @@ void Engine::printLastResult() m_printLastResult = true; } -void Engine::eval(const std::string& jsCode, +bool Engine::eval(const std::string& jsCode, const std::string& filename) { bool errFlag = true; @@ -429,16 +429,17 @@ void Engine::eval(const std::string& jsCode, js_pop(handle, 1); onAfterEval(errFlag); + return !errFlag; } -void Engine::evalFile(const std::string& filename) +bool Engine::evalFile(const std::string& filename) { std::stringstream buf; { std::ifstream s(FSTREAM_PATH(filename)); buf << s.rdbuf(); } - eval(buf.str(), filename); + return eval(buf.str(), filename); } } // namespace script diff --git a/src/script/engine.h b/src/script/engine.h index c4f629481..9a68fbf0e 100644 --- a/src/script/engine.h +++ b/src/script/engine.h @@ -141,9 +141,9 @@ namespace script { ~Engine(); void printLastResult(); - void eval(const std::string& jsCode, + bool eval(const std::string& jsCode, const std::string& filename = std::string()); - void evalFile(const std::string& filename); + bool evalFile(const std::string& filename); Context& context() { return m_ctx; }