Skip to content

Commit 28e63dc

Browse files
Add register_error_hint for UndefVarError (#39850)
* add show_error_hints for UndefVarError Hi, I just include the show_error_hints part from #39089 Further relevant discussion in [discourse](https://discourse.julialang.org/t/help-with-register-error-hint/56140/4) * Update errorshow.jl * Update Base.jl Co-authored-by: Simeon Schaub <simeondavidschaub99@gmail.com>
1 parent 9c50643 commit 28e63dc

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

base/Base.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ include("meta.jl")
337337
include("stacktraces.jl")
338338
using .StackTraces
339339

340+
# experimental API's
341+
include("experimental.jl")
342+
340343
# utilities
341344
include("deepcopy.jl")
342345
include("download.jl")
@@ -360,9 +363,6 @@ include("util.jl")
360363

361364
include("asyncmap.jl")
362365

363-
# experimental API's
364-
include("experimental.jl")
365-
366366
# deprecated functions
367367
include("deprecated.jl")
368368

base/errorshow.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,18 @@ showerror(io::IO, ex::UndefKeywordError) =
159159
print(io, "UndefKeywordError: keyword argument $(ex.var) not assigned")
160160

161161
function showerror(io::IO, ex::UndefVarError)
162+
print(io, "UndefVarError: $(ex.var) not defined")
163+
Experimental.show_error_hints(io, ex)
164+
end
165+
166+
Experimental.register_error_hint(UndefVarError) do io::IO, ex::UndefVarError
162167
if ex.var in [:UTF16String, :UTF32String, :WString, :utf16, :utf32, :wstring, :RepString]
163-
return showerror(io, ErrorException("""
164-
`$(ex.var)` has been moved to the package LegacyStrings.jl:
165-
Run Pkg.add("LegacyStrings") to install LegacyStrings on Julia v0.5-;
166-
Then do `using LegacyStrings` to get `$(ex.var)`.
167-
"""))
168+
println(io)
169+
print(io, """
170+
`$(ex.var)` has been moved to the package LegacyStrings.jl:
171+
Run Pkg.add("LegacyStrings") to install LegacyStrings on Julia v0.5-;
172+
Then do `using LegacyStrings` to get `$(ex.var)`.""")
168173
end
169-
print(io, "UndefVarError: $(ex.var) not defined")
170174
end
171175

172176
function showerror(io::IO, ex::InexactError)

test/errorshow.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,5 @@ if Sys.isapple() || (Sys.islinux() && Sys.ARCH === :x86_64)
797797
end
798798
end
799799
end # Sys.isapple()
800+
801+
@test contains(sprint(Base.showerror, UndefVarError(:UTF16String)), "LegacyStrings")

0 commit comments

Comments
 (0)