PowerShell / PowerShell/PowerShell

Error starting PowerShell 7.4.0+

Open
#20,706 18 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Prerequisites
Steps to reproduce
  1. Install PowerShell 7.4.0
  2. Start it
  3. Create a powershell.config.json and set PSModulePath to multiple paths, separated by ; (path separator char) (see reference).
  4. See it fail
Expected behavior

It starts, like 7.3 did.

Actual behavior

It fails with:

PowerShell 7.4.0
The shell cannot be started. A failure occurred during initialization:
Index was out of range. Must be non-negative and less than or equal to the size of the collection. (Parameter 'startIndex')
Error details

Not possible.

Environment data

Not possible, but it is version 7.4.0.

Visuals

This is starting from Nushell:

from nu

This is starting it from Windows Terminal:

from wt

Additional context

Downloaded and installed this file: https://github.com/PowerShell/PowerShell/releases/download/v7.4.0/PowerShell-7.4.0-win-x64.msi

I debugged and found out that the exception is ocurring at this location (ModuleIntrinsics.UpdatePath):
https://github.com/PowerShell/PowerShell/blob/ad2bf787e4e7dfde9123a67349cf1ae6ccdfc984/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs#L1278

The arguments for UpdatePath are:
path: a string with a ; separated list of paths
pathToAdd: another string with a ; separated list of paths
insertIndex: 0

The call that is failing is the one to path.IndexOf, which is passed ; and -1 (which is the result from the call to PathContainsSubstring).

The problem only happens because pathToAdd has several paths with the ; separator. If it was a single path without ; it would work.

The issue seems to have been introduced in commit 3710671c16de9bcbd945389a22a88b994cd02bcd.

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

Start in src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs at ModuleIntrinsics.UpdatePath, focusing on the path.IndexOf call described in the issue. Reproduce the failure with a powershell.config.json whose PSModulePath contains multiple semicolon-separated paths, then verify that PowerShell 7.4 starts successfully with that configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.