Browse Source

Approximate error display of REPL.

Follow up to #257, uses showerror and the output channel.
pull/261/head
Tamás K. Papp 1 year ago
parent
commit
3a3bb74287
  1. 27
      src/Literate.jl
  2. 2
      test/runtests.jl

27
src/Literate.jl

@ -936,15 +936,24 @@ function execute_block(sb::Module, block::String; inputfile::String, fake_source
end end
end end
popdisplay(disp) # IOCapture.capture has a try-catch so should always end up here popdisplay(disp) # IOCapture.capture has a try-catch so should always end up here
if c.error && !continue_on_error if c.error
error(""" if continue_on_error
$(sprint(showerror, c.value)) err = c.value
when executing the following code block from inputfile `$(Base.contractuser(inputfile))` if err isa LoadError # include_string may wrap error in LoadError
err = err.error
```julia end
$block error_output = "ERROR: " * sprint(showerror, err)
``` return nothing, error_output, disp.data
""") else
error("""
$(sprint(showerror, c.value))
when executing the following code block from inputfile `$(Base.contractuser(inputfile))`
```julia
$block
```
""")
end
end end
return c.value, c.output, disp.data return c.value, c.output, disp.data
end end

2
test/runtests.jl

@ -1471,7 +1471,7 @@ end end
write(inputfile, input_with_error) write(inputfile, input_with_error)
Literate.markdown(inputfile, sandbox; continue_on_error = true, execute = true) Literate.markdown(inputfile, sandbox; continue_on_error = true, execute = true)
output_md = read(joinpath(sandbox, "input.md"), String) output_md = read(joinpath(sandbox, "input.md"), String)
@test occursin("DomainError(-1.0", output_md) @test occursin("ERROR: DomainError with -1.0", output_md)
end end
end end

Loading…
Cancel
Save