diff --git a/doc/src/chunk_options.md b/doc/src/chunk_options.md index 69dfd0d0..ca124a03 100644 --- a/doc/src/chunk_options.md +++ b/doc/src/chunk_options.md @@ -33,6 +33,7 @@ we've mostly followed [RMarkdown's namings](http://yihui.name/knitr/options), bu ### Evaluation - `eval = true`: Evaluate the code chunk. If `false` the chunk won’t be executed. +- `error = true`: If `true` [`weave`](@ref) won't stop on errors and rather they will be included in output document. If `false`, [`weave`](@ref) will halt on any of un-caught errors. - `cache = false`: Cache results, depending on `cache` parameter on [`weave`](@ref) function. - `tangle = true`: Set tangle to `false` to exclude chunk from tangled code. diff --git a/src/Weave.jl b/src/Weave.jl index 4c655327..3ec26730 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -96,7 +96,6 @@ Weave an input document to output file. * `:all` caches everything * `:user` caches based on chunk options * `:refresh` runs all code chunks and save new cache -- `throw_errors::Bool = false`: If `false` errors are included in output document and the whole document is executed. If `true` errors are thrown when they occur - `template::Union{Nothing,AbstractString,Mustache.MustacheTokens} = nothing`: Template (file path) or `Mustache.MustacheTokens`s for `md2html` or `md2tex` formats - `css::Union{Nothing,AbstractString} = nothing`: Path of a CSS file used for md2html format - `highlight_theme::Union{Nothing,Type{<:Highlights.AbstractTheme}} = nothing`: Theme used for syntax highlighting (defaults to `Highlights.Themes.DefaultTheme`) @@ -118,7 +117,6 @@ function weave( fig_ext::Union{Nothing,AbstractString} = nothing, cache_path::AbstractString = "cache", cache::Symbol = :off, - throw_errors::Bool = false, template::Union{Nothing,AbstractString,Mustache.MustacheTokens} = nothing, css::Union{Nothing,AbstractString} = nothing, # TODO: rename to `stylesheet` highlight_theme::Union{Nothing,Type{<:Highlights.AbstractTheme}} = nothing, @@ -158,7 +156,6 @@ function weave( fig_ext = get(weave_options, "fig_ext", fig_ext) cache_path = get(weave_options, "cache_path", cache_path) cache = Symbol(get(weave_options, "cache", cache)) - throw_errors = get(weave_options, "throw_errors", throw_errors) end doc = run_doc( @@ -171,7 +168,6 @@ function weave( fig_ext = fig_ext, cache_path = cache_path, cache = cache, - throw_errors = throw_errors, ) # render document diff --git a/src/config.jl b/src/config.jl index b2aa2973..50201d35 100644 --- a/src/config.jl +++ b/src/config.jl @@ -5,6 +5,7 @@ const _DEFAULT_PARAMS = Dict{Symbol,Any}( :hold => false, :fig => true, :eval => true, + :error => true, :tangle => true, :cache => false, :fig_cap => nothing, diff --git a/src/display_methods.jl b/src/display_methods.jl index b3a509d9..779cb247 100644 --- a/src/display_methods.jl +++ b/src/display_methods.jl @@ -12,24 +12,10 @@ mutable struct Report <: AbstractDisplay mimetypes::Vector{String} first_plot::Bool header_script::String - throw_errors::Bool end -function Report(cwd, basename, format, mimetypes, throw_errors) - Report( - cwd, - basename, - format, - "", - 1, - String[], - nothing, - mimetypes, - true, - "", - throw_errors, - ) -end +Report(cwd, basename, format, mimetypes) = + Report(cwd, basename, format, "", 1, String[], nothing, mimetypes, true, "") # Default mimetypes in order, can be overridden for some inside `run method` formats const default_mime_types = ["image/svg+xml", "image/png", "text/html", "text/plain"] diff --git a/src/run.jl b/src/run.jl index ca4b57dc..85deda67 100644 --- a/src/run.jl +++ b/src/run.jl @@ -13,7 +13,6 @@ function run_doc( fig_ext::Union{Nothing,AbstractString} = nothing, cache_path::AbstractString = "cache", cache::Symbol = :off, - throw_errors::Bool = false, ) # cache :all, :user, :off, :refresh @@ -43,7 +42,7 @@ function run_doc( mimetypes = doc.format.mimetypes - report = Report(cwd, doc.basename, doc.format, mimetypes, throw_errors) + report = Report(cwd, doc.basename, doc.format, mimetypes) cd_back = let d = pwd(); () -> cd(d); end cd(cwd) pushdisplay(report) @@ -207,7 +206,7 @@ function run_code(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module) doc.path, chunk.options[:term], i == n, - report.throw_errors, + chunk.options[:error], ) figures = report.figures # Captured figures result = ChunkOutput(s, out, report.rich_output, figures) @@ -230,7 +229,7 @@ function parse_input(s) return res end -function capture_output(mod, s, path, term, lastline, throw_errors = false) +function capture_output(mod, s, path, term, lastline, error) local out = nothing local obj = nothing @@ -244,7 +243,7 @@ function capture_output(mod, s, path, term, lastline, throw_errors = false) !isnothing(obj) && (term || lastline) && display(obj) catch _err err = unwrap_load_err(_err) - throw_errors && throw(err) + error || throw(err) display(err) @warn "ERROR: $(typeof(err)) occurred, including output in Weaved document" finally diff --git a/test/test_error_rendering.jl b/test/test_error_rendering.jl index 4c4c27d5..d3d9c964 100644 --- a/test/test_error_rendering.jl +++ b/test/test_error_rendering.jl @@ -27,7 +27,7 @@ $err_stmt1 $err_stmt2 ``` -```julia; term=true +```julia; term = true $err_stmt3 ``` """ @@ -47,6 +47,17 @@ let doc = mock_run(str; doctype = "github") @test occursin(err_str3_2, get_output(3)) end -@test_throws ArgumentError mock_run(str; doctype = "github", throw_errors = true) +# TODO: move this into chunk option tests +str = """ +```julia; error = true +using # won't be thrown +``` + +```julia; error = false +using NonExisting # will be thrown +``` +""" + +@test_throws ArgumentError mock_run(str; doctype = "github") # TODO: test error rendering in `rich_output`