Skip to content

Commit

Permalink
use logger on bidsignore failure. update logger warning to warn, deno…
Browse files Browse the repository at this point in the history
  • Loading branch information
rwblair committed Oct 9, 2024
1 parent bc01649 commit 2052938
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
6 changes: 5 additions & 1 deletion bids-validator/src/files/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ export async function fileListToTree(files: File[]): Promise<FileTree> {
const tree = filesToTree(files.map((f) => new BIDSFileBrowser(f, ignore, root)))
const bidsignore = tree.get('.bidsignore')
if (bidsignore) {
ignore.add(await readBidsIgnore(bidsignore as BIDSFile))
try {
ignore.add(await readBidsIgnore(bidsignore as BIDSFile))
} catch(err) {
console.log(`Failed to read '.bidsignore' file with the following error:\n${err}`)
}

Check warning on line 62 in bids-validator/src/files/browser.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/files/browser.ts#L61-L62

Added lines #L61 - L62 were not covered by tests
}
return tree
}
5 changes: 3 additions & 2 deletions bids-validator/src/files/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as posix from '@std/path/posix'
import { type BIDSFile, FileTree } from '../types/filetree.ts'
import { requestReadPermission } from '../setup/requestPermissions.ts'
import { FileIgnoreRules, readBidsIgnore } from './ignore.ts'
import { logger } from '../utils/logger.ts'

/**
* Thrown when a text file is decoded as UTF-8 but contains UTF-16 characters
Expand Down Expand Up @@ -157,8 +158,8 @@ export async function readFileTree(rootPath: string): Promise<FileTree> {
)
ignore.add(await readBidsIgnore(ignoreFile))
} catch (err) {
if (!(Object.hasOwn(err, 'code') && err.code === "ENOENT")) {
throw err
if (!Object.hasOwn(err, 'code') || err.code !== "ENOENT") {
logger.error(`Failed to read '.bidsignore' file with the following error:\n${err}`)
}

Check warning on line 163 in bids-validator/src/files/deno.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/files/deno.ts#L162-L163

Added lines #L162 - L163 were not covered by tests
}
return _readFileTree(rootPath, '/', ignore)
Expand Down
2 changes: 1 addition & 1 deletion bids-validator/src/schema/applyRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function evalJsonCheck(
}

if (sidecarRule && !(keyName in context.sidecarKeyOrigin)) {
logger.warning(
logger.warn(

Check warning on line 224 in bids-validator/src/schema/applyRules.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/schema/applyRules.ts#L224

Added line #L224 was not covered by tests
`sidecarKeyOrigin map failed to initialize for ${context.path} on key ${keyName}. Validation caching not active for this key.`,
)
}
Expand Down
2 changes: 1 addition & 1 deletion bids-validator/src/schema/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class BIDSContext implements Context {
if (error.key) {
this.dataset.issues.add({ code: error.key, location: this.file.path })
}
logger.warning(
logger.warn(

Check warning on line 228 in bids-validator/src/schema/context.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/schema/context.ts#L228

Added line #L228 was not covered by tests
`tsv file could not be opened by loadColumns '${this.file.path}'`,
)
logger.debug(error)
Expand Down
4 changes: 2 additions & 2 deletions bids-validator/src/validators/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const compile = memoize(metadataValidator.compile.bind(metadataValidator)

export function setCustomMetadataFormats(schema: Schema): void {
if (typeof schema.objects.formats !== 'object') {
logger.warning(
logger.warn(

Check warning on line 13 in bids-validator/src/validators/json.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/validators/json.ts#L13

Added line #L13 was not covered by tests
`schema.objects.formats missing from schema, format validation disabled.`,
)
return
Expand All @@ -19,7 +19,7 @@ export function setCustomMetadataFormats(schema: Schema): void {
for (const key of Object.keys(schemaFormats)) {
const pattern = schemaFormats[key]['pattern']
if (typeof pattern !== 'string') {
logger.warning(
logger.warn(

Check warning on line 22 in bids-validator/src/validators/json.ts

View check run for this annotation

Codecov / codecov/patch

bids-validator/src/validators/json.ts#L22

Added line #L22 was not covered by tests
`schema.objects.formats.${key} pattern missing or invalid. Skipping this format for addition to context json validator`,
)
continue
Expand Down

0 comments on commit 2052938

Please sign in to comment.