MCPcopy Create free account
hub / github.com/google/guice / Message

Class Message

core/src/com/google/inject/spi/Message.java:47–181  ·  view source on GitHub ↗

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()

Source from the content-addressed store, hash-verified

45 * @author crazybob@google.com (Bob Lee)
46 */
47public 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 */

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected