Skip to content

Commit

Permalink
feat(core): Allow hiding stacktrace
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Etiene committed Dec 2, 2015
1 parent b1e4bca commit b75c918
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/sailor.lua
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
-- License: MIT
Expand All @@ -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.
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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("<pre>Error 500: Internal Server Error</pre>")
return 500
end
page:write("<pre>"..traceback(msg,2).."</pre>")
end
-- Error for controller or action not found
Expand Down
3 changes: 2 additions & 1 deletion src/sailor/blank-app/conf/conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit b75c918

Please sign in to comment.