Skip to content

Commit

Permalink
Add the fail_on_warning keyword (#873)
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge authored Aug 29, 2021
1 parent b654fc9 commit 4dd8ef5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
37 changes: 19 additions & 18 deletions src/Franklin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,25 @@ const BIG_INT = typemax(Int)
# but works fine for what we do here and limits the necessity of passing lots
# of arguments to lots of functions.
const FD_ENV = LittleDict(
:FULL_PASS => true,
:CLEAR => false,
:VERB => false,
:FINAL_PASS => false,
:PRERENDER => false,
:NO_FAIL_PRERENDER => true, # skip prerendering if fails on a page
:ON_WRITE => (_, _) -> nothing,
:FORCE_REEVAL => false,
:CUR_PATH => "", # complements fd-rpath
:SOURCE => "", # keeps track of the origin of a HTML string
:OFFSET_LXDEFS => -BIG_INT, # helps keep track of order in lxcoms/envs
:DEBUG_MODE => false,
:SUPPRESS_ERR => false,
:SILENT_MODE => false,
:QUIET_TEST => false,
:SHOW_WARNINGS => true, # franklin-specific warnings
:UTILS_COUNTER => 0, # counter for utils module
:UTILS_HASH => nothing # hash of the utils
:FULL_PASS => true,
:CLEAR => false,
:VERB => false,
:FINAL_PASS => false,
:PRERENDER => false,
:NO_FAIL_PRERENDER => true, # skip prerendering if fails on a page
:ON_WRITE => (_, _) -> nothing,
:FORCE_REEVAL => false,
:CUR_PATH => "", # complements fd-rpath
:SOURCE => "", # keeps track of the origin of a HTML string
:OFFSET_LXDEFS => -BIG_INT, # helps keep track of order in lxcoms/envs
:DEBUG_MODE => false,
:SUPPRESS_ERR => false,
:SILENT_MODE => false,
:QUIET_TEST => false,
:SHOW_WARNINGS => true, # franklin-specific warnings
:FAIL_ON_WARNING => false, # turn warnings into fatal errors
:UTILS_COUNTER => 0, # counter for utils module
:UTILS_HASH => nothing # hash of the utils
)

utils_name() = "Utils_$(FD_ENV[:UTILS_COUNTER]::Int)"
Expand Down
4 changes: 4 additions & 0 deletions src/manager/franklin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Keyword arguments:
variables
* `host="127.0.0.1"`: the host to use for the local server
* `show_warnings=true`: whether to show franklin warnings
* `fail_on_warning=false`: if true, warnings become fatal errors
* `launch=!single`: whether to launch the browser when serving
"""
function serve(; clear::Bool = false,
Expand All @@ -61,6 +62,7 @@ function serve(; clear::Bool = false,
log::Bool = false,
host::String = "127.0.0.1",
show_warnings::Bool = true,
fail_on_warning::Bool = false,
launch::Bool = !single,
)::Union{Nothing,Int}

Expand All @@ -74,6 +76,8 @@ function serve(; clear::Bool = false,
FD_ENV[:SHOW_WARNINGS] = false
end

FD_ENV[:FAIL_ON_WARNING] = fail_on_warning

# in case of optim, there may be a prepath given which should be
# kept
prepath = get(GLOBAL_VARS, "prepath", nothing)
Expand Down
5 changes: 4 additions & 1 deletion src/manager/post_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Does a full pass followed by a pre-rendering and minification step.
* `no_fail_prerender=true`: whether to ignore errors during the pre-rendering
process
* `suppress_errors=true`: whether to suppress errors
* `fail_on_warning=false`: if true, warnings become fatal errors
* `cleanup=true`: whether to empty environment dictionaries
* `on_write(pg, fd_vars)`: callback function after the page is rendered,
passing as arguments the rendered page and the page
Expand All @@ -29,8 +30,10 @@ pages).
"""
function optimize(; prerender::Bool=true, minify::Bool=true, sig::Bool=false,
prepath::String="", no_fail_prerender::Bool=true, on_write::Function=(_,_)->nothing,
suppress_errors::Bool=true, clear::Bool=false, cleanup::Bool=true)::Union{Nothing,Bool}
suppress_errors::Bool=true, clear::Bool=false, cleanup::Bool=true,
fail_on_warning::Bool = false)::Union{Nothing,Bool}
suppress_errors && (FD_ENV[:SUPPRESS_ERR] = true)
FD_ENV[:FAIL_ON_WARNING] = fail_on_warning
#
# Prerendering
#
Expand Down
1 change: 1 addition & 0 deletions src/utils/warnings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ function print_warning(msg)
println(line)
end
printyb("\n")
FD_ENV[:FAIL_ON_WARNING] && throw(ErrorException("`fail_on_warning` is true, so exiting with error"))
return
end

0 comments on commit 4dd8ef5

Please sign in to comment.