Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ end

function showerror(io::IO, exc::FieldError)
@nospecialize
print(io, "FieldError: type $(exc.type |> nameof) has no field `$(exc.field)`")
print(io, "FieldError: type $(exc.type.name.wrapper) has no field `$(exc.field)`")
Base.Experimental.show_error_hints(io, exc)
end

Expand Down Expand Up @@ -1127,7 +1127,7 @@ Experimental.register_error_hint(fielderror_dict_hint_handler, FieldError)
function fielderror_listfields_hint_handler(io, exc)
fields = fieldnames(exc.type)
if isempty(fields)
print(io, "; $(nameof(exc.type)) has no fields at all.")
print(io, "; $(exc.type.name.wrapper) has no fields at all.")
else
print(io, ", available fields: $(join(map(k -> "`$k`", fields), ", "))")
end
Expand Down
21 changes: 20 additions & 1 deletion test/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ end

# Check error message first
errorMsg = sprint(Base.showerror, ex)
@test occursin("FieldError: type FieldFoo has no field `c`", errorMsg)
@test occursin("FieldError: type", errorMsg)
@test occursin("FieldFoo has no field `c`", errorMsg)
@test occursin("available fields: `a`, `b`", errorMsg)
@test occursin("Available properties: `x`, `y`", errorMsg)

Expand All @@ -882,6 +883,24 @@ end
@test occursin(hintExpected, errorMsg)
end

module FieldErrorTest
struct Point end
p = Point()
end

@testset "FieldError with changing fields" begin
# https://discourse.julialang.org/t/better-error-message-for-modified-structs-in-julia-1-12/129265
err_str1 = @except_str FieldErrorTest.p.x FieldError
@test occursin("FieldErrorTest.Point", err_str1)
@eval FieldErrorTest struct Point{T}
x::T
y::T
end
err_str2 = @except_str FieldErrorTest.p.x FieldError
@test occursin("@world", err_str2)
@test occursin("FieldErrorTest.Point", err_str2)
end

# UndefVar error hints
module A53000
export f
Expand Down
Loading