Skip to content

Commit 7dea3bf

Browse files
fredrikekreKristofferC
authored andcommitted
Handle :error and :invalid expressions gracefully in REPL helpmode, (#30754)
fixes #22013, fixes #24871, fixes #26933, fixes #29282, fixes #29361, fixes #30348 and fixes #30506. (cherry picked from commit b8c0ec8)
1 parent e3ec0d1 commit 7dea3bf

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

stdlib/REPL/src/docview.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ helpmode(line::AbstractString) = helpmode(stdout, line)
2121

2222
function _helpmode(io::IO, line::AbstractString)
2323
line = strip(line)
24+
x = Meta.parse(line, raise = false, depwarn = false)
2425
expr =
25-
if haskey(keywords, Symbol(line))
26+
if haskey(keywords, Symbol(line)) || isexpr(x, :error) || isexpr(x, :invalid)
2627
# Docs for keywords must be treated separately since trying to parse a single
2728
# keyword such as `function` would throw a parse error due to the missing `end`.
2829
Symbol(line)
2930
else
30-
x = Meta.parse(line, raise = false, depwarn = false)
3131
# Retrieving docs for macros requires us to make a distinction between the text
3232
# `@macroname` and `@macroname()`. These both parse the same, but are used by
3333
# the docsystem to return different results. The first returns all documentation

stdlib/REPL/test/repl.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,12 @@ for (line, expr) in Pair[
972972
@test Base.eval(REPL._helpmode(buf, line)) isa Union{Markdown.MD,Nothing}
973973
end
974974

975+
# PR 30754, Issues #22013, #24871, #26933, #29282, #29361, #30348
976+
for line in ["", "abstract", "type", "|=", ".="]
977+
@test occursin("No documentation found.",
978+
sprint(show, Base.eval(REPL._helpmode(IOBuffer(), line))::Union{Markdown.MD,Nothing}))
979+
end
980+
975981
# PR #27562
976982
fake_repl() do stdin_write, stdout_read, repl
977983
repltask = @async begin

0 commit comments

Comments
 (0)