From 42244b6aea99327acb07055d57bff2da41104555 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leandro=20Mart=C3=ADnez?= <31046348+lmiq@users.noreply.github.com> Date: Wed, 15 Nov 2023 09:31:30 -0300 Subject: [PATCH] better error message for size (#4844) * better error message for size * Update test_output.jl * fixed size error test * formatted test * remove trailing line * change message * update error message * update error message * fixed test * formatted code --- src/plot.jl | 7 ++++++- test/test_output.jl | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/plot.jl b/src/plot.jl index 30f982421..f16587489 100644 --- a/src/plot.jl +++ b/src/plot.jl @@ -231,7 +231,12 @@ end function prepare_output(plt::Plot) _before_layout_calcs(plt) - w, h = plt.attr[:size] + _wh = plt.attr[:size] + if length(_wh) != 2 + throw(ArgumentError("plot size must have length = 2, got size = $_wh")) + end + w, h = _wh + plt.layout.bbox = BoundingBox(0mm, 0mm, w * px, h * px) # One pass down and back up the tree to compute the minimum padding diff --git a/test/test_output.jl b/test/test_output.jl index 8a63849d8..12f3270a3 100644 --- a/test/test_output.jl +++ b/test/test_output.jl @@ -108,3 +108,12 @@ end Plots._show(io, MIME("text/html"), pl) end end + +@testset "size error handling" begin + plt = plot(size = ()) + @test_throws ArgumentError savefig(plt, tempname()) + plt = plot(size = (1)) + @test_throws ArgumentError savefig(plt, tempname()) + plt = plot(size = (1, 2, 3)) + @test_throws ArgumentError savefig(plt, tempname()) +end