phenixdigital / phoenix_storybook

A pluggable storybook for your Phoenix components.
MIT License
677 stars 54 forks source link

passing complex attribute can fail #189

Closed iwarshak closed 1 year ago

iwarshak commented 1 year ago

I cannot get phx_live_storybook to work when complex structs (ecto schemas) or long lists are passed as attributes. As an example

  def variations do
    items = Enum.to_list((1..123))
    Logger.warn("items are #{inspect items}")
  [
    %VariationGroup{
      id: :group_1,
      variations: [
        %Variation{
          id: :default,
          attributes: %{
            page: 1,
            total_results: 123,
            items: items,
            prev: "prev",
            next: "next",
            per_page: 4
          }
        },
      ]
    }
  ]
  end

will result in the following error in the console:

[warning] 17:15:56.424 request_id=FygzvsTSZy-9SQUAACJm remote_ip=127.0.0.1 current_login_id=42478 current_artist_id=45256 current_login_email=lelah1903@foo.com mfa=Storybook.Components.Pagination.variations/0 pid=<0.6007.0>  items are [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, ...]
warning: variable "..." does not exist and is being expanded to "...()", please use parentheses to remove the ambiguity or change the variable name
  nofile:1

[info] 17:15:56.703 request_id=FygzvsTSZy-9SQUAACJm remote_ip=127.0.0.1 current_login_id=42478 current_artist_id=45256 current_login_email=lelah1903@foo.com mfa=Logster.Plugs.Logger.call/2 pid=<0.6007.0>  state=set duration=323.349 status=500 params={"story":["components","pagination"]} path=/storybook/components/pagination method=GET
[error] 17:15:56.703 pid=<0.5203.0>  #PID<0.6007.0> running HurlerWeb.Endpoint (connection #PID<0.5203.0>, stream id 54) terminated
Server: localhost:8102 (http)
Request: GET /storybook/components/pagination
** (exit) an exception was raised:
    ** (CompileError) nofile:1: undefined function .../0 (there is no such import)
        (elixir 1.14.0) src/elixir_expand.erl:618: :elixir_expand.expand_arg/3
        (elixir 1.14.0) src/elixir_expand.erl:556: :elixir_expand.expand_list/5
        (elixir 1.14.0) src/elixir_expand.erl:466: :elixir_expand.expand/3
        (elixir 1.14.0) src/elixir_expand.erl:618: :elixir_expand.expand_arg/3
        (elixir 1.14.0) src/elixir_expand.erl:634: :elixir_expand.mapfold/5
        (elixir 1.14.0) src/elixir_expand.erl:627: :elixir_expand.expand_args/3
        (elixir 1.14.0) src/elixir_expand.erl:458: :elixir_expand.expand/3
        (elixir 1.14.0) src/elixir_expand.erl:618: :elixir_expand.expand_arg/3
        (elixir 1.14.0) src/elixir_expand.erl:634: :elixir_expand.mapfold/5
        (elixir 1.14.0) src/elixir_expand.erl:627: :elixir_expand.expand_args/3
        (elixir 1.14.0) src/elixir_map.erl:13: :elixir_map.expand_map/4
        (elixir 1.14.0) src/elixir_expand.erl:618: :elixir_expand.expand_arg/3
        (elixir 1.14.0) src/elixir_expand.erl:634: :elixir_expand.mapfold/5
        (elixir 1.14.0) src/elixir_expand.erl:848: :elixir_expand.expand_remote/8
        (elixir 1.14.0) src/elixir_expand.erl:618: :elixir_expand.expand_arg/3
        (elixir 1.14.0) src/elixir_expand.erl:634: :elixir_expand.mapfold/5
        (elixir 1.14.0) src/elixir_expand.erl:848: :elixir_expand.expand_remote/8
        (elixir 1.14.0) src/elixir_expand.erl:10: :elixir_expand.expand/3
        (elixir 1.14.0) src/elixir_expand.erl:567: :elixir_expand.expand_block/5

I am happy to dig into this more, but based on this output and a similar sort of output it seems like phx_live_storybook tries to interpret the IO.inspect output of the attributes as the actual value.

cblavier commented 1 year ago

Hey Ian, it seems like a bug indeed.

It looks a lot like an inspect/1 issue in the storybook code truncating long code with a ... ellipsis.

cblavier commented 1 year ago

I think this is the same issue as #157 Ian, can you check with the main branch before I close the issue?

iwarshak commented 1 year ago

Just ran on the main branch and am getting the same error

cblavier commented 1 year ago

Fixed by #191 🙏