Ask Your Question

Function 'fail' does not return a value

asked 2016-02-11 08:24:28 -0600

karthikeayan gravatar image

updated 2016-02-11 09:02:23 -0600

I have define function and writing puppet-rspec for this.

define test-define {
  $app_type = $name ? {
    'type1'    => $type1_script_dirs,
    'type2'    => $type2_script_dirs,
    'type3'    => $type3_script_dirs,
    'type4'    => $type4_script_dirs,
    default   => fail("Unknown app name : ${name}"),

  exec { "${app_type}" :
    command => "some command",

And from one of the class in the same module this function has been called with values type1, type2, type3 and type4. So there are already 4 exec added to the catalog with type1, type2, type3 and type4.

Now when I write rspec for this define, I am passing title like below:

let(:title) { 'another-type' }

When I execute rspec I am getting the below error,

Function 'fail' does not return a value

Also I can't pass any vales from type1, type2, type3 and type4 because all these 4 values are already added to the catalog from another class. So when I pass type1 I am getting duplicate declaration.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-02-11 10:26:57 -0600

This message is telling you that you can't use the fail function in a selector, because it doesn't return a value. Remember, the "default" in that context is the default value to give to $app_type.

You probably want a case statement:

define test-define {
  case $name {
    'type1': { $app_type = $type1_script_dirs }
    'type2': { $app_type = $type2_script_dirs }
    'type3': { $app_type = $type3_script_dirs }
    'type4': { $app_type = $type4_script_dirs }
    default: { fail("Unknown app name : ${name}") }

  exec { "${app_type}" :
    command => "some command",
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2016-02-11 08:24:28 -0600

Seen: 456 times

Last updated: Feb 11 '16