Skip to content

Commit 2b08000

Browse files
fix: DGET multiple-match check takes priority over field CellError
The defensive CellError guard added earlier returned the error as soon as a matching row with a field error was seen, even when more rows also matched. Excel's DGET resolves the "multiple matches → #NUM!" check first and only surfaces field errors when exactly one record matches. Move the CellError check to after the loop so the match count is finalised first. Addresses Cursor Bugbot finding. Regression tests added in hyperformula-tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b7a15f2 commit 2b08000

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/interpreter/plugin/DatabasePlugin.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,22 @@ export class DatabasePlugin extends FunctionPlugin implements FunctionPluginType
237237

238238
for (let rowIdx = 1; rowIdx < dbData.length; rowIdx++) {
239239
if (this.rowMatchesCriteria(dbData[rowIdx], criteriaRows)) {
240-
const cellValue = dbData[rowIdx][fieldIndex]
241-
if (cellValue instanceof CellError) {
242-
return cellValue
243-
}
244240
matchCount++
245241
if (matchCount > 1) {
246242
return new CellError(ErrorType.NUM, ErrorMessage.ValueLarge)
247243
}
248-
matchedValue = cellValue
244+
matchedValue = dbData[rowIdx][fieldIndex]
249245
}
250246
}
251247

252248
if (matchCount === 0) {
253249
return new CellError(ErrorType.VALUE, ErrorMessage.WrongType)
254250
}
255251

252+
if (matchedValue instanceof CellError) {
253+
return matchedValue
254+
}
255+
256256
return matchedValue === EmptyValue || matchedValue === undefined || matchedValue === null
257257
? 0
258258
: matchedValue

0 commit comments

Comments
 (0)