Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update-IntuneDeviceConfigurationPolicy - Does not throw an exception if an error occurs #5055

Closed
FabienTschanz opened this issue Sep 17, 2024 · 1 comment · Fixed by #5056 or #5132
Closed
Labels
Enhancement New feature or request Intune

Comments

@FabienTschanz
Copy link
Contributor

FabienTschanz commented Sep 17, 2024

Description of the issue

Currently, the cmdlet Update-IntuneDeviceConfigurationPolicy does not throw if an error occurs during execution. Instead, it simply logs the error to the event channel and returns null to the caller.

It currently looks like the following:

try
    {
        Invoke-MgGraphRequest -Method PUT -Uri $Uri -Body $body -ErrorAction Stop
    }
    catch
    {
        New-M365DSCLogEntry -Message 'Error updating data:' `
            -Exception $_ `
            -Source $($MyInvocation.MyCommand.Source) `
            -TenantId $TenantId `
            -Credential $Credential

        return $null
    }

As a consumer of the cmdlet, I would like to know if an error happened and for me, it would be the best if the execution is stopped and the exception is thrown to the higher levels to have them handle the issue. So the updated catch clause should look like the following in my opinion:

catch
    {
        New-M365DSCLogEntry -Message 'Error updating data:' `
            -Exception $_ `
            -Source $($MyInvocation.MyCommand.Source) `
            -TenantId $TenantId `
            -Credential $Credential

        throw
    }

Instead of returning null, I believe it's better if we rethrow the exception to stop the execution flow and let the caller of the cmdlet handle the exception. What do you think?

For visibility: @ricmestre

Microsoft 365 DSC Version

DEV

Which workloads are affected

Intune

The DSC configuration

No response

Verbose logs showing the problem

No response

Environment Information + PowerShell Version

No response

@ricmestre
Copy link
Contributor

I always preferred when code fails fast and hard otherwise it might continue with unforeseen consequences, so yes I'm all for the function to throw an exception instead of returning $null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Intune
Projects
None yet
3 participants