Closed as duplicate of#13881
Closed as duplicate of#13881
Description
Elixir and Erlang/OTP versions
Calling IO.inspect with the width option set to an invalid value like :infinite
(note the typo, not :infinity
) in iex raises a confusing exception.
Operating system
macOS Sequoia 15.4.1
Current behavior
iex(1)> IO.inspect(nil, width: :infinite)
** (FunctionClauseError) no function clause matching in Inspect.Algebra.format/2
The following arguments were given to Inspect.Algebra.format/2:
# 1
{:doc_group, "nil", :self}
# 2
:infinite
Attempted function clauses (showing 1 out of 1):
def format(doc, width) when (is_binary(doc) or doc === :doc_nil or doc === :doc_line or is_tuple(doc) and (elem(doc, 0) === :doc_break or elem(doc, 0) === :doc_collapse or elem(doc, 0) === :doc_color or elem(doc, 0) === :doc_cons or elem(doc, 0) === :doc_fits or elem(doc, 0) === :doc_force or elem(doc, 0) === :doc_group or elem(doc, 0) === :doc_nest or elem(doc, 0) === :doc_string or elem(doc, 0) === :doc_limit)) and (width == :infinity or is_integer(width) and width >= 0)
(elixir 1.18.3) lib/inspect/algebra.ex:1010: Inspect.Algebra.format/2
(elixir 1.18.3) lib/io.ex:490: IO.inspect/3
iex:1: (file)
### Expected behavior
Expected behavior is that it prints an error like `Invalid width :infinite, valid values are integers or :infinity`.
Actually, even a match error would be fine, if it was easier to read. The important part of this one (`width == :infinity or is_integer(width)`) is buried too deeply.
Metadata
Metadata
Assignees
Labels
No labels