On Friday, July 25, 2014 11:25:37 AM UTC-5, Andy Parker wrote:
>
> On Thu, Jul 24, 2014 at 6:04 PM, Henrik Lindberg <
> henrik....@cloudsmith.com <javascript:>> wrote:
>
>> On 2014-25-07 2:32, Andy Parker wrote:
>>
>>>
>>>
>>> DECISION SEVEN
>>>
>>>    undef is not allowed as a title
>>>
>>> Not much to say here. notify { undef: } fails (or anything that
>>> evaluates to undef)
>>>
>>>  
>> DECISION SEVEN AND 3/4
>>
>> A title expression must result in a String value, or Array of String 
>> values. No regular expressions, hashes, booleans, numbers etc.
>>
>> No magic turning a title into a string if it is not.
>>
>>
> I agree in principle, but am worried about the impact. Right now it is 
> somewhat common to do things like:
>
>   # bad example but should illustrate the idea
>   define hosts() {
>     host { $title[hostname]: ip => $title[ip] }
>   }
>
>   hosts { [{ hostname => andy, ip => '192.168.12.3' },
>               { hostname => henrik, ip => '192.168.12.4' }]: }
>
> This ends up creating instances of Hosts with hashes as titles. Often this 
> works out fine...just not always.
>


No, that's not common at all, because it doesn't work (or it never used to 
do, anyway).  Resource titles are *always* strings.  Puppet stringifies 
values of other types (except one level of array) if they are used as 
resource titles.

This actually comes up from time to time on puppet-users.  People try to 
instantiate a defined type with a hash as its title, and Puppet throws an 
error when the defined type body tries to apply the element selection 
operator to the title.

Henrik is suggesting (I think) that the error instead be in the 
instantiation expression, when it turns out that the title is not a 
String.  I think that's a great idea, because it causes the error to be 
flagged where it occurs.  If you really want to create resources with 
stringified hashes (or whatever) as titles, then there should be a 
to_string() function that you can apply to the hashes to show that you 
really mean it.  And with the future parser, you can easily apply it to the 
array elements in your example if that's what you want to do.  It also fits 
in naturally with the more specific limitation that titles not be undef.


John

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/b8ea69f9-30dc-4fa5-8d45-97597564d39c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to