summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Leopardi <an.leopardi@gmail.com>2022-01-09 12:24:33 +0200
committerAndrea Leopardi <an.leopardi@gmail.com>2022-01-09 12:24:33 +0200
commit53ee9d295837d0a24305b1cc41174322ab3bc13e (patch)
tree8354ae3ef66be0c8fe18cfe27cab554310b25bc6
parentd07b58b3e3a593cfeacf1ebf2c6f196a2f686030 (diff)
downloadelixir-andrea/path-join-argument-error.tar.gz
Raise ArgumentError with empty list in Path.join/1andrea/path-join-argument-error
We were raising a FunctionClauseError which can be pretty obscure in some cases. I think the FunctionClauseError makes perfect sense if you pass the wrong argument type (not a list in this case), but an empty list feels like a good candidate for a more explicit error.
-rw-r--r--lib/elixir/lib/path.ex4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/elixir/lib/path.ex b/lib/elixir/lib/path.ex
index 52bad2d2b..b9e5bdca6 100644
--- a/lib/elixir/lib/path.ex
+++ b/lib/elixir/lib/path.ex
@@ -504,10 +504,14 @@ defmodule Path do
iex> Path.join(["/", "foo", "bar/"])
"/foo/bar"
+ iex> Path.join([])
+ ** (ArgumentError) list of paths must have at least one element
+
"""
@spec join(nonempty_list(t)) :: binary
def join([name1, name2 | rest]), do: join([join(name1, name2) | rest])
def join([name]), do: IO.chardata_to_string(name)
+ def join([]), do: raise(ArgumentError, "list of paths must have at least one element")
@doc """
Joins two paths.