basho / cuttlefish

never lose your childlike sense of wonder baby cuttlefish, promise me?
Apache License 2.0
205 stars 124 forks source link

There doesn't appear to be a way to specify an empty string in the .conf file #153

Open rlipscombe opened 10 years ago

rlipscombe commented 10 years ago

I have a mapping:

{mapping, "db.password", "foo.bar.primary.db.password", []}.

In my foo.conf file, if I want to use a blank password, I try the following:

db.password = 

I get the following error:

escript: exception error: no function clause matching 
                 lists:unzip({[{["nodename"],"foo"},
                               {["distributed_cookie"],"foo"},
                               {["audit","root"],"/tmp"},
                               {["db","hostname"],
                                "localhost"},
                               {["db","database"],
                                "foo"},
                               {["db","username"],
                                "meh"}],
                              <<"db.password =\n">>,
                              {{line,12},{column,1}}},
                             [],[]) (lists.erl, line 387)
  in function  cuttlefish_conf:file/1 (src/cuttlefish_conf.erl, line 71)
  in call from cuttlefish_conf:'-files/1-fun-1-'/2 (src/cuttlefish_conf.erl, line 45)
  in call from lists:foldl/3 (lists.erl, line 1248)
  in call from cuttlefish_conf:files/1 (src/cuttlefish_conf.erl, line 43)
  in call from cuttlefish_escript:load_conf/1 (src/cuttlefish_escript.erl, line 307)
  in call from cuttlefish_escript:engage_cuttlefish/1 (src/cuttlefish_escript.erl, line 360)
  in call from cuttlefish_escript:generate/1 (src/cuttlefish_escript.erl, line 259)
seancribbs commented 10 years ago

That happens because the result of the parse is not checked strictly. conf_parse:file/1 returns list() on success and {list(), binary(), {{line,pos_integer()},{column,pos_integer()}}} on incomplete parse.

Assigning to 2.1 milestone, if necessary we can move it up.

seancribbs commented 10 years ago

Sorry, more to the point - I doubt the "empty string" will be a valid RHS in this format, ever. It would be better to define an atom value, or other setting that disables the password. Also, if you don't have a default for the setting, it will remain unset.

In your schema example, this is the case. The user need only omit the setting from the conf file for the password to be empty/unset.

seancribbs commented 10 years ago

Another possibility would be to interpret the empty 'string' "" in a translation, but that also feels like a hack.