Skip to content

Improve error message from Start-NativeExecution#26500

Merged
daxian-dbw merged 2 commits into
PowerShell:masterfrom
logiclrd:start-nativeexecution-error-report-cwd
Jan 9, 2026
Merged

Improve error message from Start-NativeExecution#26500
daxian-dbw merged 2 commits into
PowerShell:masterfrom
logiclrd:start-nativeexecution-error-report-cwd

Conversation

@logiclrd
Copy link
Copy Markdown
Contributor

PR Summary

Update the Start-NativeExecution cmdlet that is part of the build infrastructure to report the directory in which the script block was executed, in the event of an error.

PR Context

I ran Start-PSBuild, and it failed with an error during the ResGen phase:

PS /code/PowerShell> Start-PSBuild                                  
VERBOSE: Using default feeds which are Microsoft, use -UseNuGetOrg to switch to Public feeds
WARNING: The 'dotnet' in the current path can't find SDK version 10.0.100, prepending /home/logiclrd/.dotnet to PATH.
VERBOSE: In Find-DotNet
VERBOSE: Executing:  dotnet --list-sdks 
VERBOSE: Find-DotNet: dotnetCLIInstalledVersion = 10.0.100; chosenDotNetVersion = 10.0.100
VERBOSE: Using configuration 'Debug'
VERBOSE: Using framework 'net10.0'
VERBOSE: Using runtime 'linux-x64'
VERBOSE: Top project directory is /code/PowerShell/src/powershell-unix
=== BEGIN: Restore NuGet Packages ===
==== END: Restore NuGet Packages ====
Run ResGen (generating C# bindings for resx files)

The build failed. Fix the build errors and run again.
Exception: /code/PowerShell/tools/buildCommon/startNativeExecution.ps1:42
Line |
  42 |                  throw $errorMessage
     |                  ~~~~~~~~~~~~~~~~~~~
     | Execution of { dotnet run } by build.psm1: line 2666 failed with exit code 1
PS /code/PowerShell> 

This error message told me what went wrong: dotnet run

It told me in general terms what was happening when it went wrong: Run ResGen

But this information alone wasn't enough to diagnose the problem. dotnet run in the root obviously doesn't do anything and isn't connected with the error at all. I had to open up build.psm1 and find out what exactly was on line 2666:

function Start-ResGen
{
    [CmdletBinding()]
    param()

    # Add .NET CLI tools to PATH
    Find-Dotnet

    Push-Location "$PSScriptRoot/src/ResGen"
    try {
        Start-NativeExecution { dotnet run } | Write-Verbose
    } finally {
        Pop-Location
    }
}

Ahh. It's doing it inside ./src/ResGen.

So, this PR updates the error message so that obtaining this context doesn't require peeking into build.psm1 directly:

Exception: /code/PowerShell/tools/buildCommon/startNativeExecution.ps1:42
Line |
  42 |                  throw $errorMessage
     |                  ~~~~~~~~~~~~~~~~~~~
     | Execution of { dotnet run } in '/code/PowerShell/src/ResGen' by build.psm1: line 2666 failed with exit code 1

PR Checklist

… executing the script block and then include it in the error message if one happens.
@logiclrd logiclrd requested review from a team and jshigetomi as code owners November 20, 2025 16:27
Comment thread tools/buildCommon/startNativeExecution.ps1
Comment thread tools/buildCommon/startNativeExecution.ps1 Outdated
@iSazonov iSazonov added the CL-Tools Indicates that a PR should be marked as a tools change in the Change Log label Nov 24, 2025
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Review - Needed The PR is being reviewed label Dec 1, 2025
@microsoft-github-policy-service
Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

Copy link
Copy Markdown
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

LGTM

@daxian-dbw daxian-dbw merged commit 7ace9e0 into PowerShell:master Jan 9, 2026
36 of 37 checks passed
@daxian-dbw daxian-dbw removed the Review - Needed The PR is being reviewed label Jan 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Tools Indicates that a PR should be marked as a tools change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants