jbe/bsw@0: local function open(class)
jbe/bsw@0: slot.put('
')
jbe/bsw@0: end
jbe/bsw@0: local function open_head()
jbe/bsw@0: slot.put('')
jbe/bsw@0: end
jbe/bsw@0: local function close_head()
jbe/bsw@0: slot.put('
')
jbe/bsw@0: end
jbe/bsw@0: local function close()
jbe/bsw@0: slot.put('')
jbe/bsw@0: end
jbe/bsw@0: function trace._render_sub_tree(node)
jbe/bsw@0: local function render_children(tail)
jbe/bsw@0: if #node > 0 then
jbe/bsw@0: slot.put('')
jbe/bsw@0: for idx, child in ipairs(node) do
jbe/bsw@0: trace._render_sub_tree(child)
jbe/bsw@0: end
jbe/bsw@0: if tail then
jbe/bsw@0: slot.put(tail)
jbe/bsw@0: end
jbe/bsw@0: slot.put("
")
jbe/bsw@0: end
jbe/bsw@0: end
jbe/bsw@0: local function close_with_children()
jbe/bsw@0: close_head()
jbe/bsw@0: render_children()
jbe/bsw@0: close()
jbe/bsw@0: end
jbe/bsw@0: local node_type = node.type
jbe/bsw@0: if node_type == "root" then
jbe/bsw@0: render_children()
jbe/bsw@0: elseif node_type == "debug" then
jbe/bsw@0: open("debug")
jbe/bsw@0: slot.put(encode.html(node.message))
jbe/bsw@0: close()
poelzi@31: elseif node_type == "debug_table" then
poelzi@31: open("debug")
poelzi@31: slot.put("")
poelzi@31: if type(node.message) == "table" then
poelzi@31: for k, v in pairs(node.message) do
jbe@45: slot.put("", encode.html(tostring(k)), " | ", encode.html(tostring(v)), " |
")
poelzi@31: end
poelzi@31: slot.put("
")
poelzi@31: else
poelzi@31: slot.put("debug_table: not of table type")
poelzi@31: end
poelzi@31: close()
poelzi@29: elseif node_type == "traceback" then
poelzi@29: open("debug")
poelzi@29: slot.put('')
poelzi@29: slot.put(encode.html(node.message))
poelzi@29: slot.put('
')
poelzi@29: close()
jbe/bsw@0: elseif node_type == "request" then
jbe/bsw@0: open("request")
jbe/bsw@0: open_head()
jbe/bsw@0: slot.put("REQUESTED")
jbe/bsw@0: if node.view then
jbe/bsw@0: slot.put(" VIEW")
jbe/bsw@0: elseif node.action then
jbe/bsw@0: slot.put(" ACTION")
jbe/bsw@0: end
jbe/bsw@0: slot.put(
jbe/bsw@0: ": ",
jbe/bsw@0: encode.html(node.module),
jbe/bsw@0: "/",
jbe/bsw@0: encode.html(node.view or node.action)
jbe/bsw@0: )
jbe/bsw@0: close_with_children()
jbe/bsw@0: elseif node_type == "config" then
jbe/bsw@0: open("config")
jbe/bsw@0: open_head()
jbe/bsw@0: slot.put('Configuration "', encode.html(node.name), '"')
jbe/bsw@0: close_with_children()
jbe/bsw@0: elseif node_type == "filter" then
jbe/bsw@0: open("filter")
jbe/bsw@0: open_head()
jbe/bsw@0: slot.put(encode.html(node.path))
jbe/bsw@0: close_with_children()
jbe/bsw@0: elseif node_type == "view" then
jbe/bsw@0: open("view")
jbe/bsw@0: open_head()
jbe/bsw@0: slot.put(
jbe/bsw@0: "EXECUTE VIEW: ",
jbe/bsw@0: encode.html(node.module),
jbe/bsw@0: "/",
jbe/bsw@0: encode.html(node.view)
jbe/bsw@0: )
jbe/bsw@0: close_with_children()
jbe/bsw@0: elseif node_type == "action" then
jbe/bsw@0: if
jbe/bsw@0: node.status and (
jbe/bsw@0: node.status == "ok" or
jbe/bsw@0: string.find(node.status, "^ok_")
jbe/bsw@0: )
jbe/bsw@0: then
jbe/bsw@0: open("action_success")
jbe/bsw@0: elseif
jbe/bsw@0: node.status and (
jbe/bsw@0: node.status == "error" or
jbe/bsw@0: string.find(node.status, "^error_")
jbe/bsw@0: )
jbe/bsw@0: then
jbe/bsw@0: open("action_softfail")
jbe/bsw@0: else
jbe/bsw@0: open("action_neutral")
jbe/bsw@0: end
jbe/bsw@0: open_head()
jbe/bsw@0: slot.put(
jbe/bsw@0: "EXECUTE ACTION: ",
jbe/bsw@0: encode.html(node.module),
jbe/bsw@0: "/",
jbe/bsw@0: encode.html(node.action)
jbe/bsw@0: )
jbe/bsw@0: close_head()
jbe/bsw@0: if node.status == "softfail" then
jbe/bsw@0: render_children(
jbe/bsw@0: 'Status code: "' ..
jbe/bsw@0: encode.html(node.failure_code) ..
jbe/bsw@0: '"'
jbe/bsw@0: )
jbe/bsw@0: else
jbe/bsw@0: render_children()
jbe/bsw@0: end
jbe/bsw@0: close()
jbe/bsw@0: elseif node_type == "redirect" then
jbe/bsw@0: open("redirect")
jbe/bsw@0: open_head()
jbe/bsw@0: slot.put("303 REDIRECT TO VIEW: ", encode.html(node.module), "/", encode.html(node.view))
jbe/bsw@0: close_with_children()
jbe/bsw@0: elseif node_type == "forward" then
jbe/bsw@0: open("forward")
jbe/bsw@0: open_head()
jbe/bsw@0: slot.put("INTERNAL FORWARD TO VIEW: ", encode.html(node.module), "/", encode.html(node.view))
jbe/bsw@0: close_with_children()
jbe/bsw@0: elseif node_type == "exectime" then
jbe/bsw@0: open("exectime")
jbe/bsw@0: open_head()
jbe/bsw@0: slot.put(
jbe/bsw@0: "Finished after " ..
jbe@65: string.format("%.1f", extos.monotonic_hires_time() * 1000) ..
jbe/bsw@0: ' ms (' ..
jbe/bsw@0: string.format("%.1f", os.clock() * 1000) ..
jbe/bsw@0: ' ms CPU)'
jbe/bsw@0: )
jbe/bsw@0: close_with_children()
jbe/bsw@0: elseif node_type == "sql" then
jbe/bsw@0: open("sql")
jbe/bsw@0: if node.error_position then
jbe/bsw@0: -- error position starts counting with 1
jbe/bsw@0: local part1 = string.sub(node.command, 1, node.error_position - 1)
jbe/bsw@0: --local part2 = string.sub(node.command, node.error_position - 1, node.error_position + 1)
jbe/bsw@0: local part2 = string.sub(node.command, node.error_position)
jbe/bsw@0: slot.put(encode.html(part1))
jbe/bsw@0: slot.put('⇒')
jbe/bsw@0: slot.put(encode.html(part2))
jbe/bsw@0: --slot.put('')
jbe/bsw@0: --slot.put(encode.html(part3))
jbe/bsw@0: else
jbe/bsw@0: slot.put(encode.html(node.command))
jbe/bsw@0: end
jbe/bsw@0: close();
jbe/bsw@0: elseif node_type == "error" then
jbe/bsw@0: open("error")
jbe/bsw@0: open_head()
jbe/bsw@0: slot.put("UNEXPECTED ERROR")
jbe/bsw@0: close_head()
jbe/bsw@0: close()
jbe/bsw@0: end
jbe/bsw@0: end