The Problem Given the below code I would expect to get an error message back indicating that the test parameter didn't pass type validation but it instead causes failure in the function used in the parameter below.
function puppet_enterprise::calculate_log_temp_files( |
Variant[String, Integer] $work_mem, |
) >> Integer { |
#work_mem is specified in kB if no memory unit is provided |
if $work_mem =~ /\A(\d+)(kB|MB|GB|TB)\Z/ { |
|
$wm_size = $work_mem.pe_size() |
|
$work_mem_integer = $work_mem[0, $wm_size - 2] |
|
$work_mem_suffix = $work_mem[$wm_size-2, $wm_size] |
|
$multiplier = $work_mem_suffix ? { |
'kb' => 1, |
'MB' => 1024, |
'GB' => 1024*1024, |
'TB' => 1024*1024*1024, |
} |
|
$log_temp_files = Integer($work_mem_integer * $multiplier) |
} else { |
$log_temp_files = Integer($work_mem) |
} |
} |
|
|
class my_class ( |
Integer[64] $test, |
Integer $blah = puppet_enterprise::calculate_log_temp_files($test), |
) { |
#do things |
} |
|
class { 'my_class' : |
test => 63, |
}
|
Causes a failure like:
[root@master201811-centos ~]# puppet apply /tmp/test.pp |
Error: Evaluation Error: Left match operand must result in a String value. Got an Integer. (file: /tmp/test.pp, line: 5, column: 6) on node master201811-centos.puppetdebug.vlan
|
Expected Behavior If I fix the function so it doesn't fail then I get something like this which is the same thing I would expect since I don't expect the function to be evaluated if the first parameter doesn't pass type validation.
Error: Evaluation Error: Error while evaluating a Resource Statement, Class[My_class]: |
parameter 'test' expects an Integer[64] value, got Integer[63, 63]
|
|