Allow loging js execution errors
This commit is contained in:
parent
7aa1176a36
commit
b27ca57e1a
|
@ -8,6 +8,9 @@ const { getJsHelperList } = require("./list")
|
|||
let runJS
|
||||
module.exports.setJSRunner = runner => (runJS = runner)
|
||||
|
||||
let onErrorLog
|
||||
module.exports.setOnErrorLog = delegate => (onErrorLog = delegate)
|
||||
|
||||
// Helper utility to strip square brackets from a value
|
||||
const removeSquareBrackets = value => {
|
||||
if (!value || typeof value !== "string") {
|
||||
|
@ -56,6 +59,8 @@ module.exports.processJS = (handlebars, context) => {
|
|||
const res = { data: runJS(js, sandboxContext) }
|
||||
return `{{${LITERAL_MARKER} js_result-${JSON.stringify(res)}}}`
|
||||
} catch (error) {
|
||||
onErrorLog && onErrorLog(error)
|
||||
|
||||
if (error.code === "ERR_SCRIPT_EXECUTION_TIMEOUT") {
|
||||
return "Timed out while executing JS"
|
||||
}
|
||||
|
|
|
@ -365,6 +365,7 @@ module.exports.doesContainString = (template, string) => {
|
|||
}
|
||||
|
||||
module.exports.setJSRunner = javascript.setJSRunner
|
||||
module.exports.setOnErrorLog = javascript.setOnErrorLog
|
||||
|
||||
module.exports.convertToJS = hbs => {
|
||||
const blocks = exports.findHBSBlocks(hbs)
|
||||
|
|
|
@ -20,6 +20,7 @@ export const disableEscaping = templates.disableEscaping
|
|||
export const findHBSBlocks = templates.findHBSBlocks
|
||||
export const convertToJS = templates.convertToJS
|
||||
export const setJSRunner = templates.setJSRunner
|
||||
export const setOnErrorLog = templates.setOnErrorLog
|
||||
export const FIND_ANY_HBS_REGEX = templates.FIND_ANY_HBS_REGEX
|
||||
export const helpersToRemoveForJs = templates.helpersToRemoveForJs
|
||||
|
||||
|
|
Loading…
Reference in New Issue