Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another crash on valid Erlang module #2086

Closed
michalmuskala opened this issue Jan 29, 2025 · 2 comments
Closed

Another crash on valid Erlang module #2086

michalmuskala opened this issue Jan 29, 2025 · 2 comments

Comments

@michalmuskala
Copy link
Member

Given this module:

-module(test).
-moduledoc "".

-export_type([
    enum/0,
    union/0,
    entity/0
]).

-type enum() :: foo.
-type union() :: bar.
-type entity() :: enum() | union().

compiled with erlc +debug_info -o test_ebin test.erl

and placing this file as test.app inside test_ebin

{application, test, [
    {applications, [kernel, stdlib]},
    {modules, [test]}
]}.

Calling the escript as ./ex_doc -f html foobar 1.0.0 test_ebin crashes with:

17:51:37.035 [error] Task #PID<0.116.0> started from #PID<0.112.0> terminating
** (Enum.EmptyError) empty error
    (elixir 1.18.2) lib/enum.ex:2489: Enum.reduce/2
    (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.18.2) lib/code/typespec.ex:302: Code.Typespec.typespec_to_quoted/1
    (elixir 1.18.2) lib/code/typespec.ex:72: Code.Typespec.type_to_quoted/1
    (ex_doc 0.37.0-rc.2) lib/ex_doc/language/erlang.ex:240: ExDoc.Language.Erlang.autolink_spec/2
    (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (ex_doc 0.37.0-rc.2) lib/ex_doc/formatter/html.ex:109: anonymous fn/5 in ExDoc.Formatter.HTML.render_all/5
Function: &:erlang.apply/2
    Args: [#Function<18.71509929/1 in ExDoc.Formatter.HTML.render_all/5>, [%ExDoc.ModuleNode{id: "test", title: "test", nested_context: nil, nested_title: nil, module: :test, group: nil, deprecated: nil, doc_format: "text/markdown", doc: [], source_doc: %{"en" => ""}, rendered_doc: nil, moduledoc_line: 2, moduledoc_file: "test.erl", source_path: nil, source_url: nil, docs_groups: ["Types", "Callbacks", "Functions"], docs: [%ExDoc.DocNode{id: "t:entity/0", name: :entity, arity: 0, defaults: [], deprecated: nil, doc: nil, source_doc: :none, rendered_doc: nil, type: :type, signature: "entity()", specs: [{:attribute, [file: "/Users/micmus/github/elixir-lang/ex_doc/test.erl", location: {12, 2}], :type, {:entity, {:type, {12, 19}, :union, [{:type, {12, 19}, :enum, []}, {:type, {12, 28}, :union, []}]}, []}}], annotations: [], group: "Types", doc_line: 12, doc_file: "test.erl", source_url: nil}, %ExDoc.DocNode{id: "t:enum/0", name: :enum, arity: 0, defaults: [], deprecated: nil, doc: nil, source_doc: :none, rendered_doc: nil, type: :type, signature: "enum()", specs: [{:attribute, [file: "/Users/micmus/github/elixir-lang/ex_doc/test.erl", location: {10, 2}], :type, {:enum, {:atom, {10, 17}, :foo}, []}}], annotations: [], group: "Types", doc_line: 10, doc_file: "test.erl", source_url: nil}, %ExDoc.DocNode{id: "t:union/0", name: :union, arity: 0, defaults: [], deprecated: nil, doc: nil, source_doc: :none, rendered_doc: nil, type: :type, signature: "union()", specs: [{:attribute, [file: "/Users/micmus/github/elixir-lang/ex_doc/test.erl", location: {11, 2}], :type, {:union, {:atom, {11, 18}, :bar}, []}}], annotations: [], group: "Types", doc_line: 11, doc_file: "test.erl", source_url: nil}], typespecs: [], type: :module, language: ExDoc.Language.Erlang, annotations: [], metadata: %{otp_doc_vsn: {1, 0, 0}, kind: :module}}]]
** (EXIT from #PID<0.112.0>) an exception was raised:
    ** (Enum.EmptyError) empty error
        (elixir 1.18.2) lib/enum.ex:2489: Enum.reduce/2
        (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
        (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
        (elixir 1.18.2) lib/code/typespec.ex:302: Code.Typespec.typespec_to_quoted/1
        (elixir 1.18.2) lib/code/typespec.ex:72: Code.Typespec.type_to_quoted/1
        (ex_doc 0.37.0-rc.2) lib/ex_doc/language/erlang.ex:240: ExDoc.Language.Erlang.autolink_spec/2
        (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
        (ex_doc 0.37.0-rc.2) lib/ex_doc/formatter/html.ex:109: anonymous fn/5 in ExDoc.Formatter.HTML.render_all/5

This is on latest master and following elixir --version:

Erlang/OTP 27 [erts-15.2.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit] [dtrace]

Elixir 1.18.2 (compiled with Erlang/OTP 27)
@josevalim
Copy link
Member

I will take a look, thank you. Btw, in the long term, we should stop translating Erlang typespecs into Elixir. We should either:

  1. Add a function to Erlang/OTP to pretty print typespecs with links
  2. Tranverse the Erlang AST instead when generating links

This way we can evolve the Erlang components of ExDoc without depending on Elixir. Contributions around those areas would be very welcome.

@garazdawi
Copy link
Contributor

@michalmuskala Do you know if it be possible to run https://github.com/WhatsApp/erlfuzz and see if there are any more cases that need to be covered?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants