From cfb719cbb0f39e1227d33b639cf7aa2ea823089f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Tue, 31 Aug 2021 22:19:52 +0200 Subject: [PATCH] Fix dialyzer warnings --- lib/livebook/config.ex | 1 + lib/livebook/evaluator/io_proxy.ex | 1 - lib/livebook/file_system/file.ex | 2 +- lib/livebook/file_system/local.ex | 2 +- lib/livebook/runtime/erl_dist/logger_gl_backend.ex | 10 ---------- lib/livebook/session/data.ex | 3 ++- lib/livebook/users/user.ex | 3 ++- test/support/noop_runtime.ex | 2 +- 8 files changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/livebook/config.ex b/lib/livebook/config.ex index f379542ca..59bd05b43 100644 --- a/lib/livebook/config.ex +++ b/lib/livebook/config.ex @@ -310,6 +310,7 @@ defmodule Livebook.Config do @doc """ Aborts booting due to a configuration error. """ + @spec abort!(String.t()) :: no_return() def abort!(message) do IO.puts("\nERROR!!! [Livebook] " <> message) System.halt(1) diff --git a/lib/livebook/evaluator/io_proxy.ex b/lib/livebook/evaluator/io_proxy.ex index ecb398169..5e290db7b 100644 --- a/lib/livebook/evaluator/io_proxy.ex +++ b/lib/livebook/evaluator/io_proxy.ex @@ -357,7 +357,6 @@ defmodule Livebook.Evaluator.IOProxy do end end - defp binary_to_list(data, _) when is_list(data), do: data defp binary_to_list(data, :unicode) when is_binary(data), do: String.to_charlist(data) defp binary_to_list(data, :latin1) when is_binary(data), do: :erlang.binary_to_list(data) diff --git a/lib/livebook/file_system/file.ex b/lib/livebook/file_system/file.ex index 4872e5493..1704c9c4f 100644 --- a/lib/livebook/file_system/file.ex +++ b/lib/livebook/file_system/file.ex @@ -160,7 +160,7 @@ defmodule Livebook.FileSystem.File do @doc """ Creates the given directory unless it already exists. """ - @spec create_dir(t()) :: {:ok, FileSystem.access()} | {:error, FileSystem.error()} + @spec create_dir(t()) :: :ok | {:error, FileSystem.error()} def create_dir(file) do FileSystem.create_dir(file.file_system, file.path) end diff --git a/lib/livebook/file_system/local.ex b/lib/livebook/file_system/local.ex index 2eb21fc0f..a288ddd54 100644 --- a/lib/livebook/file_system/local.ex +++ b/lib/livebook/file_system/local.ex @@ -110,7 +110,7 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.Local do def remove(_file_system, path) do case File.rm_rf(path) do {:ok, _paths} -> :ok - {:error, error} -> FileSystem.Utils.posix_error(error) + {:error, error, _paths} -> FileSystem.Utils.posix_error(error) end end diff --git a/lib/livebook/runtime/erl_dist/logger_gl_backend.ex b/lib/livebook/runtime/erl_dist/logger_gl_backend.ex index d0812f823..10199e2b3 100644 --- a/lib/livebook/runtime/erl_dist/logger_gl_backend.ex +++ b/lib/livebook/runtime/erl_dist/logger_gl_backend.ex @@ -105,16 +105,6 @@ defmodule Livebook.Runtime.ErlDist.LoggerGLBackend do info[:dictionary][:"$initial_call"] == {Livebook.Evaluator.IOProxy, :init, 1} end - defp async_io(name, output) when is_atom(name) do - case Process.whereis(name) do - device when is_pid(device) -> - async_io(device, output) - - nil -> - raise "no device registered with the name #{inspect(name)}" - end - end - defp async_io(device, output) when is_pid(device) do send(device, {:io_request, self(), make_ref(), {:put_chars, :unicode, output}}) end diff --git a/lib/livebook/session/data.ex b/lib/livebook/session/data.ex index 8f0609ea6..40da94366 100644 --- a/lib/livebook/session/data.ex +++ b/lib/livebook/session/data.ex @@ -1106,7 +1106,8 @@ defmodule Livebook.Session.Data do # Note: the session LV drops cell's source once it's no longer needed new_source = - cell.source && JSInterop.apply_delta_to_string(transformed_new_delta, cell.source) + Map.get(cell, :source) && + JSInterop.apply_delta_to_string(transformed_new_delta, cell.source) data_actions |> set!(notebook: Notebook.update_cell(data.notebook, cell.id, &%{&1 | source: new_source})) diff --git a/lib/livebook/users/user.ex b/lib/livebook/users/user.ex index 0a206ddbb..9b1017646 100644 --- a/lib/livebook/users/user.ex +++ b/lib/livebook/users/user.ex @@ -41,7 +41,8 @@ defmodule Livebook.Users.User do is returned, where `user` is partially updated by using only the valid attributes. """ - @spec change(t(), %{binary() => any()}) :: {:ok, t()} | {:error, list(String.t()), t()} + @spec change(t(), %{binary() => any()}) :: + {:ok, t()} | {:error, list({atom(), String.t()}), t()} def change(user, attrs \\ %{}) do {user, []} |> change_name(attrs) diff --git a/test/support/noop_runtime.ex b/test/support/noop_runtime.ex index 4af5ea396..64abb0375 100644 --- a/test/support/noop_runtime.ex +++ b/test/support/noop_runtime.ex @@ -9,7 +9,7 @@ defmodule Livebook.Runtime.NoopRuntime do def new(), do: %__MODULE__{} defimpl Livebook.Runtime do - def connect(_), do: :ok + def connect(_), do: make_ref() def disconnect(_), do: :ok def evaluate_code(_, _, _, _, _ \\ []), do: :ok def forget_evaluation(_, _), do: :ok