Skip to content

Commit 77d15b2

Browse files
ehennestadCopilot
andauthored
Improve error message in types.util.dynamictable.checkConfig on invalid shape (#803)
* Update checkConfig.m * Update checkConfig.m * Refactor checkConfig: build error message only on error path Agent-Logs-Url: https://github.com/NeurodataWithoutBorders/matnwb/sessions/99200b8a-18aa-462d-8ab7-5c814819a7d5 Co-authored-by: ehennestad <17237719+ehennestad@users.noreply.github.com> * Revert "Refactor checkConfig: build error message only on error path" This reverts commit eedc96f. * Update checkConfig.m Add extra guard for empty columns in check * Update run_tests.yml --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ehennestad <17237719+ehennestad@users.noreply.github.com>
1 parent bf9a79d commit 77d15b2

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

+types/+util/+dynamictable/checkConfig.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ function checkConfig(DynamicTable, ignoreList)
3131
% do not check specified columns - useful for classes that build on DynamicTable class
3232
columns = setdiff(DynamicTable.colnames, ignoreList);
3333

34+
if isempty(columns)
35+
return
36+
end
37+
3438
columnHeights = zeros(length(columns), 1);
39+
columnNames = strings(length(columns), 1);
3540
for iCol = 1:length(columns)
3641
columnName = retrieveHighestIndex(DynamicTable, columns{iCol});
3742
columnHeight = unique(types.util.dynamictable.getColumnHeight(getVector(DynamicTable, columnName)));
@@ -40,16 +45,20 @@ function checkConfig(DynamicTable, ignoreList)
4045
'NWB:DynamicTable:CheckConfig:InvalidShape', ...
4146
'Invalid compound column detected: compound column heights must all be the same.');
4247
columnHeights(iCol) = columnHeight;
48+
columnNames(iCol) = columnName;
4349
end
4450

4551
tableHeight = unique(columnHeights);
4652
if isempty(tableHeight)
4753
tableHeight = 0;
4854
end
55+
56+
formatSpec = sprintf(' %%-%ds %%d', max(strlength(columnNames)));
4957
assert(isscalar(tableHeight), ...
5058
'NWB:DynamicTable:CheckConfig:InvalidShape', ...
51-
['Invalid table detected: ' ...
52-
'column heights (vector lengths or number of matrix columns) must be the same.']);
59+
['Invalid table: all columns must have the same height (number of rows).\n\n' ...
60+
'Detected column heights:\n' ...
61+
strjoin( compose(formatSpec, columnNames, columnHeights), newline) ]);
5362

5463
if isempty(DynamicTable.id)
5564
types.util.dynamictable.internal.initDynamicTableId(DynamicTable, tableHeight);

0 commit comments

Comments
 (0)