How to use the error.IoError function in error

To help you get started, we’ve selected a few error examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dsheiko / puppetry / src / service / io.js View on Github external
throw new InvalidArgumentError( `File is empty or not a string` );
  }

  const filePath = join( directory, file );
  // in case of snippets
  if ( file === SNIPPETS_FILENAME && !fs.existsSync( filePath ) ) {
    log.warn( `Suite file ${filePath} not found.` );
    return null;
  }

  try {
    const text = await readFile( filePath, "utf8" );
    return parseJson( text, filePath );
  } catch ( e ) {
    log.warn( `Renderer process: io.readSuite: ${ e }` );
    throw new IoError( `Suite file ${filePath} cannot be open.
          Please make sure that the file exists and that you have read permission for it` );
  }
}
github dsheiko / puppetry / src / service / io.js View on Github external
export async function writeGit( directory, data ) {
  if ( !directory ) {
    return;
  }
  const filePath = join( directory, GIT_FILE_NAME );
  try {
    await writeFile( filePath, JSON.stringify( data, null, "  " ), "utf8" );
  } catch ( e ) {
    log.warn( `Renderer process: io.writeGit: ${ e }` );
    throw new IoError( `Project file ${filePath} cannot be written.
          Please make sure that you have write permission for it` );
  }
}
github dsheiko / puppetry / src / service / io.js View on Github external
export async function readGit( directory ) {
  const filePath = join( directory, GIT_FILE_NAME );
  try {
    const text = await readFile( filePath, "utf8" );
    return parseJson( text, filePath );
  } catch ( e ) {
    log.warn( `Renderer process: io.readGit: ${ e }` );
    throw new IoError( `Project file ${filePath} cannot be open.
          Please make sure that the file exists and that you have read permission for it` );
  }
}
github dsheiko / puppetry / src / service / io.js View on Github external
export async function writeProject( directory, data ) {
  if ( !directory ) {
    return;
  }
  const filePath = join( directory, PROJECT_FILE_NAME );
  if ( !data.name ) {
    log.warn( `Renderer process: io.writeProject: empty name in ${ JSON.stringify( data ) } in ${ directory }` );
    return;
  }
  try {
    await writeFile( filePath, JSON.stringify( data, null, "  " ), "utf8" );
  } catch ( e ) {
    log.warn( `Renderer process: io.writeProject: ${ e }` );
    throw new IoError( `Project file ${filePath} cannot be written.
          Please make sure that you have write permission for it` );
  }
}
github dsheiko / puppetry / src / service / io.js View on Github external
export function lockRuntimeTestPath() {
  const lockFile = getLockRuntimeTestPath(),
        version = remote.app.getVersion(),
        now = new Date(),
        data = {
          version,
          installed: now.toString()
        };
  try {
    fs.writeFileSync( lockFile, JSON.stringify( data, null, "  " ), "utf8" );
  } catch ( e ) {
    log.warn( `Renderer process: lockRuntimeTestPath(${ lockFile }) ${ e }` );
    throw new IoError( `Could not write file ${ lockFile }.
          Please make sure that you have write permission for it` );
  }
}
github dsheiko / puppetry / src / service / io.js View on Github external
export async function removeSuite( directory, file ) {

  if ( !directory || typeof directory !== "string" ) {
    throw new InvalidArgumentError( `Directory is empty or not a string` );
  }
  if ( !file || typeof file !== "string" ) {
    throw new InvalidArgumentError( `File is empty or not a string` );
  }

  const filePath = join( directory, file );
  try {
    await unlink( filePath );
  } catch ( e ) {
    log.warn( `Renderer process: io.removeSuite: ${ e }` );
    throw new IoError( `Suite file ${filePath} cannot be removed.` );
  }
}
github dsheiko / puppetry / src / service / io.js View on Github external
function parseJson( text, filePath ) {
  try {
    return JSON.parse( text || "{}" );
  } catch ( e ) {
    log.warn( `Renderer process: io.parseJson: ${ e }` );
    throw new IoError( `File ${filePath} seems to be corrupted.` );
  }
}