Skip to content

Commit

Permalink
better error message for size (#4844)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
lmiq authored Nov 15, 2023
1 parent 92f36ab commit 42244b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/plot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/test_output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 42244b6

Please sign in to comment.