Hello,
I would like to discuss with you error handling in custom DSC resources (mainly for classes). I have seen several times similar code:
[void] Set() { try { # Do something } catch { Write-Verbose -Message $_.Exception.Message } }
For example here: xTimeZoneClassSingleInstance/xTimeZone.psm1 at master · TravisEz13/xTimeZoneClassSingleInstance · GitHub
Btw. the code in example will not work because there is (for any reason) $PSCmdlet.ShouldProcess.
I think it is totally wrong to close all code in Set() to try-catch block and then output exception message in verbose stream. Of course there are reasons why to add part of your code that can fail to try-catch and then output the exception in verbose stream. But if you put everything in Set() to try-catch then you have no information that Set() failed (nothing in event log).
I prefer to put
$ErrorActionPreference = 'Stop'
at the beginning of all DSC methods (Get(), Test(), Set()) and then do a proper error handling using try-catch blocks.
What do you think?
Thank you and have and have a nice day
Rudolf