microsoft / StoreBroker

A PowerShell module that leverages the Windows Store Submission API to allow easy automation of application submissions to the Windows Store. The master branch is stable and the v2 branch is under active development.
Other
98 stars 40 forks source link

Check for null values when calling Convert-EnumToString on PSCustomObject #194

Closed joseartrivera closed 4 years ago

joseartrivera commented 4 years ago

Convert-EnumToString iterates over each property and calls itself recursively in order to convert all properties that are enums into strings. In the case of converting PSCustomObjects if the value in the property is $null we would try to pass that $null value recursively to Convert-EnumToString which would throw this exception:

Cannot bind argument to parameter 'InputObject' because it is null.

Now we check for null before doing the recursive call.

joseartrivera commented 4 years ago

Nice catch. An alternate solution would be to add [AllowNull()] on the $InputObject in the params definition, but this works as well.

Something to consider: Line 1240 could also conceivably error out if a hashtable entry has a $null value (because of that $key.ToString() call)... If you're shoring up this function for possible $null values, you should probably guard there too.

Good catch and good idea, I like your approach better since it covers both cases.