SAM Template will catch all potential errors and redirect them to Orion Output.
All breaks (enters) will be removed, in order to display one long string. This is necessary, as SAM does not allow breaks in output.
You can use this to implement in your script, in order to troubleshoot what is wrong. Orion does support displaying error messages, however only if the Message/Statistic is properly displayed.
If script would exit before displaying Message/Statistic values (probably due to some error), we would only receive a "Test failed".
And you can include this part of the code in different parts of the script. So this is very useful, especially if we cannot troubleshoot the script locally on the server.
Code from the template:
# Clearing all previous errors (if any)
$error.Clear()
# Trying to cut string that is null, so the error will occur
$x.substring(0,2)
# Count number of errors
$errorsCounter = 0
$error | ForEach {$errorsCounter += 1}
# Saving all errors in one string without breaks (Orion output does not support breaks)
$errors = $($error | Out-String) | ForEach {$_ -replace "`r`n",' '}
# Displaying potential errors in PowerShell
Write-Host "Message.Debug:" $errors
Write-Host "Statistic.Debug: $errorsCounter"
Example:

Take care, Marcin.