Skip to content

Commit

Permalink
Approximate error display of REPL.
Browse files Browse the repository at this point in the history
Follow up to fredrikekre#257, uses showerror and the output channel.
  • Loading branch information
tpapp committed Oct 16, 2024
1 parent ecae718 commit 3a3bb74
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions src/Literate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -936,15 +936,24 @@ function execute_block(sb::Module, block::String; inputfile::String, fake_source
end
end
popdisplay(disp) # IOCapture.capture has a try-catch so should always end up here
if c.error && !continue_on_error
error("""
$(sprint(showerror, c.value))
when executing the following code block from inputfile `$(Base.contractuser(inputfile))`
```julia
$block
```
""")
if c.error
if continue_on_error
err = c.value
if err isa LoadError # include_string may wrap error in LoadError
err = err.error
end
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
return c.value, c.output, disp.data
end
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1471,7 +1471,7 @@ end end
write(inputfile, input_with_error)
Literate.markdown(inputfile, sandbox; continue_on_error = true, execute = true)
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

Expand Down

0 comments on commit 3a3bb74

Please sign in to comment.