Repository: cypress-io/cypress
File: packages/server/lib/scaffold.js (JavaScript)

Code before:
    // skip if user has explicitly set pluginsFile
    if (!config.pluginsFile || !isDefault(config, 'pluginsFile')) {
      return Promise.resolve()
    }

    return this.verifyScaffolding(folder, () => {
      debug(`copying index.js into ${folder}`)

      return this._copy(cypressEx.getPathToPlugins(), folder, config)
    })
  },

  _copy (file, folder, config, integration = false) {
    // allow file to be relative or absolute
    const src = path.resolve(cwd('lib', 'scaffold'), file)
    const destFile = integration ? getPathFromIntegrationFolder(file) : path.basename(file)
    const dest = path.join(folder, destFile)

    return this._assertInFileTree(dest, config)
    .then(() => {
      return fs.copyAsync(src, dest)
    }).catch((error) => {
      if (error.code === 'EACCES') {
        const err = errors.get('ERROR_WRITING_FILE', dest, error)

        errors.log(err)
      }

      throw error
    })
  },

  _removeFile (file, folder, index) {
    const dest = path.join(folder, file)

    return fileSizeIsSame(dest, index)
    .then((isSame) => {
      if (isSame) {
        // catch all errors since the user may have already removed
        // the file or changed permissions, etc.
        return fs.removeAsync(dest).catch(_.noop)
      }
    })
  },

  _removeFolder (folderPath, folder) {
    const dest = path.join(folder, folderPath)

    // catch all errors since the user may have already removed
    // the folder, changed permissions, added their own files to the folder, etc.
    return fs.rmdirAsync(dest).catch(_.noop)

Review comment (suggestion):
No need to log and then throw, I think, since the `ERROR_WRITING_FILE` error wraps `error`.

```suggestion
        error = errors.get('ERROR_WRITING_FILE', dest, error)
```

Code after:
    // skip if user has explicitly set pluginsFile
    if (!config.pluginsFile || !isDefault(config, 'pluginsFile')) {
      return Promise.resolve()
    }

    return this.verifyScaffolding(folder, () => {
      debug(`copying index.js into ${folder}`)

      return this._copy(cypressEx.getPathToPlugins(), folder, config)
    })
  },

  _copy (file, folder, config, integration = false) {
    // allow file to be relative or absolute
    const src = path.resolve(cwd('lib', 'scaffold'), file)
    const destFile = integration ? getPathFromIntegrationFolder(file) : path.basename(file)
    const dest = path.join(folder, destFile)

    return this._assertInFileTree(dest, config)
    .then(() => {
      return fs.copyAsync(src, dest)
    }).catch((error) => {
      if (error.code === 'EACCES') {
        error = errors.get('ERROR_WRITING_FILE', dest, error)
      }

      throw error
    })
  },

  _removeFile (file, folder, index) {
    const dest = path.join(folder, file)

    return fileSizeIsSame(dest, index)
    .then((isSame) => {
      if (isSame) {
        // catch all errors since the user may have already removed
        // the file or changed permissions, etc.
        return fs.removeAsync(dest).catch(_.noop)
      }
    })
  },

  _removeFolder (folderPath, folder) {
    const dest = path.join(folder, folderPath)

    // catch all errors since the user may have already removed
    // the folder, changed permissions, added their own files to the folder, etc.
    return fs.rmdirAsync(dest).catch(_.noop)
  },