An error message and the context in which it occurred. Messages are usually created internally by Guice and its extensions. Messages can be created explicitly in a module using com.google.inject.Binder#addError(Throwable) addError() statements: try { bindPropertiesFromFile()
| 45 | * @author crazybob@google.com (Bob Lee) |
| 46 | */ |
| 47 | public final class Message implements Serializable, Element { |
| 48 | private final ErrorId errorId; |
| 49 | private final ErrorDetail<?> errorDetail; |
| 50 | |
| 51 | /** @since 5.0 */ |
| 52 | public Message(GuiceInternal internalOnly, ErrorId errorId, ErrorDetail<?> errorDetail) { |
| 53 | checkNotNull(internalOnly); |
| 54 | this.errorId = errorId; |
| 55 | this.errorDetail = errorDetail; |
| 56 | } |
| 57 | |
| 58 | private Message(ErrorId errorId, ErrorDetail<?> errorDetail) { |
| 59 | this.errorId = errorId; |
| 60 | this.errorDetail = errorDetail; |
| 61 | } |
| 62 | |
| 63 | /** @since 2.0 */ |
| 64 | public Message(ErrorId errorId, List<Object> sources, String message, Throwable cause) { |
| 65 | this.errorId = errorId; |
| 66 | this.errorDetail = new GenericErrorDetail(errorId, message, sources, cause); |
| 67 | } |
| 68 | |
| 69 | /** @since 2.0 */ |
| 70 | public Message(List<Object> sources, String message, Throwable cause) { |
| 71 | this(ErrorId.OTHER, sources, message, cause); |
| 72 | } |
| 73 | |
| 74 | /** @since 4.0 */ |
| 75 | public Message(String message, Throwable cause) { |
| 76 | this(ImmutableList.of(), message, cause); |
| 77 | } |
| 78 | |
| 79 | public Message(Object source, String message) { |
| 80 | this(ImmutableList.of(source), message, null); |
| 81 | } |
| 82 | |
| 83 | public Message(String message) { |
| 84 | this(ImmutableList.of(), message, null); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Returns details about this error message. |
| 89 | * |
| 90 | * @since 5.0 |
| 91 | */ |
| 92 | public ErrorDetail<?> getErrorDetail() { |
| 93 | return errorDetail; |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public String getSource() { |
| 98 | List<Object> sources = errorDetail.getSources(); |
| 99 | return sources.isEmpty() |
| 100 | ? SourceProvider.UNKNOWN_SOURCE.toString() |
| 101 | : Errors.convert(Iterables.getLast(sources)).toString(); |
| 102 | } |
| 103 | |
| 104 | /** @since 2.0 */ |
nothing calls this directly
no outgoing calls
no test coverage detected