Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/bids/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { buildBidsSchemas } from './schema'
import { BidsJsonFile, BidsSidecar } from './types/json'
import { BidsTsvFile } from './types/tsv'
import { BidsHedIssue, BidsIssue } from './types/issues'
import { BidsHedIssue } from './types/issues'
import BidsHedSidecarValidator from './validator/sidecarValidator'
import BidsHedTsvValidator from './validator/tsvValidator'

export {
BidsTsvFile,
BidsJsonFile,
BidsSidecar,
BidsIssue,
BidsHedIssue,
BidsHedSidecarValidator,
BidsHedTsvValidator,
Expand All @@ -20,7 +19,6 @@ export default {
BidsTsvFile,
BidsJsonFile,
BidsSidecar,
BidsIssue,
BidsHedIssue,
BidsHedSidecarValidator,
BidsHedTsvValidator,
Expand Down
4 changes: 2 additions & 2 deletions src/bids/tsvParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const isContentfulRow = (row) => row && !/^\s*$/.test(row)
* Parse a TSV file.
*
* @param {string} contents The contents of a TSV file.
* @returns {Map} The parsed contents of the TSV file.
* @returns {Map<string, string[]>} The parsed contents of the TSV file.
*/
export function parseTSV(contents) {
const columns = new Map()
Expand All @@ -40,7 +40,7 @@ export function parseTSV(contents) {
* Convert parsed TSV file data from the old BIDS format to the new BIDS format.
*
* @param {{headers: string[], rows: string[][]}} oldParsedTsv Parsed TSV data using the old format
* @returns {Map} The parsed contents of the TSV file, using the new format.
* @returns {Map<string, string[]>} The parsed contents of the TSV file, using the new format.
*/
export function convertParsedTSVData(oldParsedTsv) {
const columns = new Map()
Expand Down
16 changes: 13 additions & 3 deletions src/bids/types/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class BidsFile {

/**
* The Object representing this file data.
* This is used to generate {@link BidsIssue} objects.
* This is used to generate {@link BidsHedIssue} objects.
* @type {Object}
*/

Expand All @@ -40,7 +40,7 @@ export class BidsFile {
* Validate this validator's tsv file.
*
* @param {Schemas} schemas - The HED schemas used to validate this file.
* @returns {BidsIssue[]} - Any issues found during validation of this TSV file.
* @returns {BidsHedIssue[]} - Any issues found during validation of this TSV file.
*/
validate(schemas) {
if (!this.hasHedData) {
Expand All @@ -63,9 +63,19 @@ export class BidsFile {
}
}

/**
* Determine whether this file has any HED data.
*
* @returns {boolean}
*/
get hasHedData() {
return false
}

/**
* The validator class used to validate this file.
* @returns {BidsValidator}
*
* @returns {function} (typeof BidsValidator) A subclass constructor of {@link BidsValidator}.
*/
get validatorClass() {
return this._validatorClass
Expand Down
80 changes: 44 additions & 36 deletions src/bids/types/issues.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { generateIssue, IssueError } from '../../issues/issues'

const bidsHedErrorCodes = new Set([104, 106, 107])
const bidsHedErrorCodes = new Set(['HED_ERROR', 'HED_INTERNAL_ERROR'])

export class BidsIssue {
export class BidsHedIssue {
/**
* The BIDS issue code.
* @type {number}
* @type {string}
*/
code
bidsCode
/**
* The file associated with this issue.
* @type {Object}
Expand All @@ -17,72 +17,80 @@ export class BidsIssue {
* The evidence for this issue.
* @type {string}
*/
evidence
message
/**
* The HED Issue object corresponding to this object.
* @type {Issue}
*/
hedIssue

constructor(issueCode, file, evidence) {
this.code = issueCode
/**
* Constructor.
*
* @param {Issue} hedIssue The HED issue object to be wrapped.
* @param {Object} file The file this error occurred in.
*/
constructor(hedIssue, file) {
this.hedIssue = hedIssue
this.bidsCode = BidsHedIssue._determineBidsIssueCode(hedIssue)
this.message = hedIssue.message
this.file = file
this.evidence = evidence
}

/**
* The HED spec code for this issue.
*
* @returns {string}
*/
get hedCode() {
return this.hedIssue.hedCode
}

/**
* Whether this issue is an error.
*
* @returns {boolean}
*/
isError() {
return bidsHedErrorCodes.has(this.code)
get isError() {
return bidsHedErrorCodes.has(this.bidsCode)
}

/**
* Determine if any of the passed issues are errors.
*
* @param {BidsIssue[]} issues A list of issues.
* @param {BidsHedIssue[]} issues A list of issues.
* @returns {boolean} Whether any of the passed issues are errors (rather than warnings).
*/
static anyAreErrors(issues) {
return issues.some((issue) => issue.isError())
return issues.some((issue) => issue.isError)
}

static async generateInternalErrorPromise(error, errorFile) {
return [new BidsHedIssue(generateIssue('internalError', { message: error.message }), errorFile)]
}
}

export class BidsHedIssue extends BidsIssue {
/**
* The HED Issue object corresponding to this object.
* @type {Issue}
*/
hedIssue

/**
* Constructor.
* Generate a {@link Promise} with an internal error.
*
* @param {Issue} hedIssue The HED issue object to be wrapped.
* @param {Object} file The file this error occurred in.
* @param {string} error The error message.
* @param {Object} errorFile The file this error occurred in.
* @return {Promise} A promise resolving to a singleton array containing an internal error {@link BidsHedIssue}.
*/
constructor(hedIssue, file) {
super(BidsHedIssue._determineBidsIssueCode(hedIssue), file, hedIssue.message)

this.hedIssue = hedIssue
static async generateInternalErrorPromise(error, errorFile) {
return [new BidsHedIssue(generateIssue('internalError', { message: error.message }), errorFile)]
}

/**
* Determine the BIDS issue code for this issue.
*
* @param {Issue} hedIssue The HED issue object to be wrapped.
* @returns {number} The BIDS issue code for this issue.
* @returns {string} The BIDS issue code for this issue.
* @private
*/
static _determineBidsIssueCode(hedIssue) {
if (hedIssue.internalCode === 'internalError' || hedIssue.internalCode === 'internalConsistencyError') {
return 106
if (hedIssue.internalCode === 'internalError') {
return 'HED_INTERNAL_ERROR'
}
if (hedIssue.level === 'warning') {
return 105
return 'HED_WARNING'
}
return 104
return 'HED_ERROR'
}

/**
Expand Down
23 changes: 11 additions & 12 deletions src/bids/types/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ export class BidsSidecar extends BidsJsonFile {
} else if (!defManager) {
this.definitions = new DefinitionManager()
} else {
IssueError.generateAndThrow('internalError', {
message: 'Improper format for defManager parameter -- must be null or DefinitionManager',
})
IssueError.generateAndThrowInternalError(
'Improper format for defManager parameter -- must be null or DefinitionManager',
)
}
}

Expand Down Expand Up @@ -222,9 +222,7 @@ export class BidsSidecar extends BidsJsonFile {
} else if (hedData instanceof Map) {
this._parseCategorySplice(sidecarKey, hedData)
} else if (hedData) {
IssueError.generateAndThrow('internalConsistencyError', {
message: 'Unexpected type found in bidsFile parsedHedData map.',
})
IssueError.generateAndThrowInternalError('Unexpected type found in bidsFile parsedHedData map.')
}
}
}
Expand All @@ -250,9 +248,9 @@ export class BidsSidecar extends BidsJsonFile {

/**
* Add a list of columnSplices to a key map.
* @param {Set} keyReferences
* @param {Set<string>|null} keyReferences
* @param {ParsedHedColumnSplice[]} columnSplices
* @returns {*|Set<any>}
* @returns {Set<string>}
* @private
*/
_processColumnSplices(keyReferences, columnSplices) {
Expand Down Expand Up @@ -341,13 +339,14 @@ export class BidsSidecarKey {
}

/**
* Parse the value string in a bidsFile
* @param {Schemas} hedSchemas - The HED schemas to use.
* @returns {Issue[]}
* @private
* Parse the value string in a bidsFile.
*
* ### Note:
* The value strings cannot contain definitions.
*
* @param {Schemas} hedSchemas - The HED schemas to use.
* @returns {Issue[]}
* @private
*/
_parseValueString(hedSchemas) {
const [parsedString, parsingIssues] = parseHedString(this.valueString, hedSchemas, false, true)
Expand Down
6 changes: 3 additions & 3 deletions src/bids/types/tsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { IssueError } from '../../issues/issues'
export class BidsTsvFile extends BidsFile {
/**
* This file's parsed TSV data.
* @type {Map}
* @type {Map<string, string[]>}
*/
parsedTsv
/**
Expand Down Expand Up @@ -46,7 +46,7 @@ export class BidsTsvFile extends BidsFile {
} else if (isPlainObject(tsvData)) {
this.parsedTsv = convertParsedTSVData(tsvData)
} else {
IssueError.generateAndThrow('internalError', { message: 'parsedTsv has an invalid type' })
IssueError.generateAndThrowInternalError('parsedTsv has an invalid type')
}

this.mergedSidecar = new BidsSidecar(name, this.file, mergedDictionary, defManager)
Expand Down Expand Up @@ -140,7 +140,7 @@ export class BidsTsvElement {

/**
* Create a string list of a list of BidsTsvElement objects.
* @param BidsTsvElement[] elements - A list of elements to construct line numbers from.
* @param {BidsTsvElement[]} elements - A list of elements to construct line numbers from.
* @returns {string} - A string with the list of line numbers for error messages.
*/
static getTsvLines(elements) {
Expand Down
10 changes: 4 additions & 6 deletions src/bids/validator/sidecarValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class BidsHedSidecarValidator extends BidsValidator {
/**
* Validate a BIDS JSON bidsFile file. This method returns the complete issue list for convenience.
*
* @returns {BidsIssue[]} - Any issues found during validation of this bidsFile file.
* @returns {BidsHedIssue[]} - Any issues found during validation of this bidsFile file.
*/
validate() {
// Allow schema to be set a validation time -- this is checked by the superclass of BIDS file
Expand All @@ -40,7 +40,7 @@ export class BidsHedSidecarValidator extends BidsValidator {
/**
* Validate this bidsFile's HED strings.
*
* @returns {BidsIssue[]} All issues found.
* @returns {BidsHedIssue[]} All issues found.
*/
_validateStrings() {
const issues = []
Expand All @@ -55,9 +55,7 @@ export class BidsHedSidecarValidator extends BidsValidator {
issues.push(...this._checkDetails(sidecarKeyName, valueString))
}
} else {
IssueError.generateAndThrow('internalConsistencyError', {
message: 'Unexpected type found in bidsFile parsedHedData map.',
})
IssueError.generateAndThrowInternalError('Unexpected type found in bidsFile parsedHedData map.')
}
}
return issues
Expand Down Expand Up @@ -127,7 +125,7 @@ export class BidsHedSidecarValidator extends BidsValidator {
/**
* Validate this bidsFile's curly braces -- checking recursion and missing columns.
*
* @returns {BidsIssue[]} All issues found.
* @returns {BidsHedIssue[]} All issues found.
*/
_validateCurlyBraces() {
const issues = []
Expand Down
Loading
Loading