Skip to content

Commit c2c3943

Browse files
committed
Add and update exception types
1 parent 0b6159f commit c2c3943

File tree

65 files changed

+696
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+696
-185
lines changed

src/main/java/com/relogiclabs/jschema/exception/DefinitionNotFoundException.java renamed to src/main/java/com/relogiclabs/jschema/exception/AliasNotFoundException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
44

5-
public class DefinitionNotFoundException extends CommonException {
6-
public DefinitionNotFoundException(ErrorDetail detail) {
5+
public class AliasNotFoundException extends BaseRuntimeException {
6+
public AliasNotFoundException(ErrorDetail detail) {
77
super(detail);
88
}
99
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
import com.relogiclabs.jschema.message.ErrorDetail;
4+
import com.relogiclabs.jschema.type.EValue;
5+
6+
public class ArgumentTypeException extends InvalidArgumentException {
7+
public ArgumentTypeException(String message) {
8+
super(message);
9+
}
10+
11+
public ArgumentTypeException(String code, String message, Throwable cause) {
12+
super(code, message, cause);
13+
}
14+
15+
public ArgumentTypeException(ErrorDetail detail, Throwable cause) {
16+
super(detail, cause);
17+
}
18+
19+
@Override
20+
public FunctionArgumentTypeException failWithFunctionException() {
21+
return new FunctionArgumentTypeException(this);
22+
}
23+
24+
@Override
25+
public MethodArgumentTypeException failWithMethodException(EValue self) {
26+
return new MethodArgumentTypeException(self, this);
27+
}
28+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
import com.relogiclabs.jschema.message.ErrorDetail;
4+
import com.relogiclabs.jschema.type.EValue;
5+
6+
public class ArgumentValueException extends InvalidArgumentException {
7+
public ArgumentValueException(String message) {
8+
super(message);
9+
}
10+
11+
public ArgumentValueException(String code, String message, Throwable cause) {
12+
super(code, message, cause);
13+
}
14+
15+
public ArgumentValueException(ErrorDetail detail, Throwable cause) {
16+
super(detail, cause);
17+
}
18+
19+
@Override
20+
public InvalidArgumentException failWithFunctionException() {
21+
return new FunctionArgumentValueException(this);
22+
}
23+
24+
@Override
25+
public InvalidArgumentException failWithMethodException(EValue self) {
26+
return new MethodArgumentValueException(self, this);
27+
}
28+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
import com.relogiclabs.jschema.message.ErrorDetail;
4+
5+
public class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
6+
public ArrayIndexOutOfBoundsException(ErrorDetail detail, Throwable cause) {
7+
super(detail, cause);
8+
}
9+
}

src/main/java/com/relogiclabs/jschema/exception/CommonException.java renamed to src/main/java/com/relogiclabs/jschema/exception/BaseRuntimeException.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,36 @@
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
44
import lombok.Getter;
5-
6-
import java.util.HashMap;
7-
import java.util.Map;
5+
import lombok.Setter;
86

97
import static java.util.Arrays.copyOfRange;
108

11-
public class CommonException extends RuntimeException {
9+
@Getter @Setter
10+
public class BaseRuntimeException extends RuntimeException {
11+
// Exception creation method
1212
private static final String FAIL_METHOD_PREFIX = "fail";
13-
@Getter private final String code;
14-
private Map<String, String> attributes;
13+
private String code;
1514

16-
public CommonException(String code, String message, Throwable cause) {
17-
super(message, cause);
18-
this.code = code;
19-
formatStackTrace();
15+
public BaseRuntimeException(String message) {
16+
this(null, message, null);
2017
}
2118

22-
public CommonException(String code, String message) {
19+
public BaseRuntimeException(String code, String message) {
2320
this(code, message, null);
2421
}
2522

26-
public CommonException(ErrorDetail detail, Throwable cause) {
27-
this(detail.getCode(), detail.getMessage(), cause);
23+
public BaseRuntimeException(String code, String message, Throwable cause) {
24+
super(message, cause);
25+
this.code = code;
2826
}
2927

30-
public CommonException(ErrorDetail detail) {
28+
public BaseRuntimeException(ErrorDetail detail) {
3129
this(detail, null);
3230
}
3331

34-
public String getAttribute(String name) {
35-
if(attributes == null) return null;
36-
return attributes.get(name);
37-
}
38-
39-
public void setAttribute(String name, String value) {
40-
if(attributes == null) attributes = new HashMap<>(5);
41-
attributes.put(name, value);
32+
public BaseRuntimeException(ErrorDetail detail, Throwable cause) {
33+
super(detail.getMessage(), cause);
34+
this.code = detail.getCode();
4235
}
4336

4437
@Override

src/main/java/com/relogiclabs/jschema/exception/ClassInstantiationException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
44

5-
public class ClassInstantiationException extends CommonException {
5+
public class ClassInstantiationException extends BaseRuntimeException {
66
public ClassInstantiationException(ErrorDetail detail, Throwable cause) {
77
super(detail, cause);
88
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
import com.relogiclabs.jschema.message.ActualDetail;
4+
import com.relogiclabs.jschema.message.ErrorDetail;
5+
import com.relogiclabs.jschema.message.ExpectedDetail;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
9+
@Getter @Setter
10+
public class DataTypeValidationException extends ValidationException {
11+
private String typeBaseName;
12+
13+
public DataTypeValidationException(ErrorDetail error, ExpectedDetail expected,
14+
ActualDetail actual) {
15+
super(error, expected, actual);
16+
}
17+
18+
public DataTypeValidationException(ErrorDetail error, ExpectedDetail expected,
19+
ActualDetail actual, Throwable cause) {
20+
super(error, expected, actual, cause);
21+
}
22+
}

src/main/java/com/relogiclabs/jschema/exception/DateTimeLexerException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.relogiclabs.jschema.exception;
22

3-
public class DateTimeLexerException extends CommonException {
3+
public class DateTimeLexerException extends BaseRuntimeException {
44
public DateTimeLexerException(String code, String message, Throwable cause) {
55
super(code, message, cause);
66
}

src/main/java/com/relogiclabs/jschema/exception/DuplicateDefinitionException.java renamed to src/main/java/com/relogiclabs/jschema/exception/DuplicateAliasException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.relogiclabs.jschema.message.ErrorDetail;
44

5-
public class DuplicateDefinitionException extends CommonException {
6-
public DuplicateDefinitionException(ErrorDetail detail) {
5+
public class DuplicateAliasException extends BaseRuntimeException {
6+
public DuplicateAliasException(ErrorDetail detail) {
77
super(detail);
88
}
99
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.relogiclabs.jschema.exception;
2+
3+
import com.relogiclabs.jschema.message.ErrorDetail;
4+
import org.antlr.v4.runtime.Token;
5+
6+
import static com.relogiclabs.jschema.message.MessageFormatter.formatForSchema;
7+
8+
public class DuplicateFunctionException extends MultilevelRuntimeException {
9+
public DuplicateFunctionException(String code, String message) {
10+
super(code, message);
11+
}
12+
13+
public DuplicateFunctionException(ErrorDetail detail, Throwable cause) {
14+
super(detail, cause);
15+
}
16+
17+
@Override
18+
public RuntimeException translate(Token token) {
19+
if(isHighLevel()) return this;
20+
return new DuplicateFunctionException(formatForSchema(getCode(),
21+
getMessage(), token), this);
22+
}
23+
}

0 commit comments

Comments
 (0)