Skip to content

Commit

Permalink
workaround elixir bug
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Jan 21, 2024
1 parent c40c0da commit 06ed2cc
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/elixir_sense/core/normalized/typespec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,48 @@ defmodule ElixirSense.Core.Normalized.Typespec do
def get_specs(module) do
get_module().fetch_specs(module)
|> extract_specs
rescue
e in FunctionClauseError ->
# workaround for crash
# Keyword.fetch({:error, :beam_lib, {:not_a_beam_file, ""}}, :module)
# fixed in elixir 1.16.0
if Version.match?(System.version(), ">= 1.16.0-dev") do
reraise e, __STACKTRACE__
else
[]
end
end

@spec get_types(module) :: [tuple]
def get_types(module) when is_atom(module) do
get_module().fetch_types(module)
|> extract_specs
rescue
e in FunctionClauseError ->
# workaround for crash
# Keyword.fetch({:error, :beam_lib, {:not_a_beam_file, ""}}, :module)
# fixed in elixir 1.16.0
if Version.match?(System.version(), ">= 1.16.0-dev") do
reraise e, __STACKTRACE__
else
[]
end
end

@spec get_callbacks(module) :: [tuple]
def get_callbacks(module) do
get_module().fetch_callbacks(module)
|> extract_specs
rescue
e in FunctionClauseError ->
# workaround for crash
# Keyword.fetch({:error, :beam_lib, {:not_a_beam_file, ""}}, :module)
# fixed in elixir 1.16.0
if Version.match?(System.version(), ">= 1.16.0-dev") do
reraise e, __STACKTRACE__
else
[]
end
end

defp extract_specs({:ok, specs}), do: specs
Expand Down

0 comments on commit 06ed2cc

Please sign in to comment.