Skip to content

[Bug]: Test Result Analyzer fails if no stack trace is available #2256

@FreundDK

Description

@FreundDK

AL-Go version

Preview (all versions)

Describe the issue

Some times, the Test Results XML file is missing the stack trace, like this:

Image

I cannot repro how the TestResults.xml file without a stack trace ends up being created, but this causes the TestResultsAnalyzer to fail with:

Error: Unexpected error when running action. Error Message: The property '#text' cannot be found on this object. Verify that the property exists., StackTrace: at GetTestResultSummaryMD, C:\a_actions\microsoft\AL-Go\main\Actions\AnalyzeTests\TestResultAnalyzer.ps1: line 195 <- at , C:\a_actions\microsoft\AL-Go\main\Actions\AnalyzeTests\AnalyzeTests.ps1: line 19.....

Expected behavior

No failure when stack trace isn't available

Steps to reproduce

This script shows what is wrong in the code, which uses the PowerShell construct "#Text" to capture the innertext - that construct returns NULL instead of empty string if no innertext is available.

# Demonstrates the bug fixed by this PR:
# ."#text" returns $null on empty XML elements, causing .Trim() to throw.
# .InnerText returns "" instead, handling empty nodes safely.

[xml]$xml = @"
<nodes>
  <node message="1">Content</node>
  <node message="2"></node>
</nodes>
"@

Write-Host -ForegroundColor Yellow "FAILING:"
try {
    foreach ($node in $xml.nodes.node) {
        Write-Host "$($node.message)"
        Write-Host "Content: '$($node."#text".Trim())'"
    }
}
catch {
    Write-Host -ForegroundColor Red "ERROR"
}
Write-Host
Write-Host -ForegroundColor Yellow "WORKING:"
foreach ($node in $xml.nodes.node) {
    Write-Host "$($node.message)"
    Write-Host "Content: '$($node.InnerText.Trim())'"
}

Additional context (logs, screenshots, etc.)

I will submit a PR with a fix in 2 minutes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions