src/error-handling.js
// Directory-name must exist, and Directory-name must point to valid directory
Directory-name must exist, and Directory-name must point to valid directory
Directory - name must exist and Directory - name must point to valid directory
async function validatePathName (dir) {
  try {
    const files = [];
    const directoryContents = await fs.readdir(dir);
    for (const file of directoryContents) {
      const filePathWithPrefix = `${dir}/${file}`;
      if (fs.lstatSync(filePathWithPrefix).isDirectory()) {
        const newFilesInDirectory = await validatePathName(`${filePathWithPrefix}`);
        files.push(...newFilesInDirectory.map((filename) => `${file}/${filename}`));
      } else {
        files.push(file);
      }
    }
    return files;
  } catch (err) {
    if (err.name.startsWith('TypeError')) {
      err.subMessage = `Must include a directory name in the command 'convert-json-schemas-to-graphql-types <directory-name>'`;
    }
    if (err.errno === -2) {
      err.subMessage = `The path name "${err.path}" is not a valid directory`;
    }
    throw err;
  }
}
async function validatePathName ( dir ) { try { const files = [ ] ; const directoryContents = await fs . readdir ( dir ) ; for ( const file of directoryContents ) { const filePathWithPrefix = ` ${ dir } ${ file } ` ; if ( fs . lstatSync ( filePathWithPrefix ) . isDirectory ( ) ) { const newFilesInDirectory = await validatePathName ( ` ${ filePathWithPrefix } ` ) ; files . push ( ... newFilesInDirectory . map ( ( filename ) => ` ${ file } ${ filename } ` ) ) ; } else { files . push ( file ) ; } } return files ; } catch ( err ) { if ( err . name . startsWith ( 'TypeError' ) ) { err . subMessage = ` ` ; } if ( err . errno === - 2 ) { err . subMessage = ` ${ err . path } ` ; } throw err ; } }
Directory-name must exist, and Directory-name must point to valid directory
Directory - name must exist and Directory - name must point to valid directory
// eslint-disable-next-line security/detect-non-literal-fs-filename // eslint-disable-next-line security/detect-non-literal-fs-filename