Skip to content

Commit 41468a7

Browse files
committed
refactor: return undefined instead of throwing an exception from getRow()
1 parent 57a4bb1 commit 41468a7

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

libs/execution/src/lib/debugging/debug-log-visitor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import { type Table } from '../types/io-types/table';
2020
import { findLineBounds } from '../util/string-util';
2121

2222
import { type DebugGranularity } from './debug-configuration';
23+
// eslint-disable-next-line unicorn/prefer-node-protocol
24+
import assert from 'assert';
2325

2426
export class DebugLogVisitor implements IoTypeVisitor<void> {
2527
private readonly PEEK_NUMBER_OF_WORKBOOKS = 5;
@@ -57,6 +59,7 @@ export class DebugLogVisitor implements IoTypeVisitor<void> {
5759
}
5860

5961
const row = table.getRow(i);
62+
assert(row !== undefined);
6063
const rowData = [...row.values()]
6164
.map((cell) => {
6265
if (ERROR_TYPEGUARD(cell)) {

libs/execution/src/lib/types/io-types/table.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// SPDX-License-Identifier: AGPL-3.0-only
44

55
// eslint-disable-next-line unicorn/prefer-node-protocol
6-
import { strict as assert } from 'assert';
6+
import assert from 'assert';
77

88
import {
99
ERROR_TYPEGUARD,
@@ -126,12 +126,10 @@ export class Table implements IOTypeImplementation<IOType.TABLE> {
126126
return this.columns.get(name);
127127
}
128128

129-
getRow(rowId: number): TableRow {
129+
getRow(rowId: number): TableRow | undefined {
130130
const numberOfRows = this.getNumberOfRows();
131131
if (rowId >= numberOfRows) {
132-
throw new Error(
133-
`Trying to access table row ${rowId} (of ${numberOfRows} rows)`,
134-
);
132+
return undefined;
135133
}
136134

137135
const row = new Map<
@@ -163,6 +161,7 @@ export class Table implements IOTypeImplementation<IOType.TABLE> {
163161
): void {
164162
for (let rowIdx = 0; rowIdx < this.numberOfRows; rowIdx++) {
165163
const row = this.getRow(rowIdx);
164+
assert(row !== undefined);
166165

167166
for (const constraint of this.constraints) {
168167
if (constraint.isValid(row, executionContext)) {

0 commit comments

Comments
 (0)