Skip to content

Commit 7167721

Browse files
committed
Improve exception messages and introduce common base exception type
1 parent 78c0ecd commit 7167721

11 files changed

+41
-13
lines changed

src/main/java/io/github/stefanka/protobufgen/exception/FieldAlreadyExistsException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package io.github.stefanka.protobufgen.exception;
1717

18-
public class FieldAlreadyExistsException extends RuntimeException {
18+
public class FieldAlreadyExistsException extends ProtocolBufferBuilderException {
1919

2020
public FieldAlreadyExistsException(String fieldName) {
21-
super("A field with the name '" + fieldName + "' already exists.");
21+
super("A field with the name '" + fieldName + "' already exists. Please ensure that field names are unique.");
2222
}
2323

2424
}

src/main/java/io/github/stefanka/protobufgen/exception/FieldNumberAlreadyExistsException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.github.stefanka.protobufgen.exception;
1717

18-
public class FieldNumberAlreadyExistsException extends RuntimeException {
18+
public class FieldNumberAlreadyExistsException extends ProtocolBufferBuilderException {
1919

2020
public FieldNumberAlreadyExistsException(String message, int index) {
2121
super("The message '" + message + "' already contains a field with the index " + index + ".");

src/main/java/io/github/stefanka/protobufgen/exception/FieldNumberOutOfRangeException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.github.stefanka.protobufgen.exception;
1717

18-
public class FieldNumberOutOfRangeException extends RuntimeException {
18+
public class FieldNumberOutOfRangeException extends ProtocolBufferBuilderException {
1919

2020
public FieldNumberOutOfRangeException(int number) {
2121
super("The number " + number + "is out of the supported range (1 - 536'870'911).");

src/main/java/io/github/stefanka/protobufgen/exception/FieldNumberReservedException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.github.stefanka.protobufgen.exception;
1717

18-
public class FieldNumberReservedException extends RuntimeException {
18+
public class FieldNumberReservedException extends ProtocolBufferBuilderException {
1919

2020
public FieldNumberReservedException() {
2121
super("Field numbers 19000 through 19999 are reserved for the protocol buffer library implementation.");

src/main/java/io/github/stefanka/protobufgen/exception/FirstEnumFieldZeroValueException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.github.stefanka.protobufgen.exception;
1717

18-
public class FirstEnumFieldZeroValueException extends RuntimeException {
18+
public class FirstEnumFieldZeroValueException extends ProtocolBufferBuilderException {
1919

2020
public FirstEnumFieldZeroValueException() {
2121
super("The first enum field must have the value zero (0)!");

src/main/java/io/github/stefanka/protobufgen/exception/NestedMessageAlreadyExistsException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package io.github.stefanka.protobufgen.exception;
1717

18-
public class NestedMessageAlreadyExistsException extends RuntimeException {
18+
public class NestedMessageAlreadyExistsException extends ProtocolBufferBuilderException {
1919

2020
public NestedMessageAlreadyExistsException(String name) {
21-
super("A nested message with the name '" + name + "' already exists!");
21+
super("A nested message with the name '" + name + "' already exists. Please ensure that nested message names are unique.");
2222
}
2323

2424
}

src/main/java/io/github/stefanka/protobufgen/exception/ProtoSerializationException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.github.stefanka.protobufgen.exception;
1717

18-
public class ProtoSerializationException extends RuntimeException {
18+
public class ProtoSerializationException extends ProtocolBufferBuilderException {
1919

2020
public ProtoSerializationException(Throwable e) {
2121
super("The proto file cannot be serialized.", e);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2020 Stefan Kapferer
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.github.stefanka.protobufgen.exception;
17+
18+
public class ProtocolBufferBuilderException extends RuntimeException {
19+
20+
public ProtocolBufferBuilderException(String message) {
21+
super(message);
22+
}
23+
24+
public ProtocolBufferBuilderException(String message, Throwable cause) {
25+
super(message, cause);
26+
}
27+
28+
}

src/main/java/io/github/stefanka/protobufgen/exception/RemoteProcedureCallAlreadyExistsException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package io.github.stefanka.protobufgen.exception;
1717

18-
public class RemoteProcedureCallAlreadyExistsException extends RuntimeException {
18+
public class RemoteProcedureCallAlreadyExistsException extends ProtocolBufferBuilderException {
1919

2020
public RemoteProcedureCallAlreadyExistsException(String name) {
2121
super("An RPC with the name '" + name + "' already exists in your service!");

src/main/java/io/github/stefanka/protobufgen/exception/RootElementAlreadyExistsException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package io.github.stefanka.protobufgen.exception;
1717

18-
public class RootElementAlreadyExistsException extends RuntimeException {
18+
public class RootElementAlreadyExistsException extends ProtocolBufferBuilderException {
1919

2020
public RootElementAlreadyExistsException(String name) {
21-
super("A root element (message, enum, or service) with the name '" + name + "' already exists in your spec!");
21+
super("A root element (message, enum, or service) with the name '" + name + "' already exists in your spec. Please ensure that the names of your messages, enums, and services are unique.");
2222
}
2323

2424
}

0 commit comments

Comments
 (0)