smetana

smetana

How to increase printable_limit from Macro.to_string()?

Hello all,

I need to convert AST with possible long binary to string.
Macro.to_string() uses Inspect and Inspect has the printable_limit option set to 4096 for binaries by default.
I am looking for the way to increase it so binary will not be truncated on to_string()

Thanks,
Serge

Marked As Solved

net

net

I believe this is already fixed in master. Until that’s released you can do

Macro.to_string(v, fn
  node, _ when is_binary(node) -> inspect(node, printable_limit: :infinity)
  _, string -> string
end)

Also Liked

michalmuskala

michalmuskala

This seems like a bug in Macro.to_string to me - it should print everything out. Could you open a bug report?

mruoss

mruoss

This is too related to open a new thread. But when posting before, I wasn’t aware that the problem exists only for maps now. It’s basically the same issue but for maps. Opened a GH issue here:

https://github.com/elixir-lang/elixir/issues/13875

mruoss

mruoss

Copying over José’s answer for shortcuts:

The difference here is that maps are not valid AST. We fallback to inspect in Macro.to_string for convenience, because the goal of the macro is mostly debugging, but if you returned that from a macro, Elixir would raise accordingly. In any case, it won’t be formatted accordingly. The correct fix is to call Macro.escapeor build the correct Map ast, as shown in the result of quote do: %{1 => 2, foo: :bar}|

For me, Macro.escape did the trick:

my_map = Map.new(1..51, &{&1, "value"}) |> Macro.escape()

(quote do: unquote(my_map))
|> Macro.to_string()
|> IO.inspect(printable_limit: :infinity)

Last Post!

mruoss

mruoss

This doesn’t truncate the map. However, it still does a better job formatting the code when escaping the map to a valid AST.

Where Next?

Popular in Questions Top

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
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
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
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement