gproc
gproc copied to clipboard
get_env and honoring the {default,Value} strategy
When get_env is called with a key that does not exist in the gproc cache the function exits the process with badarg; this is the expected behaviour if there is no {default, Value} strategy.
However, even with a {default,Value} strategy the function still exits the process without returning the default value.
This happens because lookup_env is called first (before try_alternatives) and ets:lookup throws a badarg in line 529 of gproc.erl:
https://github.com/uwiger/gproc/blob/46238dea573c3910c2a1ec9e413925b2cc471494/src/gproc.erl#L529
Maybe I am reading the documentation wrongly, but it surely seems that get_env should return the default value if that strategy is specified.
Have you started gproc before trying this?
ets:lookup/2 will not throw a badarg exception just because an object doesn't exist, but does do it e.g. if the table is not accessible.
Yes, I didn't mention that - should it not return the default in that case also? (e.g. even if gproc has not been started)
That's not the intent, no. :) I guess that hasn't been explicitly documented. I'll try to squeeze it into the README.
good, thanks for the good work with gproc, plain_fsm and the parse transform tools you've made. Really appreciate it, it has done a lot of good to the erlang world.