Skip to content

Commit c515163

Browse files
committed
fix: resolve Dialyzer type errors and pattern matching issues
- Remove unreachable cleanup_pidfile error pattern in Server.bootstrap/0 - Fix pattern matching in Server.bootstrap/0 to handle init_config_file errors - Remove dead code branches in Config.validate_bin/1 and Config.read_saved_config/0 - Add Dialyzer ignore file for supervisor callback false positives - Configure mix.exs to use dialyzer.ignore-warnings - Update telemetry start_poller spec to include :ignore return type - Reduce Dialyzer errors from 8 to 0 (4 ignored false positives)
1 parent be10d05 commit c515163

File tree

5 files changed

+11
-18
lines changed

5 files changed

+11
-18
lines changed

dialyzer.ignore-warnings

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Supervisor callbacks - false positives from Dialyzer
2+
# These functions return supervisor specs and don't have "no return" issues
3+
lib/caddy.ex:100
4+
lib/caddy/logger.ex:37
5+
lib/caddy/telemetry.ex:69

lib/caddy/config.ex

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ defmodule Caddy.Config do
264264
case check_bin(caddy_bin) do
265265
:ok -> :ok
266266
{:error, _} -> {:error, "Invalid Caddy binary or version incompatibility"}
267-
_ -> {:error, "Failed to validate Caddy binary"}
268267
end
269268
end
270269
rescue
@@ -410,9 +409,6 @@ defmodule Caddy.Config do
410409
{:error, reason} ->
411410
Logger.warning("Failed to read saved configuration: #{inspect(reason)}")
412411
%{}
413-
414-
_ ->
415-
%{}
416412
end
417413
end
418414

lib/caddy/server.ex

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,6 @@ defmodule Caddy.Server do
133133

134134
{:error, "Failed to create required directories"}
135135

136-
{:cleanup_pidfile, _} ->
137-
duration = System.monotonic_time() - start_time
138-
139-
Caddy.Telemetry.emit_server_event(:bootstrap_error, %{duration: duration}, %{
140-
error: "Failed to cleanup pidfile"
141-
})
142-
143-
{:error, "Failed to cleanup pidfile"}
144-
145136
{:validate_bin, {:error, reason}} ->
146137
duration = System.monotonic_time() - start_time
147138

@@ -160,14 +151,14 @@ defmodule Caddy.Server do
160151

161152
{:error, reason}
162153

163-
{:init_config_file, error} ->
154+
{:error, reason} = error ->
164155
duration = System.monotonic_time() - start_time
165156

166157
Caddy.Telemetry.emit_server_event(:bootstrap_error, %{duration: duration}, %{
167-
error: "Configuration file error: #{inspect(error)}"
158+
error: "Configuration file error: #{inspect(reason)}"
168159
})
169160

170-
{:error, "Configuration file error: #{inspect(error)}"}
161+
{:error, "Configuration file error: #{inspect(reason)}"}
171162

172163
error ->
173164
duration = System.monotonic_time() - start_time

lib/caddy/telemetry.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ defmodule Caddy.Telemetry do
6565
@doc """
6666
Starts telemetry poller for periodic metrics.
6767
"""
68-
@spec start_poller(non_neg_integer()) :: {:ok, pid()} | {:error, term()}
68+
@spec start_poller(non_neg_integer()) :: {:ok, pid()} | {:error, term()} | :ignore
6969
def start_poller(interval_ms \\ 30_000) do
7070
measurements = %{
7171
memory: fn -> :erlang.memory() end,

mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ defmodule Caddy.MixProject do
1818
docs: docs(),
1919
dialyzer: [
2020
plt_file: {:no_warn, "priv/plts/dialyzer.plt"},
21-
plt_add_apps: [:mix]
21+
plt_add_apps: [:mix],
22+
ignore_warnings: "dialyzer.ignore-warnings"
2223
]
2324
]
2425
end

0 commit comments

Comments
 (0)