Skip to content

Get-ConciseViewPositionMessage throws ArgumentOutOfRangeException in some cases #11976

Closed

Description

Steps to reproduce

  1. Create a C:\temp\repro.ps1 file with the following content:
$global:ErrorView = 'ConciseView' # NormalView and CategoryView work as expected

# Bug happens when the path is >= 128 characters long.
# Shorten path to < 128 characters and it works as expected.
Resolve-Path -LiteralPath 'C:\really\long\path\that\does\not\exist\but\is\exactly\128\characters\long\and\breaks\the\world\which\is\not\great.oops.2bad.exe'
  1. Open a PowerShell 7 RC3 prompt
  2. Run this command c:\temp\repro.ps1

Expected behavior

Concise error view should be shown:

Resolve-Path: C:\temp\repro.ps1:5
Line |
   5 |  Resolve-Path -LiteralPath 'C:\really\long\path\that\does\not\exist\bu …
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot find path
     | 'C:\really\long\path\that\does\not\exist\but\i\exactly\128\characters\long\and\breaks\the\world\which\is\not\great.oops.2bad.exe'
     | because it does not exist.

Actual behavior

  • No error is written to the host.
  • $? = True
  • Get-Error returns information about an exception thrown by Get-ConciseViewPositionMessage.
Exception             :
    Type           : System.Management.Automation.MethodInvocationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : ArgumentOutOfRangeException
        InvocationInfo        :
            ScriptLineNumber : 171
            OffsetInLine     : 53
            HistoryId        : -1
            Line             : $remainingMessage = $remainingMessage.Substring($substring.Length - $prefix.Length).Trim()

            PositionMessage  : At line:171 char:53
                               + …             $remainingMessage = $remainingMessage.Substring($substrin …
                               +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at Get-ConciseViewPositionMessage, <No file>: line 171
                                at <ScriptBlock>, <No file>: line 227
                                at <ScriptBlock>, C:\temp\repro.ps1: line 5
                                at <ScriptBlock>, <No file>: line 1
    TargetSite     :
        Name          : CheckActionPreference
        DeclaringType : System.Management.Automation.ExceptionHandlingOps, System.Management.Automation, Version=7.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    StackTrace     :
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   at System.Management.Automation.ScriptBlock.InvokeWithPipeImpl(ScriptBlockClauseToInvoke clauseToInvoke, Boolean createLocalScope,
Dictionary`2 functionsToDefine, List`1 variablesToDefine, ErrorHandlingBehavior errorHandlingBehavior, Object dollarUnder, Object input, Object
scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Object[] args)
   at System.Management.Automation.ScriptBlock.InvokeWithPipe(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object
dollarUnder, Object input, Object scriptThis, Pipe outputPipe, InvocationInfo invocationInfo, Boolean propagateAllExceptionsToTop, List`1
variablesToDefine, Dictionary`2 functionsToDefine, Object[] args)
   at System.Management.Automation.ScriptBlock.DoInvokeReturnAsIs(Boolean useLocalScope, ErrorHandlingBehavior errorHandlingBehavior, Object
dollarUnder, Object input, Object scriptThis, Object[] args)
   at Microsoft.PowerShell.Commands.PSPropertyExpression.GetValue(PSObject target, Boolean eatExceptions)
    Message        : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. (Parameter 'startIndex')"
    Data           : System.Collections.ListDictionaryInternal
    InnerException :
        Type       : System.ArgumentOutOfRangeException
        Message    : StartIndex cannot be less than zero. (Parameter 'startIndex')
        ParamName  : startIndex
        TargetSite :
            Name          : Substring
            DeclaringType : string
            MemberType    : Method
            Module        : System.Private.CoreLib.dll
        StackTrace :
   at System.String.Substring(Int32 startIndex, Int32 length)
   at CallSite.Target(Closure , CallSite , Object , Object )
        Source     : System.Private.CoreLib
        HResult    : -2146233086
    Source         : System.Management.Automation
    HResult        : -2146233087
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : ArgumentOutOfRangeException
InvocationInfo        :
    ScriptLineNumber : 171
    OffsetInLine     : 53
    HistoryId        : -1
    Line             : $remainingMessage = $remainingMessage.Substring($substring.Length - $prefix.Length).Trim()

    PositionMessage  : At line:171 char:53
                       + …             $remainingMessage = $remainingMessage.Substring($substrin …
                       +               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at Get-ConciseViewPositionMessage, <No file>: line 171
                        at <ScriptBlock>, <No file>: line 227
                        at <ScriptBlock>, C:\temp\repro.ps1: line 5
                        at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-rc.3
PSEdition                      Core
GitCommitId                    7.0.0-rc.3
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Feb 28, 2020
  2. jpoehls commented on Feb 28, 2020

    @jpoehls
    Author

    Assuming this isn't something unique to my environment, this is a critical issue since the concise error view is the new default and this bug results on errors not being shown to users in some cases.

  3. iSazonov commented on Feb 28, 2020

    @iSazonov
    Collaborator

    Perhaps it was fixed in #11941 /cc Steve Lee (@SteveL-MSFT)

  4. added
    WG-Engine
    on Feb 28, 2020
  5. SteveL-MSFT commented on Feb 28, 2020

    @SteveL-MSFT
    Member

    This is already fixed via #11880, we should consider it for 7.0.1

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

Metadata

Metadata

Labels

Issue-QuestionResolution-FixedWG-Engine

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions