Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index was outside the bounds of the array #3

Closed
Erikov-K opened this issue Oct 8, 2020 · 2 comments
Closed

Index was outside the bounds of the array #3

Erikov-K opened this issue Oct 8, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@Erikov-K
Copy link

Erikov-K commented Oct 8, 2020

Hi!

Thank you for script 'ConvertFrom-SourceTable.ps1'
Great work! :-)

In my project I use StrictMode Version 3.0 and I see that function 'ConvertFrom-SourceTable' throw 'Index was outside the bounds of the array' exception.

Simple example below:

PS C:\> Set-StrictMode -Version 2
PS C:\> . .\ConvertFrom-SourceTable.ps1
PS C:\> ConvertFrom-SourceTable '
>> Name   Age
>> ----   ----
>> John   18
>> Sam    22
>> ' -ErrorAction stop

Name Age
---- ---
John 18
Sam  22


PS C:\> Set-StrictMode -Version 3
PS C:\> ConvertFrom-SourceTable '
>> Name   Age
>> ----   ----
>> John   18
>> Sam    22
>> ' -ErrorAction stop
Foreach-Object : Index was outside the bounds of the array.
At C:\ConvertFrom-SourceTable.ps1:377 char:90
+ ... Skip $DataIndex | Where-Object {$_.Trim()} | Foreach-Object {Mask $_}
+                                                  ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [ForEach-Object], IndexOutOfRangeException
    + FullyQualifiedErrorId : System.IndexOutOfRangeException,Microsoft.PowerShell.Commands.ForEachObjectCommand

PS C:\>

@iRon7
Copy link
Owner

iRon7 commented Oct 8, 2020

Thanks for the information, I wasn't even aware that is a new Set-StrictMode -Version 3 😳
I will need to investigate this.

@iRon7 iRon7 added the enhancement New feature or request label Oct 8, 2020
@iRon7 iRon7 self-assigned this Oct 8, 2020
iRon7 added a commit that referenced this issue Oct 8, 2020
Compliant with Set-StrictMode -Version 3
@iRon7
Copy link
Owner

iRon7 commented Oct 8, 2020

Apparently I was implicitly relying on the behavior that an index outside the bounds of the array returns $Null with statements like $Array[$i] -notmatch '\S' (vs. $Array[$i] -match '\s').
Anyways, it should be fixed now in version 0.3.15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants