gproc icon indicating copy to clipboard operation
gproc copied to clipboard

get_env and honoring the {default,Value} strategy

Open erlanger opened this issue 10 years ago • 4 comments
trafficstars

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.

erlanger avatar Jan 16 '15 03:01 erlanger

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.

uwiger avatar Jan 16 '15 06:01 uwiger

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)

erlanger avatar Jan 18 '15 20:01 erlanger

That's not the intent, no. :) I guess that hasn't been explicitly documented. I'll try to squeeze it into the README.

uwiger avatar Jan 18 '15 23:01 uwiger

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.

erlanger avatar Jan 21 '15 02:01 erlanger