sztosz
I have in module a very long list of filters like this:
@mapping %{
published_at: {:date_time, "published_at"},
indexed_at: {:date_time, "indexed_at"},
...
not_parent_shared_uid: {:terms_exclusion, "parent.shared_uid"},
...
}
Because I wan’t to dynamically call some functions like this
def parse_filter({filter_name, value}, topic_id, acc) do
{function, field} = Map.get(@mapping, String.to_existing_atom(filter_name))
apply(__MODULE__, function, [value, field, topic_id, acc])
end
Yet for existing atoms in @mapping I sometimes, occasionally get
Elixir.ArgumentError in :erlang.binary_to_existing_atom/2
arg0: "not_parent_shared_uid"
arg1: :utf8
So the question is, how can I make sure that those atoms do exist?
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
blackode
I think this will solve your problem.
Just checking whether the
filter_nameis atom or not.sztosz
Actually I am 100% sure the filter_name is binary (string actually), but it comes from a json, so I don’t want to use
String.to_atom()to circumvent potential creation of invalid atoms. I have no problems with errors being raised when there is no atom in system, but the error is raised for valid atoms.Also UPDATE: I copied modified code from my debug session earlier. Instead of
to_atomI am actually usingto_existing_atom. Withto_atomit works as intended, the problem is withto_existing_atomidi527
Maybe you can replace your map with a “function lookup”. And have mappings keys be strings? Would it change anything?
NobbZ
Are you sure, that the string does not contain any unprintable bytes (zero width space or similar)?
But instead of relying on
String.to_existing_atom/1, I’d use something like this:Or if you need the crash on invalid filter names use
Map.fetch!/2instead ofAccess-Syntax.edit
Using
Map.fetch!/2had actually the benefit that we would also fail for"ok", whileString.to_existing_atom("ok")fould simply return:ok.sztosz
@idi527: I’d rather use atoms as map keys, although it’s just a personal preference. But I’ll look more into your code, thanks
I can’t be sure, it comes from the outside. It’s not really something I can control, I have to have “good faith” in the maintainer of the app that’s queering this app of mine. He’s got no malicious intent, though, as he’s a my work colleague.
With Map.fetch! this would fail every time exactly where it should, so I may go with this instead. Thanks