From fe09fa65333da4434cdef446587aeb7b37ad6ac7 Mon Sep 17 00:00:00 2001 From: Brian Ingles Date: Thu, 28 Mar 2024 16:14:42 -0500 Subject: [PATCH] useGetItemIndexByValue error handling (#1889) --- .../src/useGetItemIndexByValue.test.ts | 16 ++++++++++++++++ .../src/useGetItemIndexByValue.ts | 13 ++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/packages/jsapi-components/src/useGetItemIndexByValue.test.ts b/packages/jsapi-components/src/useGetItemIndexByValue.test.ts index 8bbb81d22f..3e0deec62f 100644 --- a/packages/jsapi-components/src/useGetItemIndexByValue.test.ts +++ b/packages/jsapi-components/src/useGetItemIndexByValue.test.ts @@ -54,6 +54,22 @@ describe('useGetItemIndexByValue', () => { } ); + it('should return null if seekRow fails', async () => { + asMock(mockTable.seekRow).mockRejectedValue('Some error'); + + const { result } = renderHook(() => + useGetItemIndexByValue({ + columnName: 'mock.columnName', + table: mockTable, + value: 'mock.value', + }) + ); + + const actual = await result.current(); + + expect(actual).toBeNull(); + }); + it.each([ ['mock.value', 42, 42], ['mock.value', -1, null], diff --git a/packages/jsapi-components/src/useGetItemIndexByValue.ts b/packages/jsapi-components/src/useGetItemIndexByValue.ts index c1e91556af..6d38ec5d2e 100644 --- a/packages/jsapi-components/src/useGetItemIndexByValue.ts +++ b/packages/jsapi-components/src/useGetItemIndexByValue.ts @@ -1,7 +1,10 @@ import { useCallback } from 'react'; import { dh } from '@deephaven/jsapi-types'; +import Log from '@deephaven/log'; import { useTableUtils } from './useTableUtils'; +const log = Log.module('useGetItemIndexByValue'); + /** * Returns a function that gets the index of the first row containing a column * value. @@ -30,9 +33,13 @@ export function useGetItemIndexByValue({ const column = table.findColumn(columnName); const columnValueType = tableUtils.getValueType(column.type); - const index = await table.seekRow(0, column, columnValueType, value); - - return index === -1 ? null : index; + try { + const index = await table.seekRow(0, column, columnValueType, value); + return index === -1 ? null : index; + } catch (err) { + log.debug('Error seeking row', { column, value, columnValueType }); + return null; + } }, [columnName, table, tableUtils, value]); }