PowerShell / PowerShell/PowerShell

`exit` does not return ExitCode when using #Requires -Module <ScriptModule>

Open
#23,887 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Needs-Triage
Dominant language
C#
Stars
55.5k
Forks
8.5k
Avg merge
1d 2h
Merged PRs (30d)
88

Description

Prerequisites
Steps to reproduce
Setup

Test.ps1:

#Requires -Modules TestModule
exit 42

TestModule/TestModule.psm1:

. $PSScriptRoot/ModuleScript.ps1

TestModule/ModuleScript.ps1:

#Empty
Environment Variables

The PSModulePath variable must be set to the current directory, so that TestModule can be found by #requires

$env:PSModulePath = $PWD
Run

pwsh Test.ps1

Expected behavior
Exit code: 42
Actual behavior
Exit code: 0
Error details

No response

Environment data
Found on:
Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Repro'd on latest HEAD:
Name                           Value
----                           -----
PSVersion                      7.5.0-preview.3
PSEdition                      Core
GitCommitId                    7.5.0-preview.3-23-g7f99fa1bf3ecbb4a16e70c90e6736f584df19ef9
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with Test.ps1, TestModule/TestModule.psm1, and TestModule/ModuleScript.ps1 using the stated PSModulePath setup. Then locate the implementation and tests for #Requires -Module and exit handling, add coverage for the expected exit code 42, and verify that the command no longer returns 0.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.