@@ -17,12 +17,15 @@ param(
1717# Import MCP Nexus helper module
1818Import-Module " $PSScriptRoot \..\modules\McpNexusExtensions.psm1" - Force
1919
20- Write-NexusProgress " Starting stack analysis with source download for thread $ThreadId "
20+ # Display user-friendly thread description
21+ $threadDisplay = if ($ThreadId -eq " ." ) { " current thread" } else { " thread $ThreadId " }
22+
23+ Write-NexusProgress " Starting stack analysis with source download for $threadDisplay "
2124Write-NexusLog " Starting stack_with_sources extension for thread: $ThreadId " - Level Information
2225
2326try {
2427 # Step 1: Get stack with line numbers
25- Write-NexusProgress " Retrieving stack trace for thread $ThreadId ..."
28+ Write-NexusProgress " Retrieving stack trace for $threadDisplay ..."
2629 $stackCommand = if ($ThreadId -eq " ." ) { " kL" } else { " ~${ThreadId} kL" }
2730 $stackOutput = Invoke-NexusCommand $stackCommand
2831
3235 exit 1
3336 }
3437
38+ # Step 1.5: Validate that the thread exists (check for common error patterns)
39+ if ($stackOutput -match " Invalid thread" -or
40+ $stackOutput -match " Illegal thread" -or
41+ $stackOutput -match " Thread not found" -or
42+ $stackOutput -match " \^ .*error" -or
43+ $stackOutput -match " Couldn't resolve error" ) {
44+
45+ Write-NexusLog " [$threadDisplay ] Thread not found or invalid (ThreadId: $ThreadId )" - Level Error
46+ Write-Error " [$threadDisplay ] not found or invalid"
47+
48+ $result = @ {
49+ success = $false
50+ threadId = $ThreadId
51+ totalFrames = 0
52+ sourcesDownloaded = 0
53+ addresses = @ ()
54+ error = " Thread '$ThreadId ' not found. The thread ID may be invalid or the thread may not exist in this dump file."
55+ suggestion = " Use the '!threads' or '~' command to list available threads, then try again with a valid thread ID."
56+ } | ConvertTo-Json
57+ Write-Output $result
58+ exit 0
59+ }
60+
3561 Write-NexusProgress " Stack trace retrieved successfully"
3662
3763 # Step 2: Parse stack to extract return addresses (middle column)
78104 foreach ($addr in $addresses ) {
79105 $processedCount ++
80106 $percent = [int ](($processedCount / $addresses.Count ) * 100 )
81- Write-NexusProgress " Downloading source for address $addr ($processedCount of $ ( $addresses.Count ) , $percent %)"
107+ Write-NexusProgress " [ $threadDisplay ] Downloading source for address $addr ($processedCount of $ ( $addresses.Count ) , $percent %)"
82108
83109 try {
84110 $lsaOutput = Invoke-NexusCommand " lsa $addr "
@@ -97,10 +123,10 @@ try {
97123 }
98124 }
99125
100- Write-NexusProgress " Source download complete: $downloadedCount of $ ( $addresses.Count ) sources downloaded"
126+ Write-NexusProgress " [ $threadDisplay ] Source download complete: $downloadedCount of $ ( $addresses.Count ) sources downloaded"
101127
102128 $successRate = [math ]::Round(($downloadedCount / $addresses.Count ) * 100 , 2 )
103- Write-NexusLog " Source download completed: $downloadedCount /$ ( $addresses.Count ) sources ($successRate % success rate)" - Level Information
129+ Write-NexusLog " [ $threadDisplay ] Source download completed: $downloadedCount /$ ( $addresses.Count ) sources ($successRate % success rate)" - Level Information
104130
105131 if ($failedAddresses.Count -gt 0 ) {
106132 Write-NexusLog " Failed to download sources for $ ( $failedAddresses.Count ) addresses" - Level Warning
0 commit comments