From b75c918167019c7efd661fc94be0b6f67ced18ee Mon Sep 17 00:00:00 2001 From: Etiene Dalcol Date: Wed, 2 Dec 2015 10:15:33 +0100 Subject: [PATCH] feat(core): Allow hiding stacktrace Adds a configuration hide_stack_trace on conf.lua that, if set to true, will not show the stack trace and throw a default 500 Internal Server Error message. --- src/sailor.lua | 16 ++++++++++++++-- src/sailor/blank-app/conf/conf.lua | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/sailor.lua b/src/sailor.lua index 8e2c7b6..abd9f7e 100755 --- a/src/sailor.lua +++ b/src/sailor.lua @@ -1,5 +1,5 @@ -------------------------------------------------------------------------------- --- sailor.lua, v0.4.16: core functionalities of the framework +-- sailor.lua, v0.5.0: core functionalities of the framework -- This file is a part of Sailor project -- Copyright (c) 2014 Etiene Dalcol -- License: MIT @@ -13,7 +13,7 @@ local sailor = { conf = conf.sailor, _COPYRIGHT = "Copyright (C) 2014-2015 Etiene Dalcol", _DESCRIPTION = "Sailor is a framework for creating MVC web applications.", - _VERSION = "Sailor 0.4.16", + _VERSION = "Sailor 0.5.0", } -- Loads Lua@client's settings from Sailor conf. @@ -90,6 +90,14 @@ function sailor.init(r) POSTMULTI = POSTMULTI, base_path = sailor.base_path } + + if conf.extensions and conf.extensions.enable then + for _,e in pairs(conf.extensions.enable) do + package.path = 'extensions/' .. e .. '/?.lua;' .. package.path + local c = require "controllers.user" + end + end + sailor.r = r lp.setoutfunc("page:print") @@ -134,6 +142,10 @@ function sailor.route(page) -- Encapsulated error function for showing detailed traceback -- Needs improvement local function error_handler(msg) + if sailor.conf.hide_stack_trace then + page:write("
Error 500: Internal Server Error
") + return 500 + end page:write("
"..traceback(msg,2).."
") end -- Error for controller or action not found diff --git a/src/sailor/blank-app/conf/conf.lua b/src/sailor/blank-app/conf/conf.lua index 14f1ef7..91d3982 100755 --- a/src/sailor/blank-app/conf/conf.lua +++ b/src/sailor/blank-app/conf/conf.lua @@ -12,7 +12,8 @@ local conf = { enable_autogen = false, -- default is false, should be true only in development environment friendly_urls = false, max_upload = 1024 * 1024, - environment = "development" -- this will use db configuration named development + environment = "development", -- this will use db configuration named development + hide_stack_trace = false -- false recommended for development, true recommended for production }, db = {