Skip to content

Commit 71b8529

Browse files
authored
Update specs to match OTP definitions (#14121)
1 parent 2567938 commit 71b8529

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

lib/elixir/lib/file.ex

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ defmodule File do
263263
on some platforms, `:enoent` is returned instead
264264
265265
"""
266-
@spec mkdir(Path.t()) :: :ok | {:error, posix}
266+
@spec mkdir(Path.t()) :: :ok | {:error, posix | :badarg}
267267
def mkdir(path) do
268268
:file.make_dir(IO.chardata_to_string(path))
269269
end
@@ -300,7 +300,7 @@ defmodule File do
300300
* `:enotdir` - a component of `path` is not a directory
301301
302302
"""
303-
@spec mkdir_p(Path.t()) :: :ok | {:error, posix}
303+
@spec mkdir_p(Path.t()) :: :ok | {:error, posix | :badarg}
304304
def mkdir_p(path) do
305305
do_mkdir_p(IO.chardata_to_string(path))
306306
end
@@ -366,7 +366,7 @@ defmodule File do
366366
367367
You can use `:file.format_error/1` to get a descriptive string of the error.
368368
"""
369-
@spec read(Path.t()) :: {:ok, binary} | {:error, posix}
369+
@spec read(Path.t()) :: {:ok, binary} | {:error, posix | :badarg | :terminated | :system_limit}
370370
def read(path) do
371371
:file.read_file(IO.chardata_to_string(path))
372372
end
@@ -408,7 +408,7 @@ defmodule File do
408408
Note: Since file times are stored in POSIX time format on most operating systems,
409409
it is faster to retrieve file information with the `time: :posix` option.
410410
"""
411-
@spec stat(Path.t(), stat_options) :: {:ok, File.Stat.t()} | {:error, posix}
411+
@spec stat(Path.t(), stat_options) :: {:ok, File.Stat.t()} | {:error, posix | :badarg}
412412
def stat(path, opts \\ []) do
413413
opts = Keyword.put_new(opts, :time, :universal)
414414

@@ -461,7 +461,7 @@ defmodule File do
461461
Note: Since file times are stored in POSIX time format on most operating systems,
462462
it is faster to retrieve file information with the `time: :posix` option.
463463
"""
464-
@spec lstat(Path.t(), stat_options) :: {:ok, File.Stat.t()} | {:error, posix}
464+
@spec lstat(Path.t(), stat_options) :: {:ok, File.Stat.t()} | {:error, posix | :badarg}
465465
def lstat(path, opts \\ []) do
466466
opts = Keyword.put_new(opts, :time, :universal)
467467

@@ -508,7 +508,7 @@ defmodule File do
508508
509509
"""
510510
@doc since: "1.5.0"
511-
@spec read_link(Path.t()) :: {:ok, binary} | {:error, posix}
511+
@spec read_link(Path.t()) :: {:ok, binary} | {:error, posix | :badarg}
512512
def read_link(path) do
513513
case path |> IO.chardata_to_string() |> :file.read_link() do
514514
{:ok, target} -> {:ok, IO.chardata_to_string(target)}
@@ -536,7 +536,7 @@ defmodule File do
536536
Writes the given `File.Stat` back to the file system at the given
537537
path. Returns `:ok` or `{:error, reason}`.
538538
"""
539-
@spec write_stat(Path.t(), File.Stat.t(), stat_options) :: :ok | {:error, posix}
539+
@spec write_stat(Path.t(), File.Stat.t(), stat_options) :: :ok | {:error, posix | :badarg}
540540
def write_stat(path, stat, opts \\ []) do
541541
opts = Keyword.put_new(opts, :time, :universal)
542542
:file.write_file_info(IO.chardata_to_string(path), File.Stat.to_record(stat), opts)
@@ -585,7 +585,8 @@ defmodule File do
585585
#=> :ok
586586
587587
"""
588-
@spec touch(Path.t(), erlang_time() | posix_time()) :: :ok | {:error, posix}
588+
@spec touch(Path.t(), erlang_time() | posix_time()) ::
589+
:ok | {:error, posix | :badarg | :terminated | :system_limit}
589590
def touch(path, time \\ System.os_time(:second))
590591

591592
def touch(path, time) when is_tuple(time) do
@@ -641,7 +642,7 @@ defmodule File do
641642
`{:error, :enotsup}`.
642643
"""
643644
@doc since: "1.5.0"
644-
@spec ln(Path.t(), Path.t()) :: :ok | {:error, posix}
645+
@spec ln(Path.t(), Path.t()) :: :ok | {:error, posix | :badarg}
645646
def ln(existing, new) do
646647
:file.make_link(IO.chardata_to_string(existing), IO.chardata_to_string(new))
647648
end
@@ -674,7 +675,7 @@ defmodule File do
674675
`{:error, :enotsup}`.
675676
"""
676677
@doc since: "1.5.0"
677-
@spec ln_s(Path.t(), Path.t()) :: :ok | {:error, posix}
678+
@spec ln_s(Path.t(), Path.t()) :: :ok | {:error, posix | :badarg}
678679
def ln_s(existing, new) do
679680
:file.make_symlink(IO.chardata_to_string(existing), IO.chardata_to_string(new))
680681
end
@@ -721,7 +722,7 @@ defmodule File do
721722
`read/1` and `write/3`.
722723
"""
723724
@spec copy(Path.t() | io_device, Path.t() | io_device, pos_integer | :infinity) ::
724-
{:ok, non_neg_integer} | {:error, posix}
725+
{:ok, non_neg_integer} | {:error, posix | :badarg | :terminated}
725726
def copy(source, destination, bytes_count \\ :infinity) do
726727
source = normalize_path_or_io_device(source)
727728
destination = normalize_path_or_io_device(destination)
@@ -771,7 +772,7 @@ defmodule File do
771772
772773
"""
773774
@doc since: "1.1.0"
774-
@spec rename(Path.t(), Path.t()) :: :ok | {:error, posix}
775+
@spec rename(Path.t(), Path.t()) :: :ok | {:error, posix | :badarg}
775776
def rename(source, destination) do
776777
source = IO.chardata_to_string(source)
777778
destination = IO.chardata_to_string(destination)
@@ -826,7 +827,8 @@ defmodule File do
826827
given as third argument, but such behavior is now deprecated.
827828
828829
"""
829-
@spec cp(Path.t(), Path.t(), on_conflict: on_conflict_callback) :: :ok | {:error, posix}
830+
@spec cp(Path.t(), Path.t(), on_conflict: on_conflict_callback) ::
831+
:ok | {:error, posix | :badarg | :terminated}
830832
def cp(source_file, destination_file, options \\ [])
831833

832834
# TODO: Deprecate me on Elixir v1.19
@@ -938,7 +940,7 @@ defmodule File do
938940
on_conflict: on_conflict_callback,
939941
dereference_symlinks: boolean()
940942
) ::
941-
{:ok, [binary]} | {:error, posix, binary}
943+
{:ok, [binary]} | {:error, posix | :badarg | :terminated, binary}
942944

943945
def cp_r(source, destination, options \\ [])
944946

@@ -1140,7 +1142,8 @@ defmodule File do
11401142
11411143
Check `File.open/2` for other available options.
11421144
"""
1143-
@spec write(Path.t(), iodata, [mode]) :: :ok | {:error, posix}
1145+
@spec write(Path.t(), iodata, [mode]) ::
1146+
:ok | {:error, posix | :badarg, :terminated | :system_limit}
11441147
def write(path, content, modes \\ []) do
11451148
modes = normalize_modes(modes, false)
11461149
:file.write_file(IO.chardata_to_string(path), content, modes)
@@ -1189,7 +1192,7 @@ defmodule File do
11891192
#=> {:error, :eperm}
11901193
11911194
"""
1192-
@spec rm(Path.t()) :: :ok | {:error, posix}
1195+
@spec rm(Path.t()) :: :ok | {:error, posix | :badarg}
11931196
def rm(path) do
11941197
path = IO.chardata_to_string(path)
11951198

@@ -1257,7 +1260,7 @@ defmodule File do
12571260
#=> {:error, :enotdir}
12581261
12591262
"""
1260-
@spec rmdir(Path.t()) :: :ok | {:error, posix}
1263+
@spec rmdir(Path.t()) :: :ok | {:error, posix | :badarg}
12611264
def rmdir(path) do
12621265
:file.del_dir(IO.chardata_to_string(path))
12631266
end
@@ -1266,7 +1269,7 @@ defmodule File do
12661269
Same as `rmdir/1`, but raises a `File.Error` exception in case of failure.
12671270
Otherwise `:ok`.
12681271
"""
1269-
@spec rmdir!(Path.t()) :: :ok | {:error, posix}
1272+
@spec rmdir!(Path.t()) :: :ok
12701273
def rmdir!(path) do
12711274
case rmdir(path) do
12721275
:ok ->
@@ -1298,7 +1301,7 @@ defmodule File do
12981301
#=> {:ok, []}
12991302
13001303
"""
1301-
@spec rm_rf(Path.t()) :: {:ok, [binary]} | {:error, posix, binary}
1304+
@spec rm_rf(Path.t()) :: {:ok, [binary]} | {:error, posix | :badarg, binary}
13021305
def rm_rf(path) do
13031306
{major, _} = :os.type()
13041307

@@ -1496,8 +1499,10 @@ defmodule File do
14961499
File.close(file)
14971500
14981501
"""
1499-
@spec open(Path.t(), [mode | :ram]) :: {:ok, io_device | file_descriptor} | {:error, posix}
1500-
@spec open(Path.t(), (io_device | file_descriptor -> res)) :: {:ok, res} | {:error, posix}
1502+
@spec open(Path.t(), [mode | :ram]) ::
1503+
{:ok, io_device | file_descriptor} | {:error, posix | :badarg | :system_limit}
1504+
@spec open(Path.t(), (io_device | file_descriptor -> res)) ::
1505+
{:ok, res} | {:error, posix | :badarg | :system_limit}
15011506
when res: var
15021507
def open(path, modes_or_function \\ [])
15031508

@@ -1533,7 +1538,7 @@ defmodule File do
15331538
See `open/2` for the list of available `modes`.
15341539
"""
15351540
@spec open(Path.t(), [mode | :ram], (io_device | file_descriptor -> res)) ::
1536-
{:ok, res} | {:error, posix}
1541+
{:ok, res} | {:error, posix | :badarg | :system_limit}
15371542
when res: var
15381543
def open(path, modes, function) when is_list(modes) and is_function(function, 1) do
15391544
case open(path, modes) do
@@ -1594,7 +1599,7 @@ defmodule File do
15941599
current directory. For this reason, returns `{:ok, cwd}` in case
15951600
of success, `{:error, reason}` otherwise.
15961601
"""
1597-
@spec cwd() :: {:ok, binary} | {:error, posix}
1602+
@spec cwd() :: {:ok, binary} | {:error, posix, :badarg}
15981603
def cwd() do
15991604
case :file.get_cwd() do
16001605
{:ok, base} -> {:ok, IO.chardata_to_string(fix_drive_letter(base))}
@@ -1636,7 +1641,7 @@ defmodule File do
16361641
16371642
Returns `:ok` if successful, `{:error, reason}` otherwise.
16381643
"""
1639-
@spec cd(Path.t()) :: :ok | {:error, posix}
1644+
@spec cd(Path.t()) :: :ok | {:error, posix | :badarg | :no_translation}
16401645
def cd(path) do
16411646
:file.set_cwd(IO.chardata_to_string(path))
16421647
end
@@ -1695,7 +1700,7 @@ defmodule File do
16951700
Returns `{:ok, files}` in case of success,
16961701
`{:error, reason}` otherwise.
16971702
"""
1698-
@spec ls(Path.t()) :: {:ok, [binary]} | {:error, posix}
1703+
@spec ls(Path.t()) :: {:ok, [binary]} | {:error, posix | :badarg, {:no_translation, binary}}
16991704
def ls(path \\ ".") do
17001705
case :file.list_dir(IO.chardata_to_string(path)) do
17011706
{:ok, file_list} -> {:ok, Enum.map(file_list, &IO.chardata_to_string/1)}
@@ -1841,7 +1846,7 @@ defmodule File do
18411846
and both read and execute permission to group
18421847
and others.
18431848
"""
1844-
@spec chmod(Path.t(), non_neg_integer) :: :ok | {:error, posix}
1849+
@spec chmod(Path.t(), non_neg_integer) :: :ok | {:error, posix | :badarg}
18451850
def chmod(path, mode) do
18461851
:file.change_mode(IO.chardata_to_string(path), mode)
18471852
end
@@ -1869,7 +1874,7 @@ defmodule File do
18691874
for a given `file`. Returns `:ok` on success, or
18701875
`{:error, reason}` on failure.
18711876
"""
1872-
@spec chgrp(Path.t(), non_neg_integer) :: :ok | {:error, posix}
1877+
@spec chgrp(Path.t(), non_neg_integer) :: :ok | {:error, posix | :badarg}
18731878
def chgrp(path, gid) do
18741879
:file.change_group(IO.chardata_to_string(path), gid)
18751880
end
@@ -1897,7 +1902,7 @@ defmodule File do
18971902
for a given `file`. Returns `:ok` on success,
18981903
or `{:error, reason}` on failure.
18991904
"""
1900-
@spec chown(Path.t(), non_neg_integer) :: :ok | {:error, posix}
1905+
@spec chown(Path.t(), non_neg_integer) :: :ok | {:error, posix | :badarg}
19011906
def chown(path, uid) do
19021907
:file.change_owner(IO.chardata_to_string(path), uid)
19031908
end

0 commit comments

Comments
 (0)