MacAddress parameter validation requires Try-Catch on calling script #1
Labels
No Label
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No Milestone
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: asif/ps-cmdlet-wol#1
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently,
MacAddress
is checked using PowerShell integrated parameter validation against a RegEx. This requires any calling script to wrap calls to this function in Try...Catch blocks in case an invalid MAC address is passed.DETAIL: Parameter validation is run by the command processor before Get-Process invocation. Validation failures throw a ParmeterBindingValidationException. This cannot be handled by
-ErrorAction
and does not register in-ErrorVariable
because the process (Get-Process) does not even start! As such, only Try...Catch can handle this error. There is nothing wrong with this but it is not intuitive and makes calling the function awkward. Hence, this is an enchancement, not really a bug.SOLUTION: Move validation before MAC address processing within the script itself and out of the param block. Register errors with Write-Error and skip further processing. This will allow the calling script to handle errors as desired via
-ErrorAction
and will register with-ErrorVariable
.Closed by
d5c3c071cd