title: Google Apps Script throws "We're sorry, a server error occurred. Please wait a bit and try again. (line 13, file "Code")"
body: <p>I'm trying to migrate Google Drive files to new accounts in a new domain.  I thought I had finished my script, but when I tried to test it I keep getting this very unhelpful error.  Does anyone know what sorts of problems typically cause this error, or how to interpret it?  I've searched SO, but I did not find anything useful.</p>
  
  <p>Here is my script:</p>
  
  <pre><code>function copyDrive() {
  
  
    var originFolder = DriveApp.getFolderById(originFolderID);
    var destination = DriveApp.getFolderById(destinationID);
  
    var scriptProperties = PropertiesService.getScriptProperties();
    var lastExecution = scriptProperties.getProperty('LAST_EXECUTION');
    if( lastExecution === null )
      lastExecution = '';
  
    var fileContinuationToken = scriptProperties.getProperty('FILE_CONTINUATION_TOKEN');
    var fileIterator = fileContinuationToken == null ?
      originFolder.getFiles() : DriveApp.continueFileIterator(fileContinuationToken);
    var folderContinuationToken = scriptProperties.getProperty('FOLDER_CONTINUATION_TOKEN');
    var folderIterator = folderContinuationToken == null ?
      originFolder.getFolders() : DriveApp.continueFolderIterator(folderContinuationToken);
  
    try { 
      var rootFileName;
      while(fileIterator.hasNext()) {
        var rootFile = fileIterator.next();
        var rootFileDateCreated = formatDate(rootFile.getDateCreated());
        if(rootFileDateCreated &lt; lastExecution) {
          rootFileName = rootFile.getName();
          rootFile.makeCopy(rootFileName, destination);
        }
      }
      var folder = folderIterator.next();
      var folderDateCreated = formatDate(folder.getDateCreated());
      if(folderDateCreated &lt; lastExecution) {
        var folderName = folder.getName();
        var folderCopy = folder.makeCopy(folderName, destination);
      }
      copyFiles(folder, folderCopy);
    } catch(err) {
      Logger.log(err);
    }
  
    if(fileIterator.hasNext()) {
      scriptProperties.setProperty('FILE_CONTINUATION_TOKEN', fileIterator.getContinuationToken());
    } else {
      scriptProperties.deleteProperty('FILE_CONTINUATION_TOKEN');
    }
    if(folderIterator.hasNext()) {
      scriptProperties.setProperty('FOLDER_CONTINUATION_TOKEN', folderIterator.getContinuationToken());
    } else {
      scriptProperties.deleteProperty('FOLDER_CONTINUATION_TOKEN');
    }
    scriptProperties.setProperty('LAST_EXECUTION', formatDate(new Date()));
  
  };
  
  function formatDate(date) { return Utilities.formatDate(date, "GMT", "yyyy-MM-dd HH:mm:ss"); };
  
  function copyFiles(passedFolder, targetFolder) {
    var fileContents = passedFolder.getFiles();
    var file;
    var fileName;
  
    while(fileContents.hasNext()) {
      file = fileContents.next();
      fileName = file.getName();
      file.makeCopy(fileName, targetFolder);
    }
    copySubFolders(passedFolder, targetFolder);
  };
  
  function copySubFolders(passedFolder, targetFolder) {
    var subFolderContents = passedFolder.getFolders();
    var subFolder;
    var subFolderName;
  
    while(folderContents.hasNext()) {
      subFolder = subFolderContents.next();
      subFolderName = subFolder.getName();
      var subFolderCopy = targetFolder.createFolder(folderName);
      copyFiles(subFolder, subFolderCopy);
    }
  };
  </code></pre>
  
  <p>I get the error on this line:</p>
  
  <pre><code>  var fileIterator = fileContinuationToken == null ? originFolder.getFiles() : DriveApp.continueFileIterator(fileContinuationToken);
  </code></pre>
  
  <p>Any ideas?</p>