Skip to content

Commit 73ae6a4

Browse files
committed
address Tess' feedback
1 parent 8c01c05 commit 73ae6a4

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

dsc/tests/dsc_user_functions.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,6 @@ resources:
149149
"@
150150
dsc -l trace config get -i $configYaml 2>$testdrive/error.log | Out-Null
151151
$LASTEXITCODE | Should -Be 2 -Because (Get-Content $testdrive/error.log | Out-String)
152-
(Get-Content $testdrive/error.log -Raw) | Should -BeLike "*Output of user function 'MyFunction.BadFunction' returned an integer, but was expected to be of type 'int'*" -Because (Get-Content $testdrive/error.log | Out-String)
152+
(Get-Content $testdrive/error.log -Raw) | Should -BeLike "*Output of user function 'MyFunction.BadFunction' did not returned expected type 'int'*" -Because (Get-Content $testdrive/error.log | Out-String)
153153
}
154154
}

dsc_lib/locales/en-us.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,10 @@ description = "Returns a deterministic unique string from the given strings"
480480
invoked = "uniqueString function"
481481

482482
[functions.userFunction]
483-
expectedNoParamters = "User function '%{name}' does not accept parameters"
483+
expectedNoParameters = "User function '%{name}' does not accept parameters"
484484
unknownUserFunction = "Unknown user function '%{name}'"
485485
wrongParamCount = "User function '%{name}' expects %{expected} parameters, but %{got} were provided"
486-
outputNotString = "Output of user function '%{name}' returned a string, but was expected to be of type '%{expected_type}'"
487-
outputNotInteger = "Output of user function '%{name}' returned an integer, but was expected to be of type '%{expected_type}'"
488-
outputNotBoolean = "Output of user function '%{name}' returned a boolean, but was expected to be of type '%{expected_type}'"
489-
outputNotArray = "Output of user function '%{name}' returned an array, but was expected to be of type '%{expected_type}'"
490-
outputNotObject = "Output of user function '%{name}' returned an object, but was expected to be of type '%{expected_type}'"
486+
incorrectOutputType = "Output of user function '%{name}' did not returned expected type '%{expected_type}'"
491487

492488
[functions.utcNow]
493489
description = "Returns the current UTC time"

dsc_lib/src/functions/user_function.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn invoke_user_function(name: &str, args: &[Value], context: &Context) -> Re
3232
user_context.user_functions.clear();
3333
for (i, arg) in args.iter().enumerate() {
3434
let Some(params) = &function_definition.parameters else {
35-
return Err(DscError::Parser(t!("functions.userFunction.expectedNoParamters", name = name).to_string()));
35+
return Err(DscError::Parser(t!("functions.userFunction.expectedNoParameters", name = name).to_string()));
3636
};
3737
user_context.parameters.insert(params[i].name.clone(), (arg.clone(), params[i].r#type.clone()));
3838
}
@@ -61,27 +61,27 @@ fn validate_output_type(name: &str, function_definition: &UserFunctionDefinition
6161
match function_definition.output.r#type {
6262
DataType::String | DataType::SecureString => {
6363
if !output.is_string() {
64-
return Err(DscError::Validation(t!("functions.userFunction.outputNotString", name = name, expected_type = function_definition.output.r#type.to_string()).to_string()));
64+
return Err(DscError::Validation(t!("functions.userFunction.incorrectOutputType", name = name, expected_type = "string").to_string()));
6565
}
6666
},
6767
DataType::Int => {
6868
if !output.is_i64() {
69-
return Err(DscError::Validation(t!("functions.userFunction.outputNotInteger", name = name, expected_type = function_definition.output.r#type.to_string()).to_string()));
69+
return Err(DscError::Validation(t!("functions.userFunction.incorrectOutputType", name = name, expected_type = "int").to_string()));
7070
}
7171
},
7272
DataType::Bool => {
7373
if !output.is_boolean() {
74-
return Err(DscError::Validation(t!("functions.userFunction.outputNotBoolean", name = name, expected_type = function_definition.output.r#type.to_string()).to_string()));
74+
return Err(DscError::Validation(t!("functions.userFunction.incorrectOutputType", name = name, expected_type = "bool").to_string()));
7575
}
7676
},
7777
DataType::Array => {
7878
if !output.is_array() {
79-
return Err(DscError::Validation(t!("functions.userFunction.outputNotArray", name = name, expected_type = function_definition.output.r#type.to_string()).to_string()));
79+
return Err(DscError::Validation(t!("functions.userFunction.incorrectOutputType", name = name, expected_type = "array").to_string()));
8080
}
8181
},
8282
DataType::Object | DataType::SecureObject => {
8383
if !output.is_object() {
84-
return Err(DscError::Validation(t!("functions.userFunction.outputNotObject", name = name, expected_type = function_definition.output.r#type.to_string()).to_string()));
84+
return Err(DscError::Validation(t!("functions.userFunction.incorrectOutputType", name = name, expected_type = "object").to_string()));
8585
}
8686
},
8787
}

0 commit comments

Comments
 (0)