mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-17 20:50:44 +00:00
Refactoring javascript executor scripts.main error handling
This commit is contained in:
@ -90,14 +90,20 @@ public class QJavaScriptExecutor implements QCodeExecutor
|
||||
{
|
||||
%s
|
||||
|
||||
var mainFunction = null;
|
||||
try
|
||||
{
|
||||
if(script && script.main)
|
||||
if(script && script.main && typeof script.main == "function")
|
||||
{
|
||||
return (script.main());
|
||||
mainFunction = script.main;
|
||||
}
|
||||
}
|
||||
catch(e) { }
|
||||
|
||||
if(mainFunction != null)
|
||||
{
|
||||
return (mainFunction());
|
||||
}
|
||||
})();
|
||||
""".formatted(code);
|
||||
|
||||
|
@ -35,6 +35,7 @@ import com.kingsrook.qqq.backend.core.model.metadata.code.QCodeUsage;
|
||||
import com.kingsrook.qqq.backend.core.model.session.QSession;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
@ -123,6 +124,29 @@ class ExecuteCodeActionTest
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void testCompiledFromTypeScriptThatThrows() throws QException
|
||||
{
|
||||
assertThatThrownBy(() ->
|
||||
{
|
||||
testOne(4, """
|
||||
var script = (function (exports) {
|
||||
function main() {
|
||||
throw "inline script failure";
|
||||
return (output);
|
||||
}
|
||||
exports.main = main;
|
||||
return exports;
|
||||
})({});
|
||||
""");
|
||||
}).hasMessageContaining("inline script failure");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
Reference in New Issue
Block a user