From 4e7fda212d3583be5c3550cca6edadcc037f05fb Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Sat, 9 May 2020 02:48:56 +0900 Subject: [PATCH] ensure Weave display pops out even if an internal err occurs --- src/run.jl | 61 ++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/src/run.jl b/src/run.jl index fc2917d..d68476d 100644 --- a/src/run.jl +++ b/src/run.jl @@ -87,45 +87,42 @@ function Base.run( report = Report(doc.cwd, doc.basename, doc.format.formatdict, mimetypes, throw_errors) pushdisplay(report) - if cache != :off && cache != :refresh - cached = read_cache(doc, cache_path) - cached == nothing && @info("No cached results found, running code") - else - cached = nothing - end - - executed = Any[] - n = length(doc.chunks) - - for i = 1:n - chunk = doc.chunks[i] - - if isa(chunk, CodeChunk) - options = merge(doc.chunk_defaults, chunk.options) - merge!(chunk.options, options) - end - - restore = (cache == :user && typeof(chunk) == CodeChunk && chunk.options[:cache]) - - if cached != nothing && (cache == :all || restore) - result_chunks = restore_chunk(chunk, cached) + try + if cache !== :off && cache !== :refresh + cached = read_cache(doc, cache_path) + cached === nothing && @info "No cached results found, running code" else - result_chunks = run_chunk(chunk, doc, report, mod) + cached = nothing end - executed = [executed; result_chunks] - end + executed = [] + for chunk in doc.chunks + if isa(chunk, CodeChunk) + options = merge(doc.chunk_defaults, chunk.options) + merge!(chunk.options, options) + end - doc.header_script = report.header_script + restore = (cache === :user && typeof(chunk) == CodeChunk && chunk.options[:cache]) - popdisplay(report) + result_chunks = if cached != nothing && (cache === :all || restore) + restore_chunk(chunk, cached) + else + run_chunk(chunk, doc, report, mod) + end - # Clear variables from used sandbox - mod == :sandbox && clear_sandbox(SandBox) - doc.chunks = executed + executed = [executed; result_chunks] + end - if cache != :off - write_cache(doc, cache_path) + doc.header_script = report.header_script + # Clear variables from used sandbox + mod === :sandbox && clear_sandbox(SandBox) + doc.chunks = executed + + cache !== :off && write_cache(doc, cache_path) + catch err + rethrow(err) + finally + popdisplay(report) # ensure display pops out even if internal error occurs end return doc