Skip to content

Commit 2fbb023

Browse files
authored
Run Dialyzer on CI (#285)
* remove dead code * add explicit dependancy on Jason * match on success in functions that may fail * warn if unable to remove temp file * warn if unable to read/write protocol messages * only build test/support in test env * annotate match against opaque type * add missing applications otherwise elixir 1.11 will emit a warning * add empty ignore file * add dialyzer config * run formatter * run dialyzer on CI
1 parent 55c24db commit 2fbb023

File tree

18 files changed

+117
-58
lines changed

18 files changed

+117
-58
lines changed

.dialyzer_ignore.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

.formatter.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
inputs: [
3-
"mix.exs",
3+
"*.exs",
44
"config/**/*.exs",
55
"apps/*/{config,lib,test}/**/*.{ex,exs}",
66
"apps/*/mix.exs"

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ script:
99
echo "Not checking formatting"
1010
fi
1111
- mix test
12+
- |
13+
if [[ "$RUN_DIALYZER" -eq 1 ]]
14+
then
15+
mix dialyzer
16+
else
17+
echo "Not running Dialyzer"
18+
fi
1219
env:
1320
global:
1421
- MIX_HOME=$HOME/.mix
@@ -27,4 +34,6 @@ matrix:
2734
elixir: 1.9.4
2835
- otp_release: 22.2
2936
elixir: 1.10.2
30-
env: CHECK_FORMATTED=1
37+
env:
38+
- CHECK_FORMATTED=1
39+
- RUN_DIALYZER=1

apps/elixir_ls_debugger/lib/debugger.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule ElixirLS.Debugger do
99
def start(_type, _args) do
1010
# We don't start this as a worker because if the debugger crashes, we want
1111
# this process to remain alive to print errors
12-
ElixirLS.Debugger.Output.start(ElixirLS.Debugger.Output)
12+
{:ok, _pid} = ElixirLS.Debugger.Output.start(ElixirLS.Debugger.Output)
1313

1414
children = [
1515
{ElixirLS.Debugger.Server, name: ElixirLS.Debugger.Server}

apps/elixir_ls_debugger/lib/debugger/cli.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule ElixirLS.Debugger.CLI do
55
def main do
66
WireProtocol.intercept_output(&Output.print/1, &Output.print_err/1)
77
Launch.start_mix()
8-
Application.ensure_all_started(:elixir_ls_debugger, :permanent)
8+
{:ok, _} = Application.ensure_all_started(:elixir_ls_debugger, :permanent)
99
IO.puts("Started ElixirLS debugger v#{Launch.debugger_version()}")
1010
Launch.print_versions()
1111
warn_if_unsupported_version()

apps/elixir_ls_debugger/lib/debugger/server.ex

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ defmodule ElixirLS.Debugger.Server do
5454

5555
@impl GenServer
5656
def init(opts) do
57-
:int.start()
57+
{:ok, _pid} = :int.start()
5858
state = if opts[:output], do: %__MODULE__{output: opts[:output]}, else: %__MODULE__{}
5959
{:ok, state}
6060
end
@@ -595,9 +595,9 @@ defmodule ElixirLS.Debugger.Server do
595595
# test helpers before tests). We save the .beam files to a temporary folder which we add to the
596596
# code path.
597597
defp require_files(required_files) do
598-
File.rm_rf(@temp_beam_dir)
599-
File.mkdir_p(@temp_beam_dir)
600-
Code.append_path(Path.expand(@temp_beam_dir))
598+
{:ok, _} = File.rm_rf(@temp_beam_dir)
599+
:ok = File.mkdir_p(@temp_beam_dir)
600+
true = Code.append_path(Path.expand(@temp_beam_dir))
601601

602602
for path <- required_files,
603603
file <- Path.wildcard(path),
@@ -608,7 +608,7 @@ defmodule ElixirLS.Debugger.Server do
608608
end
609609

610610
defp save_and_reload(module, beam_bin) do
611-
File.write(Path.join(@temp_beam_dir, to_string(module) <> ".beam"), beam_bin)
611+
:ok = File.write(Path.join(@temp_beam_dir, to_string(module) <> ".beam"), beam_bin)
612612
:code.delete(module)
613613
:int.ni(module)
614614
end

apps/elixir_ls_debugger/mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule ElixirLS.Debugger.Mixfile do
1919
end
2020

2121
def application do
22-
[mod: {ElixirLS.Debugger, []}, extra_applications: [:mix, :logger]]
22+
[mod: {ElixirLS.Debugger, []}, extra_applications: [:mix, :logger, :debugger]]
2323
end
2424

2525
defp deps do

apps/elixir_ls_utils/lib/mix.tasks.elixir_ls.release.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ defmodule Mix.Tasks.ElixirLs.Release do
3333
if opts[:zip] do
3434
zip_file = to_charlist(Path.expand(opts[:zip]))
3535
files = Enum.map(File.ls!(destination), &to_charlist/1)
36-
:zip.create(zip_file, files, cwd: to_charlist(destination))
36+
{:ok, _} = :zip.create(zip_file, files, cwd: to_charlist(destination))
3737
end
3838

3939
:ok

apps/elixir_ls_utils/lib/packet_stream.ex

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,69 @@ defmodule ElixirLS.Utils.PacketStream do
44
"""
55

66
def stream(pid \\ Process.group_leader()) do
7-
if is_pid(pid), do: :io.setopts(pid, binary: true, encoding: :latin1)
7+
if is_pid(pid) do
8+
:ok = :io.setopts(pid, binary: true, encoding: :latin1)
9+
end
810

911
Stream.resource(
1012
fn -> :ok end,
1113
fn _acc ->
1214
case read_packet(pid) do
1315
:eof -> {:halt, :ok}
16+
{:error, reason} -> {:halt, {:error, reason}}
1417
packet -> {[packet], :ok}
1518
end
1619
end,
17-
fn _acc -> :ok end
20+
fn
21+
:ok ->
22+
:ok
23+
24+
{:error, reason} ->
25+
IO.warn("Unable to read from device: #{inspect(reason)}")
26+
end
1827
)
1928
end
2029

2130
defp read_packet(pid) do
2231
header = read_header(pid)
2332

24-
if header == :eof do
25-
:eof
26-
else
27-
read_body(pid, header)
33+
case header do
34+
:eof -> :eof
35+
{:error, reason} -> {:error, reason}
36+
header -> read_body(pid, header)
2837
end
2938
end
3039

3140
defp read_header(pid, header \\ %{}) do
3241
line = IO.binread(pid, :line)
3342

34-
if line == :eof do
35-
:eof
36-
else
37-
line = String.trim(line)
43+
case line do
44+
:eof ->
45+
:eof
3846

39-
if line == "" do
40-
header
41-
else
42-
[key, value] = String.split(line, ": ")
43-
read_header(pid, Map.put(header, key, value))
44-
end
47+
{:error, reason} ->
48+
{:error, reason}
49+
50+
line ->
51+
line = String.trim(line)
52+
53+
if line == "" do
54+
header
55+
else
56+
[key, value] = String.split(line, ": ")
57+
read_header(pid, Map.put(header, key, value))
58+
end
4559
end
4660
end
4761

4862
defp read_body(pid, header) do
4963
%{"Content-Length" => content_length_str} = header
5064
body = IO.binread(pid, String.to_integer(content_length_str))
5165

52-
if body == :eof do
53-
:eof
54-
else
55-
JasonVendored.decode!(body)
66+
case body do
67+
:eof -> :eof
68+
{:error, reason} -> {:error, reason}
69+
body -> JasonVendored.decode!(body)
5670
end
5771
end
5872
end

apps/elixir_ls_utils/lib/wire_protocol.ex

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ defmodule ElixirLS.Utils.WireProtocol do
77
def send(packet) do
88
pid = io_dest()
99
body = JasonVendored.encode!(packet) <> "\r\n\r\n"
10-
IO.binwrite(pid, "Content-Length: #{byte_size(body)}\r\n\r\n" <> body)
10+
11+
case IO.binwrite(pid, "Content-Length: #{byte_size(body)}\r\n\r\n" <> body) do
12+
:ok ->
13+
:ok
14+
15+
{:error, reason} ->
16+
IO.warn("Unable to write to the device: #{inspect(reason)}")
17+
end
1118
end
1219

1320
defp io_dest do
@@ -21,7 +28,7 @@ defmodule ElixirLS.Utils.WireProtocol do
2128
def intercept_output(print_fn, print_err_fn) do
2229
raw_user = Process.whereis(:user)
2330
raw_standard_error = Process.whereis(:standard_error)
24-
:io.setopts(raw_user, binary: true, encoding: :latin1)
31+
:ok = :io.setopts(raw_user, binary: true, encoding: :latin1)
2532

2633
{:ok, user} = OutputDevice.start_link(raw_user, print_fn)
2734
{:ok, standard_error} = OutputDevice.start_link(raw_standard_error, print_err_fn)

0 commit comments

Comments
 (0)