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

better error message for size #4844

Merged
merged 10 commits into from
Nov 15, 2023
Merged

Conversation

lmiq
Copy link
Contributor

@lmiq lmiq commented Nov 14, 2023

Description

If the size parameter of the plot is provided in the wrong format, provide a sensible error message. Current the behavior does not provide an indication on where the input problem is:

julia> using Plots

julia> plot(size=())
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: BoundsError: attempt to access Tuple{} at index [1]
Stacktrace:
  [1] indexed_iterate
    @ Base ./tuple.jl:92 [inlined]
  [2] indexed_iterate(t::Tuple{}, i::Int64)
    @ Base ./tuple.jl:92
  [3] prepare_output(plt::Plots.Plot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/sxUvK/src/plot.jl:234
  [4] display(::Plots.PlotsDisplay, plt::Plots.Plot{Plots.GRBackend})
    @ Plots ~/.julia/packages/Plots/sxUvK/src/output.jl:168
  [5] display(x::Any)
    @ Base.Multimedia ./multimedia.jl:340
  [6] #invokelatest#2
    @ Base ./essentials.jl:887 [inlined]
  [7] invokelatest
    @ Base ./essentials.jl:884 [inlined]
  [8] print_response(errio::IO, response::Any, show_value::Bool, have_color::Bool, specialdisplay::Union{…})
    @ REPL ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:315
  [9] (::REPL.var"#57#58"{REPL.LineEditREPL, Pair{Any, Bool}, Bool, Bool})(io::Any)
    @ REPL ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:284
 [10] with_repl_linfo(f::Any, repl::REPL.LineEditREPL)
    @ REPL ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:569
 [11] print_response(repl::REPL.AbstractREPL, response::Any, show_value::Bool, have_color::Bool)
    @ REPL ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:282
 [12] (::REPL.var"#do_respond#80"{})(s::REPL.LineEdit.MIState, buf::Any, ok::Bool)
    @ REPL ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:911
 [13] #invokelatest#2
    @ Base ./essentials.jl:887 [inlined]
 [14] invokelatest
    @ Base ./essentials.jl:884 [inlined]
 [15] run_interface(terminal::REPL.Terminals.TextTerminal, m::REPL.LineEdit.ModalInterface, s::REPL.LineEdit.MIState)
    @ REPL.LineEdit ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/LineEdit.jl:2656
 [16] run_frontend(repl::REPL.LineEditREPL, backend::REPL.REPLBackendRef)
    @ REPL ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:1312
 [17] (::REPL.var"#62#68"{REPL.LineEditREPL, REPL.REPLBackendRef})()
    @ REPL ~/.julia/juliaup/julia-1.10.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.10/REPL/src/REPL.jl:386
Some type information was truncated. Use `show(err)` to see complete types.

which when in the middle of a larger script can be really hard to track, as the error only manifest when the figure is being shown or saved.

With this change, we get:

julia> plot(size=())
Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: ArgumentError: plot size must have length = 2, got size = ()
Stacktrace:

and

julia> plt = plot(size = ());

julia> savefig(plt, "teste.png")
ERROR: ArgumentError: plot size must have length = 2, got size = ()

Which are much more clear.

Description

Attribution

Things to consider

  • Does it work on log scales?
  • Does it work in layouts?
  • Does it work in recipes?
  • Does it work with multiple series in one call?
  • [ X ] PR includes or updates tests?
  • PR includes or updates documentation?

Attribution

@lmiq lmiq marked this pull request as draft November 14, 2023 14:22
@lmiq
Copy link
Contributor Author

lmiq commented Nov 14, 2023

Te tests that are failing are not related to this PR.

@lmiq lmiq marked this pull request as ready for review November 14, 2023 16:12
@BeastyBlacksmith BeastyBlacksmith merged commit 42244b6 into JuliaPlots:master Nov 15, 2023
7 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants