Skip to content

Commit 9d18828

Browse files
committed
add further type checks to catching errors, and then immediately ts-ignore the issues.add because thats poorly typed. Update Deno.run to Deno.Command. Removes stubfile validators/isBidsy.ts.
1 parent 80b2789 commit 9d18828

File tree

10 files changed

+20
-29
lines changed

10 files changed

+20
-29
lines changed

bids-validator/deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@bids/schema": "jsr:@bids/[email protected]+d9c23eb0",
3232
"@cliffy/command": "jsr:@cliffy/[email protected]",
3333
"@cliffy/table": "jsr:@cliffy/[email protected]",
34-
"@hed/validator": "npm:[email protected].4",
34+
"@hed/validator": "npm:[email protected].5",
3535
"@ignore": "npm:[email protected]",
3636
"@libs/xml": "jsr:@libs/[email protected]",
3737
"@mango/nifti": "npm:[email protected]",

bids-validator/src/files/browser.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { assertEquals, assertObjectMatch } from '@std/assert'
44
import { BIDSFileBrowser, fileListToTree } from './browser.ts'
55

66
class TestFile extends File {
7-
webkitRelativePath: string
7+
override webkitRelativePath: string
88
constructor(
99
fileBits: BlobPart[],
1010
fileName: string,

bids-validator/src/files/deno.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class BIDSFileDeno implements BIDSFile {
3838
try {
3939
this.#fileInfo = Deno.statSync(this._getPath())
4040
} catch (error) {
41-
if (error.code === 'ENOENT') {
41+
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
4242
this.#fileInfo = Deno.lstatSync(this._getPath())
4343
}
4444
}
@@ -158,7 +158,7 @@ export async function readFileTree(rootPath: string): Promise<FileTree> {
158158
)
159159
ignore.add(await readBidsIgnore(ignoreFile))
160160
} catch (err) {
161-
if (!Object.hasOwn(err, 'code') || err.code !== 'ENOENT') {
161+
if (err && typeof err === 'object' && !('code' in err && err.code !== 'ENOENT')) {
162162
logger.error(`Failed to read '.bidsignore' file with the following error:\n${err}`)
163163
}
164164
}

bids-validator/src/files/inheritance.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assertEquals, assertThrows } from '@std/assert'
1+
import { assert, assertEquals, assertThrows } from '@std/assert'
22
import { pathsToTree } from './filetree.ts'
33
import { walkBack } from './inheritance.ts'
44

@@ -17,6 +17,9 @@ Deno.test('walkback inheritance tests', async (t) => {
1717
continue
1818
}
1919
} catch (error) {
20+
assert(error)
21+
assert(typeof error === 'object')
22+
assert('code' in error)
2023
assertEquals(error.code, 'MULTIPLE_INHERITABLE_FILES')
2124
throw error
2225
}

bids-validator/src/schema/associations.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ export async function buildAssociations(
163163
try {
164164
file = walkBack(source, inherit, extensions, suffix).next().value
165165
} catch (error) {
166-
if (error.code === 'MULTIPLE_INHERITABLE_FILES') {
166+
if (error && typeof error === 'object' && 'code' in error && error.code === 'MULTIPLE_INHERITABLE_FILES') {
167+
// @ts-expect-error
167168
issues.add(error)
168169
break
169170
} else {

bids-validator/src/schema/context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ export class BIDSContext implements Context {
184184
try {
185185
sidecars = [...walkBack(this.file)]
186186
} catch (error) {
187-
if (error.code === 'MULTIPLE_INHERITABLE_FILES') {
187+
if (error && typeof error === 'object' && 'code' in error && error.code === 'MULTIPLE_INHERITABLE_FILES') {
188+
// @ts-expect-error
188189
this.dataset.issues.add(error)
189190
} else {
190191
throw error

bids-validator/src/utils/errors.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export class SchemaStructureError extends Error {
2-
constructor(schemaPath) {
2+
schemaPath: string
3+
constructor(schemaPath: string) {
34
super(`Validator attempted to access ${schemaPath}, but it wasn't there.`)
45
this.name = 'SchemaStructureError'
56
this.schemaPath = schemaPath

bids-validator/src/validators/hed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function hedValidate(
8080
context.dataset.issues.add({
8181
code: 'HED_ERROR',
8282
location: context.path,
83-
issueMessage: error,
83+
issueMessage: error as string,
8484
})
8585
}
8686

bids-validator/src/validators/isBidsy.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

bids-validator/src/version.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ export async function getVersion(): Promise<string> {
3232
}
3333

3434
async function getLocalVersion(path: string): Promise<string> {
35-
const p = Deno.run({
36-
// safe.directory setting so we could still operate from another user
37-
cmd: ['git', '-C', path, '-c', 'safe.directory=*', 'describe', '--tags', '--always'],
38-
stdout: 'piped',
35+
// safe.directory setting so we could still operate from another user
36+
const command = new Deno.Command("git", {
37+
args: ['git', '-C', path, '-c', 'safe.directory=*', 'describe', '--tags', '--always'],
3938
})
40-
const description = new TextDecoder().decode(await p.output()).trim()
41-
p.close()
39+
const { success, stdout } = await command.output();
40+
const description = new TextDecoder().decode(stdout).trim()
4241
return description
4342
}
4443

0 commit comments

Comments
 (0)