OK, two things:
1 - Why should I have to design extra logic to properly throw/catch an error in a function built into the Syncro platform? I’m saying that the Set-Asset-Field function in the Syncro module will not trigger a try/catch block correctly (EDIT: In case of an error 429, for example). as an example I did something like this:
try{
Set-Asset-Field -Name "TestField" -Value "TestValue"
Write-Host "If you're seeing this, setting the asset field was successful."
}catch{
Write-Host "Setting the asset field failed."
exit 1
}
That script would be listed as successful in the Syncro console and give me output like this (EDIT: If the API write failed due to the rate limit):
error> System.Net.WebException: The remote server returned an error: (429) Too Many Requests.
error> HTTP Status: 429 '429'
error> Content-Type: ''
error> Stack:
error> at Invoke-WebRequest20, C:\ProgramData\Syncro\bin\module.psm1: line 341
error> at Call-Api, C:\ProgramData\Syncro\bin\module.psm1: line 268
error> at Call-SyncroApi, C:\ProgramData\Syncro\bin\module.psm1: line 249
error> at Set-Asset-Field, C:\ProgramData\Syncro\bin\module.psm1: line 150
error> at <ScriptBlock>, C:\ProgramData\Syncro\bin\afe37143-4e00-4213-b557-7c405ec29b32.ps1: line 67
error> at <ScriptBlock>, <No file>: line 1
error> at <ScriptBlock>, <No file>: line 1
error> Call-SyncroApi: failure
If you're seeing this, setting the asset field was successful.
The catch block wouldn’t trigger despite the error, because the Handle-WebException function in the Syncro PS module isn’t written in a way that throws an error if you get a 429 or other similar web exception. It only writes the error contents to the display and then just keeps going as if nothing happened. That’s why I had to write a function to wrap around it just to read the contents of the $Error variable for a 429 so that I could handle it properly.
2 - I’ve attempted to test a script with $FailThisScript. I have it declared as a runtime variable in a test script, but when I attempt to just write it to the transcript it’s blank. I followed the example here:
https://community.syncromsp.com/t/scripts-report-success-even-when-the-output-is-error/3686/7
Here’s a screenshot of my test:
And here’s the result:
The date and time is:
Call-SyncroApi: success
FailThisScript value:
I’m attempting to call a non-existent variable, write to a non-existent custom asset field, and am explicitly throwing an error in that try/catch block, but FailThisScript doesn’t show a value.