Browse Source

Use showerror for showing captured errors (#261)

pull/266/head
Tamas K. Papp 1 year ago committed by GitHub
parent
commit
c4ac614a61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 5
      CHANGELOG.md
  2. 11
      src/Literate.jl
  3. 7
      test/runtests.jl

5
CHANGELOG.md

@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fixed
- Errors from code evaluation (with `continue_on_error = true`) are now properly displayed
with `showerror`. ([#261])
## [v2.20.0] - 2024-10-16
### Added
- A new keyword argument configuration `continue_on_error::Bool = false` has been added

11
src/Literate.jl

@ -936,7 +936,15 @@ function execute_block(sb::Module, block::String; inputfile::String, fake_source @@ -936,7 +936,15 @@ 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
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
all_output = c.output * "\n\nERROR: " * sprint(showerror, err)
return nothing, all_output, disp.data
else
error("""
$(sprint(showerror, c.value))
when executing the following code block from inputfile `$(Base.contractuser(inputfile))`
@ -946,6 +954,7 @@ function execute_block(sb::Module, block::String; inputfile::String, fake_source @@ -946,6 +954,7 @@ function execute_block(sb::Module, block::String; inputfile::String, fake_source
```
""")
end
end
return c.value, c.output, disp.data
end

7
test/runtests.jl

@ -1462,8 +1462,8 @@ end end @@ -1462,8 +1462,8 @@ end end
@testset "continue_on_error=true" begin
input_with_error =
"""
# The following will error
# The following will print something, then error
print("I always wanted to calculate")
sqrt(-1.0)
"""
mktempdir(@__DIR__) do sandbox
@ -1471,7 +1471,8 @@ end end @@ -1471,7 +1471,8 @@ 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("I always wanted to calculate", output_md)
@test occursin("ERROR: DomainError with -1.0", output_md)
end
end

Loading…
Cancel
Save