Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long types printed in MethodError #50803

Closed
timholy opened this issue Aug 5, 2023 · 6 comments · Fixed by #50809
Closed

Long types printed in MethodError #50803

timholy opened this issue Aug 5, 2023 · 6 comments · Fixed by #50809
Labels
error messages Better, more actionable error messages

Comments

@timholy
Copy link
Sponsor Member

timholy commented Aug 5, 2023

As reported in https://discourse.julialang.org/t/type-parameter-display-in-1-10-for-methoderror/102516

a = view(reinterpret(reshape, UInt8, PermutedDimsArray(rand(5, 7), (2, 1))), 2:3, 2:4, 1:4); # a mildly-complex type
function foo end

julia> foo(a, a, a, a, a, a, a)
ERROR: MethodError: no method matching foo(::SubArray{UInt8, 3, Base.ReinterpretArray{UInt8, 3, Float64, PermutedDimsArray{Float64, 2, (2, 1), (2, 1), Matrix{Float64}}, true}, Tuple{UnitRange{Int64}, UnitRange{Int64}, UnitRange{Int64}}, false}, ::SubArray{UInt8, 3, Base.ReinterpretArray{UInt8, 3, Float64, PermutedDimsArray{Float64, 2, (2, 1), (2, 1), Matrix{Float64}}, true}, Tuple{UnitRange{Int64}, UnitRange{Int64}, UnitRange{Int64}}, false}, ::SubArray{UInt8, 3, Base.ReinterpretArray{UInt8, 3, Float64, PermutedDimsArray{Float64, 2, (2, 1), (2, 1), Matrix{Float64}}, true}, Tuple{UnitRange{Int64}, UnitRange{Int64}, UnitRange{Int64}}, false}, ::SubArray{UInt8, 3, Base.ReinterpretArray{UInt8, 3, Float64, PermutedDimsArray{Float64, 2, (2, 1), (2, 1), Matrix{Float64}}, true}, Tuple{UnitRange{Int64}, UnitRange{Int64}, UnitRange{Int64}}, false}, ::SubArray{UInt8, 3, Base.ReinterpretArray{UInt8, 3, Float64, PermutedDimsArray{Float64, 2, (2, 1), (2, 1), Matrix{Float64}}, true}, Tuple{UnitRange{Int64}, UnitRange{Int64}, UnitRange{Int64}}, false}, ::SubArray{UInt8, 3, Base.ReinterpretArray{UInt8, 3, Float64, PermutedDimsArray{Float64, 2, (2, 1), (2, 1), Matrix{Float64}}, true}, Tuple{UnitRange{Int64}, UnitRange{Int64}, UnitRange{Int64}}, false}, ::SubArray{UInt8, 3, Base.ReinterpretArray{UInt8, 3, Float64, PermutedDimsArray{Float64, 2, (2, 1), (2, 1), Matrix{Float64}}, true}, Tuple{UnitRange{Int64}, UnitRange{Int64}, UnitRange{Int64}}, false})
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1
@gdalle
Copy link
Contributor

gdalle commented Aug 5, 2023

Thanks for the issue and the MWE 🚀

@timholy
Copy link
Sponsor Member Author

timholy commented Aug 5, 2023

One big concern: when printing a stacktrace, we can fall back on

Some type information was truncated. Use `show(err)` to see complete types.

for those cases where full type-information is needed to resolve the error. But when the MethodError happens at toplevel (directly in the REPL call itself), there is no err object to query:

julia> foo(a, a, a, a, a, a, a)
ERROR: MethodError: no method matching foo... # manually truncated
Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

julia> err

julia>

@gdalle
Copy link
Contributor

gdalle commented Aug 5, 2023

Newbie reac here: can we put the error in ans in that case?

@timholy
Copy link
Sponsor Member Author

timholy commented Aug 5, 2023

I think we should be able to put it in err, but I'm not immediately sure why we don't have it. Will do a bit of digging.

@timholy
Copy link
Sponsor Member Author

timholy commented Aug 5, 2023

The answer seems to be

julia/base/client.jl

Lines 105 to 106 in 117ef2e

istrivialerror(stack::ExceptionStack) =
length(stack) == 1 && length(stack[1].backtrace) 1

If I change that to always return false, then we get a useful err object. @BioTurboNick, can you comment on this check? I'm not sure what the consequences will be if we change it.

@BioTurboNick
Copy link
Contributor

The intent there was just to avoid saving a stack trace that was just the top level, partly to avoid overwriting the variable if you make an error trying to access it. So I don't see any harm in deeming all MethodErrors to be not trivial.

@brenhinkeller brenhinkeller added the error messages Better, more actionable error messages label Aug 5, 2023
timholy added a commit that referenced this issue Aug 6, 2023
timholy added a commit that referenced this issue Aug 16, 2023
This applies the same `...` depth-based parametric truncation to
the signature in `MethodError` that we use in printing stacktraces.

Fixes #50803
IanButterworth pushed a commit that referenced this issue Aug 19, 2023
This applies the same `...` depth-based parametric truncation to
the signature in `MethodError` that we use in printing stacktraces.

Fixes #50803

(cherry picked from commit 90b4eed)
nalimilan pushed a commit that referenced this issue Nov 5, 2023
This applies the same `...` depth-based parametric truncation to
the signature in `MethodError` that we use in printing stacktraces.

Fixes #50803

(cherry picked from commit 90b4eed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error messages Better, more actionable error messages
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants