tme_317

tme_317

Running IO.inspect on a socket without truncating the result?

Hopefully a very simple question… I am troubleshooting and would like to see all the contents of a given socket using IO.inspect(). I know about using limit: :infinity to show everything in maps, lists, etc without truncation but that doesn’t seem to work with sockets. The printing is truncated with ...

Another weird thing is the socket is printed as #Phoenix.LiveView.Socket<> instead of %Phoenix.LiveView.Socket{} like a normal struct. What is a #Name<> data structure and how is it different than a struct? Couldn’t find where in the docs it is mentioned.

IO.inspect(socket, limit: :infinity)

returns this truncated result:

#Phoenix.LiveView.Socket<
   assigns: %{},
   changed: %{
     changeset: true,
     email: true,
     field_errors: true,
     form_error: true,
     ...
   },
   endpoint: MyAppWeb.Endpoint,
   id: "phx-4dWXZ4j7",
   parent_pid: nil,
   view: MyAppWeb.RegistrationLive,
   ...
 >
#io

Marked As Solved

sb8244

sb8244

Author of Real-Time Phoenix

LiveView derives the Inspect protocol here: phoenix_live_view/lib/phoenix_live_view/socket.ex at 900b6a3400771425f79d62e208f1fdd6b32aefd9 · phoenixframework/phoenix_live_view · GitHub

This causes the output to only include the specified fields and outputs in the <> syntax. You can see an example at https://hexdocs.pm/elixir/master/Inspect.html#module-deriving.

You may be able to use the structs: false opt to IO.inspect to get access to it.

:structs - when false, structs are not formatted by the inspect protocol, they are instead printed as maps, defaults to true.
21
Post #2

Also Liked

tme_317

tme_317

Thanks @sb8244, really appreciate it… been working with Elixir a couple years and amazingly have never read about the inner workings of the Inspect protocol and deriving.

Where Next?

Popular in Questions Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement