Converts RepositoryException into an appropriate FetchException, prepending
the specified message. If message is null, original exception message is
preserved.

@param message message to prepend, which may be null
778656
public final FetchException toFetchException(final String message) {
        Throwable cause;
        if (this instanceof FetchException) {
            cause = this;
        } else {
            cause = getCause();
        }

        if (cause == null) {
            cause = this;
        } else if (cause instanceof FetchException && message == null) {
            return (FetchException) cause;
        }

        String causeMessage = cause.getMessage();
        if (causeMessage == null) {
            causeMessage = message;
        } else if (message != null) {
            causeMessage = message + " : " + causeMessage;
        }

        return makeFetchException(causeMessage, cause);
    }
317577
protected String constructMessage(String message, Throwable cause) {
		
		if (cause != null) {
		
			StringBuilder strBuilder = new StringBuilder();
			
			if (message != null) {
				strBuilder.append(message).append(": ");
			}
			
			strBuilder.append("Wrapped exception is {").append(cause);
			strBuilder.append("}");
			
			return strBuilder.toString();
			
		} else {
			return message;
		}
	}
90285
public void setErrorMessage(Throwable exception) {
		if (exception != null) {
			String message = exception.getLocalizedMessage();
			if (Strings.isNullOrEmpty(message)) {
				message = exception.getMessage();
			}
			if (Strings.isNullOrEmpty(message)) {
				message = MessageFormat.format(Messages.SREsPreferencePage_9, exception.getClass().getName());
			}
			setErrorMessage(message);
		}
	}
852144
public void error(final String message) {
        messages.add(new LogMessage(message, LogMessage.Type.ERROR));
        log.error(message);
    }
1282909
final void dispatchToAppender(final String message) {
    // dispatch a copy, since events should be treated as being immutable
    final FoundationFileRollingAppender appender = this.getSource();
    if (appender != null) {
      appender.append(new FileRollEvent(this, message));
    }
  }
252435
public static void throwExceptionOnError(ResponseEntity<?> response) {
		if (!response.getStatusCode().equals(HttpStatus.OK)) {
			throw new CredHubException(response.getStatusCode());
		}
	}
1214900
public static EvaluatorException reportRuntimeError(String message)
    {
        int[] linep = { 0 };
        String filename = getSourcePositionFromStack(linep);
        return Context.reportRuntimeError(message, filename, linep[0], null, 0);
    }
1245437
private void throwOrWarnAboutDescriptorProblem(String message) {
        if (validateDescriptions) {
            throw new IllegalArgumentException(message);
        }
        ControllerLogger.ROOT_LOGGER.warn(message);
    }
844169
@SuppressWarnings("checkstyle:regexp")
	public static void showError(String message, Throwable exception) {
		try (PrintWriter logger = new PrintWriter(getConsoleLogger())) {
			if (message != null && !message.isEmpty()) {
				logger.println(message);
			} else if (exception != null) {
				exception.printStackTrace(logger);
			}
			logger.println();
			logger.flush();
			showHelp(logger, false);
			showVersion(true);
		}
	}
85130
private void doCounterGet(final Message<JsonObject> message) {
    final String name = message.body().getString("name");
    if (name == null) {
      message.reply(new JsonObject().putString("status", "error").putString("message", "No name specified."));
      return;
    }

    context.execute(new Action<Long>() {
      @Override
      public Long perform() {
        Map<Object, Long> counters = data.getMap(formatKey("counters"));
        Long value = counters.get(name);
        if (value == null) {
          value = 0L;
        }
        return value;
      }
    }, new Handler<AsyncResult<Long>>() {
      @Override
      public void handle(AsyncResult<Long> result) {
        if (result.failed()) {
          message.reply(new JsonObject().putString("status", "error").putString("message", result.cause().getMessage()));
        } else {
          message.reply(new JsonObject().putString("status", "ok").putNumber("result", result.result()));
        }
      }
    });
  }
716204
public RepositoryException toRepositoryException(Throwable e) {
        RepositoryException re = transformIntoRepositoryException(e);
        if (re != null) {
            return re;
        }

        Throwable cause = e.getCause();
        if (cause != null) {
            re = transformIntoRepositoryException(cause);
            if (re != null) {
                return re;
            }
        } else {
            cause = e;
        }

        return new RepositoryException(cause);
    }
1218449
public void javacError(String message, Throwable t) {
		messager.printMessage(Diagnostic.Kind.ERROR, message + (t == null ? "" : (": " + t)));
		if (t != null) t.printStackTrace();
	}
710108
protected static Throwable newEncoderException(final String message,
                                                   final Throwable cause) {

        try {
            return ENCODER_EXCEPTION
                .getConstructor(String.class, Throwable.class)
                .newInstance(message, cause);
        } catch (final NoSuchMethodException nsme) {
            throw new RuntimeException(nsme);
        } catch (final InstantiationException ie) {
            throw new RuntimeException(ie);
        } catch (final IllegalAccessException iae) {
            throw new RuntimeException(iae);
        } catch (final InvocationTargetException ite) {
            throw new RuntimeException(ite);
        }
    }
28401
@Override
    public void handleMessage(final Message message) throws Fault {
        final InputStream is = message.getContent(InputStream.class);
        if (WireTapHelper.isMessageContentToBeLogged(message, logMessageContent, logMessageContentOverride)) {
            if (null == is) {
                Reader reader = message.getContent(Reader.class);
                if (null != reader) {
                    String encoding = (String) message.get(Message.ENCODING);
                    if (encoding == null) {
                        encoding = "UTF-8";
                    }
                    try {
                        final CachedOutputStream cos = new CachedOutputStream();
                        final Writer writer = new OutputStreamWriter(cos, encoding);
                        IOUtils.copy(reader, writer, 1024);
                        reader.reset();
                        writer.flush();
                        message.setContent(InputStream.class, cos.getInputStream());
                        message.setContent(Reader.class, null);
                        message.setContent(CachedOutputStream.class, cos);
                        closeCachedOutputStream(message, cos);
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    } finally {
                        try {
                            reader.reset();
                        } catch (IOException e) {
                        }
                    }
                }
            } else {
                try {
                    final CachedOutputStream cos = new CachedOutputStream();
                    // TODO: We should try to make this streaming
                    //WireTapInputStream wtis = new WireTapInputStream(is, cos);
                    //message.setContent(InputStream.class, wtis);
                    IOUtils.copyAndCloseInput(is, cos);
                    message.setContent(InputStream.class, cos.getInputStream());
                    message.setContent(CachedOutputStream.class, cos);
                    closeCachedOutputStream(message, cos);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }else {
            try {
                final CachedOutputStream cos = new CachedOutputStream();
                cos.write(WireTapHelper.CONTENT_LOGGING_IS_DISABLED.getBytes(Charset.forName("UTF-8")));
                message.setContent(CachedOutputStream.class, cos);
                message.setContent(InputStream.class, is);
                closeCachedOutputStream(message, cos);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
673059
@Override public void addError(String message) {
		ast.printMessage(Diagnostic.Kind.ERROR, message, this, null, true);
	}
674817
@Override
    public void onMessage(Message message) {
        MDC.put("name", name);
        try {
            // Make sure thread priority is correct
            if (!Thread.currentThread().getName().equals(thread.getName())) {
                Thread.currentThread().setName(thread.getName());
                Thread.currentThread().setPriority(thread.getPriority());
            }

            // Get the message details
            String text = ((TextMessage) message).getText();
            JsonSimple config = new JsonSimple(text);
            String event = config.getString(null, "event");
            if (event == null) {
                log.error("Invalid message received: '{}'", text);
                return;
            }

            // Commit on the index
            if (event.equals("commit")) {
                log.debug("Commit received");
                submitBuffer(true);
            }
            // Index the incoming document
            if (event.equals("index")) {
                String index = config.getString(null, "index");
                String document = config.getString(null, "document");
                if (index == null || document == null) {
                    log.error("Invalid message received: '{}'", text);
                    return;
                }
                addToBuffer(index, document);
            }

        } catch (JMSException jmse) {
            log.error("Failed to send/receive message: {}", jmse.getMessage());
        } catch (IOException ioe) {
            log.error("Failed to parse message: {}", ioe.getMessage());
        }
    }
754922
private HttpMessage convertOutboundMessage(Message message) {
        HttpMessage httpMessage;
        if (message instanceof HttpMessage) {
            httpMessage = (HttpMessage) message;
        } else {
            httpMessage = new HttpMessage(message);
        }
        return httpMessage;
    }