Exit with 1 when --script <script> fails

We throw an exception if the script fails, so app_main() catches it
and exit with code 1 (in this way we can detect the problem running
scripts from command line).
This commit is contained in:
David Capello 2018-08-20 13:59:52 -03:00
parent 783b6f4ad9
commit 7620c05aed
3 changed files with 8 additions and 6 deletions

View File

@ -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
}

View File

@ -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

View File

@ -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; }