Skip to content

Test Result Analyzer fails if no stack trace is available#2257

Open
FreundDK wants to merge 14 commits into
microsoft:mainfrom
BUNKERHOLDINGBC:TestResultBug
Open

Test Result Analyzer fails if no stack trace is available#2257
FreundDK wants to merge 14 commits into
microsoft:mainfrom
BUNKERHOLDINGBC:TestResultBug

Conversation

@FreundDK
Copy link
Copy Markdown

@FreundDK FreundDK commented May 20, 2026

❔What, Why & How

Fixes #2256

TestResultAnalyzer uses "#Text", which might be null instead of InnerText
This code shows what is wrong with that:

# 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())'"
}

@FreundDK FreundDK requested a review from a team as a code owner May 20, 2026 04:22
Copilot AI review requested due to automatic review settings May 20, 2026 04:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash in the AnalyzeTests action when a <failure> XML element has no stack trace content by switching from the XML "#text" accessor (which can be $null) to InnerText (empty string for empty nodes).

Changes:

  • Replace $failure."#text" with $failure.InnerText when rendering and storing stack traces in GetTestResultSummaryMD.

Comment on lines 193 to +198
Write-Host " - Error: $($failure.message)"
Write-Host " Stacktrace:"
Write-Host " $($failure."#text".Trim().Replace("`n","`n "))"
Write-Host " $($failure.InnerText.Trim().Replace("`n","`n "))"
$testFailureNode = [FailureNode]::new($true)
$testFailureNode.errorMessage = $failure.message
$testFailureNode.errorStackTrace = $($failure."#text".Trim().Replace("`n","<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"))
$testFailureNode.errorStackTrace = $($failure.InnerText.Trim().Replace("`n","<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"))
Copy link
Copy Markdown
Collaborator

@aholstrup1 aholstrup1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Missing a releasenote though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants