1e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin/*
2e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * Copyright (C) 2012 Google Inc.
3e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin *
4e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * Licensed under the Apache License, Version 2.0 (the "License");
5e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * you may not use this file except in compliance with the License.
6e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * You may obtain a copy of the License at
7e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin *
8e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * http://www.apache.org/licenses/LICENSE-2.0
9e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin *
10e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * Unless required by applicable law or agreed to in writing, software
11e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * distributed under the License is distributed on an "AS IS" BASIS,
12e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * See the License for the specific language governing permissions and
14e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * limitations under the License.
15e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin */
16e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin
17e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffinpackage com.google.caliper.runner;
18e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin
19e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffinimport com.google.common.base.Joiner;
20e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffinimport com.google.common.base.Splitter;
21e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin
22e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin
23e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin/**
24e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * An exception created on the runner with the same stack trace as one thrown on the worker that
25e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin * reports the actual exception class and message in its message.
26e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin */
27e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffinfinal class ProxyWorkerException extends RuntimeException {
28e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin  ProxyWorkerException(String stackTrace) {
29e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin    super(formatMesssage(stackTrace));
30e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin  }
31e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin
32e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin  private static String formatMesssage(String stackTrace) {
33e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin    StringBuilder builder = new StringBuilder(stackTrace.length() + 512)
34e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin        .append("An exception occurred in a worker process.  The stack trace is as follows:\n\t");
35e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin    Joiner.on("\n\t").appendTo(builder, Splitter.on('\n').split(stackTrace));
36e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin    return builder.toString();
37e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin  }
38e236301e5fc778bffe1748ed80d7936e6c807012Paul Duffin}
39