Skip to content

Commit 14e7e75

Browse files
committed
rf: Raise more issue-like objects for TSV
1 parent 3d010fa commit 14e7e75

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/files/tsv.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Deno.test('TSV loading', async (t) => {
5353
try {
5454
await loadTSV(file)
5555
} catch (e: any) {
56-
assertObjectMatch(e, { key: 'TSV_EMPTY_LINE', line: 3 })
56+
assertObjectMatch(e, { code: 'TSV_EMPTY_LINE', line: 3 })
5757
}
5858
})
5959

@@ -64,7 +64,7 @@ Deno.test('TSV loading', async (t) => {
6464
try {
6565
await loadTSV(file)
6666
} catch (e: any) {
67-
assertObjectMatch(e, { key: 'TSV_EQUAL_ROWS', line: 3 })
67+
assertObjectMatch(e, { code: 'TSV_EQUAL_ROWS', location: '/mismatched_row.tsv', line: 3 })
6868
}
6969
})
7070

@@ -171,7 +171,7 @@ Deno.test('TSV loading', async (t) => {
171171
await loadTSV(file)
172172
assert(false, 'Expected error')
173173
} catch (e: any) {
174-
assertObjectMatch(e, { key: 'TSV_COLUMN_HEADER_DUPLICATE', evidence: 'a, a' })
174+
assertObjectMatch(e, { code: 'TSV_COLUMN_HEADER_DUPLICATE', issueMessage: 'a, a' })
175175
}
176176
})
177177

src/files/tsv.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ async function _loadTSV(file: BIDSFile, maxRows: number = -1): Promise<ColumnsMa
1919
const headers = (headerRow.done || !headerRow.value) ? [] : headerRow.value.split('\t')
2020

2121
if (new Set(headers).size !== headers.length) {
22-
throw { key: 'TSV_COLUMN_HEADER_DUPLICATE', evidence: headers.join(', ') }
22+
throw {
23+
code: 'TSV_COLUMN_HEADER_DUPLICATE',
24+
location: file.path,
25+
issueMessage: headers.join(', '),
26+
}
2327
}
2428

2529
// Initialize columns in array for construction efficiency
@@ -36,12 +40,12 @@ async function _loadTSV(file: BIDSFile, maxRows: number = -1): Promise<ColumnsMa
3640
if (!value) {
3741
const nextRow = await reader.read()
3842
if (nextRow.done) break
39-
throw { key: 'TSV_EMPTY_LINE', line: rowIndex + 2 }
43+
throw { code: 'TSV_EMPTY_LINE', location: file.path, line: rowIndex + 2 }
4044
}
4145

4246
const values = value.split('\t')
4347
if (values.length !== headers.length) {
44-
throw { key: 'TSV_EQUAL_ROWS', line: rowIndex + 2 }
48+
throw { code: 'TSV_EQUAL_ROWS', location: file.path, line: rowIndex + 2 }
4549
}
4650
columns.forEach((column, columnIndex) => {
4751
// Double array size if we exceed the current capacity

src/schema/context.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ export class BIDSContext implements Context {
248248

249249
this.columns = await loadTSV(this.file, this.dataset.options?.maxRows)
250250
.catch((error) => {
251-
if (error.key) {
252-
this.dataset.issues.add({ code: error.key, location: this.file.path })
251+
if (error.code) {
252+
this.dataset.issues.add({ ...error, location: this.file.path })
253253
}
254254
logger.warn(
255255
`tsv file could not be opened by loadColumns '${this.file.path}'`,

0 commit comments

Comments
 (0)