Closed tpcarman closed 1 year ago
I can confirm this behavior. It also exists with the HTML
format:
Scripts> .\Test.ps1
Index was outside the bounds of the array.
At line:95 char:25
+ ... $newPScriboFormattedTableRowValueCellParams['Width'] = $T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException
Index was outside the bounds of the array.
At line:95 char:25
+ ... $newPScriboFormattedTableRowValueCellParams['Width'] = $T ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], IndexOutOfRangeException
+ FullyQualifiedErrorId : System.IndexOutOfRangeException
Some more digging and this is the line of code dropping the error. As you'd expect both Word
& Html
plugins leverage this function.
I'll debug some more to determine the root cause.
@tpcarman Please check out #125 as I've added logic to avoid this error and generate a warning:
The root cause of this issue was the ColumnWidths
count not matching the number of columns in the table.
For example, here's the code you shared:
Table -Hashtable $hashtableArray -List -Key 'Column 1' -ColumnWidths 20, 40, 40
Here we see 3 ColumnWidths values (20, 40, 40
). However, as this is a List
with a Key
specified, the Key
adds an additional column so 4 ColumnWidths values are required. We can confirm this by removing the ColumnWidths altogether and we see:
As @carceneaux pointed out, you need to add an additional column width to the array to account for the additional column. I have an updated warning in some code waiting to be pushed (I think @carceneaux might also have addressed this in an outstanding PR).
Thanks @carceneaux and @iainbrighton for looking into this for me. Glad to see some improvements in the error handling will be added in future updates.
The following code will cause the error
Index was outside the bounds of the array
when exporting a document in Word format. The error occurs when using theColumnWidths
parameter.Exporting to HTML and Text formats does not generate the error.
This issue has been tested and confirmed using PScribo versions 0.9.1 & 0.10.0.