From b232e01ef73e61a0c81affa15aac6aeffd84866e Mon Sep 17 00:00:00 2001 From: Chris Garvis Date: Tue, 12 May 2026 22:53:52 -0400 Subject: [PATCH] Fix source field typespecs in HTTPError and TransportError Mint.HTTPError.t() and Mint.TransportError.t() only declare the :reason field in their @type t() definitions, omitting other struct fields (e.g. :module in Mint.HTTPError). When the set-theoretic type checker resolves these as closed-map types, a value matched via a struct pattern carries extra fields that fall outside the declared type, producing a :badstructfield diagnostic. The :source field stores the original Mint exception so that Exception.message/1 can delegate to it. Exception.t() is the accurate type for that usage and resolves the incompatibility. --- lib/finch/http_error.ex | 2 +- lib/finch/transport_error.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/finch/http_error.ex b/lib/finch/http_error.ex index 6bfe7d90..43df0e36 100644 --- a/lib/finch/http_error.ex +++ b/lib/finch/http_error.ex @@ -8,7 +8,7 @@ defmodule Finch.HTTPError do @type t() :: %__MODULE__{ reason: reason(), module: module() | nil, - source: Mint.HTTPError.t() | nil + source: Exception.t() | nil } defexception [:reason, :module, :source] diff --git a/lib/finch/transport_error.ex b/lib/finch/transport_error.ex index e4041004..2a4f440f 100644 --- a/lib/finch/transport_error.ex +++ b/lib/finch/transport_error.ex @@ -5,7 +5,7 @@ defmodule Finch.TransportError do @type reason() :: Mint.TransportError.reason() - @type t() :: %__MODULE__{reason: reason(), source: Mint.TransportError.t() | nil} + @type t() :: %__MODULE__{reason: reason(), source: Exception.t() | nil} defexception [:reason, :source]