/*
Method called when a client attachment fails
5236
public void fail (ClientConnection cc, Throwable t) {
    if (tc.isEntryEnabled()) {
      SibTr.entry(tc, "fail", new Object[]{ cc, t });
      SibTr.exit(tc, "fail");
    }
  }
251567
function(resolve, reject) {
			var fn = _client.client.VimService.VimPort[name];
			fn(args, function(err, result, raw, soapHeader) {
				if (err) {
					
					// emit an error and handle the error
					_client.emit('method.error', err);
					_client.errorHandler(err, name, args, resolve, reject);
				}
				else {
					_client.retry = 0;
					
					// emit an event and resolve the output
					_client.emit('method.result', result);
					resolve(_.get(result, 'returnval'));
				}
			});
		}
319003
protected void validateAttachmentContentId(SoapAttachment receivedAttachment, SoapAttachment controlAttachment) {
        //in case contentId was not set in test case, skip validation 
        if (!StringUtils.hasText(controlAttachment.getContentId())) { return; }
        
        if (receivedAttachment.getContentId() != null) {
            Assert.isTrue(controlAttachment.getContentId() != null, 
                    buildValidationErrorMessage("Values not equal for attachment contentId", 
                            null, receivedAttachment.getContentId()));

            Assert.isTrue(receivedAttachment.getContentId().equals(controlAttachment.getContentId()),
                    buildValidationErrorMessage("Values not equal for attachment contentId", 
                            controlAttachment.getContentId(), receivedAttachment.getContentId()));
        } else {
            Assert.isTrue(controlAttachment.getContentId() == null || controlAttachment.getContentId().length() == 0, 
                    buildValidationErrorMessage("Values not equal for attachment contentId", 
                            controlAttachment.getContentId(), null));
        }
        
        if (log.isDebugEnabled()) {
            log.debug("Validating attachment contentId: " + receivedAttachment.getContentId() + 
                    "='" + controlAttachment.getContentId() + "': OK.");
        }
    }
1293861
private void processFailedReceivedDeleted(long[] failedMap, Block[] sent) {
    synchronized (receivedAndDeletedBlockList) {
      // Blocks that do not belong to an Inode are saved for
      // retransmisions
      for (int i = sent.length - 1 ; i >= 0; i--) {
        if(!LightWeightBitSet.get(failedMap, i)){
          continue;
        }
        // Insert into retry list.
        LOG.info("Block " + sent[i] + " does not belong to any file "
            + "on namenode " + avatarnodeAddress + " Retry later.");
        receivedAndDeletedBlockList.add(0, sent[i]);
        if (!DFSUtil.isDeleted(sent[i])) {
          pendingReceivedRequests++;
        }
      }
      lastBlockReceivedFailed = AvatarDataNode.now();
    }
  }
348009
function resolveFile(success, fail, request, options) {
    var path = request.substring(7);
    resolve(success, fail, path, window.PERSISTENT, UNSANDBOXED, options);
}
135406
public static void validateAttachmentLabel(String label)
      throws MonomerException {

    if (label.equalsIgnoreCase(Attachment.PAIR_ATTACHMENT)) {
      return;
    }
    char[] chars = label.toCharArray();

    if (!(String.valueOf(chars[0])).equals("R")) {
      throw new MonomerException("Invalid Attachment Label format");
    }
    for (int i = 1; i < chars.length; i++) {
      char c = chars[i];
      if (!(String.valueOf(c)).matches("[0-9]")) {
        throw new MonomerException("Invalid Attachment Label format");
      }
    }
  }
180298
void postFailure(final DownloadRequest request, final int statusCode, final String errMsg) {
    downloadPoster.execute(new Runnable() {
      @Override public void run() {
        request.downloadCallback().onFailure(request.downloadId(), statusCode, errMsg);
      }
    });
  }
605475
function processFileResponse(req, res, next) {
  var fileDetails = req.appformsResultPayload.data;
  if (fileDetails.stream) {
    var headers = {};
    headers["Content-Type"] = fileDetails.type;//Setting the file content type. Mime types are set by the file handler.
    headers["Content-Disposition"] = "attachment; filename=" + fileDetails.name;
    res.writeHead(200, headers);
    fileDetails.stream.pipe(res);
    fileDetails.stream.resume(); //Unpausing the stream as it was paused by the file handler
  } else {
    return next('Error getting submitted file - result: ' + JSON.stringify(fileDetails));
  }
}
783468
@Override
    public InputStream getAttachment(final Asset asset, final Attachment attachment) throws IOException, BadVersionException, RequestFailureException {

        // accept license for type CONTENT
        HttpURLConnection connection;
        if (attachment.getType() == AttachmentType.CONTENT) {
            connection = createHttpURLConnection(attachment.getUrl() + "?license=agree");
        } else {
            connection = createHttpURLConnection(attachment.getUrl());
        }

        // If the attachment was a link and we have a basic auth userid + password specified
        // we are attempting to access the files staged from a protected site so authorise for it
        if (attachment.getLinkType() == AttachmentLinkType.DIRECT) {
            if ((loginInfo.getAttachmentBasicAuthUserId() != null) && (loginInfo.getAttachmentBasicAuthPassword() != null)) {
                String userpass = loginInfo.getAttachmentBasicAuthUserId() + ":" + loginInfo.getAttachmentBasicAuthPassword();
                String basicAuth = "Basic " + encode(userpass.getBytes(Charset.forName("UTF-8")));
                connection.setRequestProperty("Authorization", basicAuth);
            }
        }

        connection.setRequestMethod("GET");
        testResponseCode(connection);
        return connection.getInputStream();
    }
418851
function ClientError(message, status, cause) {
    ClientError.super_.call(this, message, status || StatusCode.CLIENT_ERROR, cause);
}
1224090
public void processAnyCallbacksFromFailedHosts(Set<Integer> failedHosts) {
        synchronized(m_allHostCallbackLock) {
            failedHosts.stream()
                .forEach(i -> {
                    if (m_outstandingAllHostProcedureHostIds.contains(i)) {
                        ClientResponseImpl cri = new ClientResponseImpl(
                                ClientResponse.CONNECTION_LOST,
                                new VoltTable[0],
                                "Host " + i + " failed, connection lost");
                        // embed the hostid as a string in app status string
                        // because the recipient expects this hack
                        cri.setAppStatusString(String.valueOf(i));

                        allHostNTProcedureCallback(cri);
                    }
                });
        }
    }
218715
public static void fail(String source, int index, String description) {
        throw new FormLayoutParseException(message(source, index, description));
    }
1130716
function callback(err, callbackId) {
    // There is a single callback for all load events, so make sure this
    // is the right one.
    if (callbackId !== imageId) {
      return;
    }

    stage.removeFlashCallbackListener('imageLoaded', callback);

    // TODO: is there any way to distinguish a network error from other
    // kinds of errors? For now we always return NetworkError since this
    // prevents images to be retried continuously while we are offline.
    if (err) {
      done(new NetworkError('Network error: ' + url));
    } else {
      done(null, new FlashAsset(flashElement, imageId));
    }
  }
714098
function onFileReady(err, data) {
    if (err) {
      if (onDone) onDone(err)
      else console.error('>>>' + err);
      return;
    }

    var fileContent = data.toString();

    var msg = {
      text:    fileContent,
      mode:    flavor,
      context: context
    };

    var jsonMsg = JSON.stringify(msg);

    var options = {
      method: 'POST',
      preambleCRLF: true,
      postambleCRLF: true,
      uri: 'https://api.github.com/markdown',
      'content-type': 'application/json',
      headers: {
        'User-Agent' : userName
      },
      body: jsonMsg
    };

    //=======================================================
    // Call the Github Markdown API to parse the file content
    //=======================================================
    request(options, handleResponse.bind(this));

    //======================================================
    // Enhance the output of the Github Markdown API with
    // optional header or trailer.
    //======================================================
    function handleResponse(err, response, body) {
      if (this.debug) console.error('>>>handling response...');
      if (err) {
        if (onDone) onDone(err)
        else console.error('>>>upload to github failed: ', err);
        return;
      }

      if (stylesheet || title) {
        if (titleText == null) titleText = fileName;
        this.cat('<!DOCTYPE html>\n' +
                 '<html>\n' +
                 '<head>\n' +
                 '  <title>' + titleText + '</title>\n' +
                 '  <link rel="stylesheet" href="' + stylesheet + '">\n' +
                 '</head>\n' +
                 '<body>\n' );
      }

      this.cat(body);
      this.cat('\n');

      if (stylesheet || title) {
        this.cat( '</body>\n</html>\n' );
      }

      if (this.debug) console.error('>>>finished getting code');
      this.done = true;
      if (onDone) onDone();
    } // end handleResponse
  }
100032
function insertAttachmentMappings(docInfo, seq, callback) {

    var attsAdded = 0;
    var attsToAdd = Object.keys(docInfo.data._attachments || {});

    if (!attsToAdd.length) {
      return callback();
    }

    function checkDone() {
      if (++attsAdded === attsToAdd.length) {
        callback();
      }
    }

    function add(att) {
      var digest = docInfo.data._attachments[att].digest;
      var req = attachAndSeqStore.put({
        seq: seq,
        digestSeq: digest + '::' + seq
      });

      req.onsuccess = checkDone;
      req.onerror = function (e) {
        // this callback is for a constaint error, which we ignore
        // because this docid/rev has already been associated with
        // the digest (e.g. when new_edits == false)
        e.preventDefault(); // avoid transaction abort
        e.stopPropagation(); // avoid transaction onerror
        checkDone();
      };
    }
    for (var i = 0; i < attsToAdd.length; i++) {
      add(attsToAdd[i]); // do in parallel
    }
  }
402609
public void handleLostConnection() {
        try {
            clientEngine.applySelector(ClientSelectors.any());
        } catch (Exception e) {
            LOGGER.warning("Could not clean up client B/W list filtering.", e);
        }
    }
329118
@Override
    public void streamingFailed(final StreamingErrorEvent event) {
        assertStateConsistency(fileUploadId, event.getFileName());

        if (!isUploadInterrupted()) {
            interruptUploadDueToUploadFailed();
        }
        publishUploadFailedAndFinishedEvent(fileUploadId, event.getException());
    }