src/error-handling.js
// Each file must have .json extension, and each file must be syntactically correct
Each file must have .json extension, and each file must be syntactically correct
Each file must have . json extension and each file must be syntactically correct
async function validateJSONSyntax (file, dir) {
  if (path.extname(file) !== '.json') {
    const err = new Error(`All files in directory must have .json extension`);
    err.subLocation = dir.endsWith('/') ? `${dir}${file}` : `${dir}/${file}`;
    throw err;
  }
  try {
    const fileContent = await fs.readFile(path.join(dir, file));
    const parsedFileContent = JSON.parse(fileContent);
    if (Array.isArray(parsedFileContent)) {
      validateArrayOfSchema(parsedFileContent, file);
    }
    return parsedFileContent;
  } catch (err) {
    if (err.subMessage) throw err; 
    err.subMessage = `Invalid JSON syntax in file '${file}'`;
    err.subLocation = dir.endsWith('/') ? `${dir}${file}` : `${dir}/${file}`;
    throw err;
  }
}
async function validateJSONSyntax ( file , dir ) { if ( path . extname ( file ) !== '.json' ) { const err = new Error ( ` ` ) ; err . subLocation = dir . endsWith ( '/' ) ? ` ${ dir } ${ file } ` : ` ${ dir } ${ file } ` ; throw err ; } try { const fileContent = await fs . readFile ( path . join ( dir , file ) ) ; const parsedFileContent = JSON . parse ( fileContent ) ; if ( Array . isArray ( parsedFileContent ) ) { validateArrayOfSchema ( parsedFileContent , file ) ; } return parsedFileContent ; } catch ( err ) { if ( err . subMessage ) throw err ; err . subMessage = ` ${ file } ` ; err . subLocation = dir . endsWith ( '/' ) ? ` ${ dir } ${ file } ` : ` ${ dir } ${ file } ` ; throw err ; } }
Each file must have .json extension, and each file must be syntactically correct
Each file must have . json extension and each file must be syntactically correct
// eslint-disable-next-line security/detect-non-literal-fs-filename // Specific error from above