Closed Licenser closed 10 years ago
@Licenser could you include the real-world example you ran in to?
In the schema I tried to assing the mdns ip based on weather the ip/port is set, this needed a translation, which should not set anything in the app.config when ip/port is not set.
@Licenser Would having the translation return 'undefined' when the IP/Port combination solve the problem?
Yap, it would turn into {ok, undefined}
with the get_env which is different form undefined
aside of adding a third fork in the code path it'd break the claim that we can use get_env the same way as before ;)
@Licenser what if you used get_env/3 instead of get_env/2?
Not available in erlang R15 :(, that said in R16 I could put in the code to default to {ok, undefined}
but that still would be kind of a horrible hackish solution.
So it's no longer 'undefined' it's "defined as undefined
"
yea but get_env treats those two situations differently:
get_env(something)
returns undefined
undefined
then get_env(something)
returns {ok, undefined}
I'll take this scenario under advisement, but for now, your best bet is to add the third clause for reading this value:
{ok, undefined} -> blah;
undefined -> blah;
{ok, Value} -> blah
To add to this I just thought of another issue, if someone were to use get_env/3
the default would not be picked when the value is set to undefined
instead of not being defined at all breaking that behavior and being quite counter intuitive.
get_env/3
has it's own issues, use at your own risk ;)
@Licenser We now have an API function cuttlefish:unset()
which can be used to skip emitting a value to the generated configuration. Closing this issue.
Basically it is possible to have a mapping not take effect when they are not present, right now there isn't a way to have this behaviour for translations.
A simple way to implement this would to change the return value of translation functions to
{ok, Value}
orundefined
in which case undefined would mean the translation has no effect.