Skip to content

Commit e74c9bc

Browse files
[Improve][Connector-V2][Assert] Unified exception for assert connector (#3331)
* [Improve][Core][Exception Management] Add exception api * remove duplicate ExceptionUtil class (#3037) * [Improve][Core][Exception Management] Add exception api * [Improve][Core][Exception Management] Rename exception name * [Improve][Connector-V2][Assert] Unified exception for assert sink connector * [Improve][Connector-V2][Assert] Fix code style Co-authored-by: Eric <gaojun2048@gmail.com>
1 parent ebebf0b commit e74c9bc

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.connectors.seatunnel.assertion.exception;
19+
20+
import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
21+
22+
public enum AssertConnectorErrorCode implements SeaTunnelErrorCode {
23+
RULE_VALIDATION_FAILED("ASSERT-01", "Rule validate failed");
24+
25+
private final String code;
26+
private final String description;
27+
28+
AssertConnectorErrorCode(String code, String description) {
29+
this.code = code;
30+
this.description = description;
31+
}
32+
33+
@Override
34+
public String getCode() {
35+
return code;
36+
}
37+
38+
@Override
39+
public String getDescription() {
40+
return description;
41+
}
42+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.seatunnel.connectors.seatunnel.assertion.exception;
19+
20+
import org.apache.seatunnel.common.exception.SeaTunnelErrorCode;
21+
import org.apache.seatunnel.common.exception.SeaTunnelRuntimeException;
22+
23+
public class AssertConnectorException extends SeaTunnelRuntimeException {
24+
25+
public AssertConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, String errorMessage) {
26+
super(seaTunnelErrorCode, errorMessage);
27+
}
28+
29+
public AssertConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, String errorMessage, Throwable cause) {
30+
super(seaTunnelErrorCode, errorMessage, cause);
31+
}
32+
33+
public AssertConnectorException(SeaTunnelErrorCode seaTunnelErrorCode, Throwable cause) {
34+
super(seaTunnelErrorCode, cause);
35+
}
36+
}

seatunnel-connectors-v2/connector-assert/src/main/java/org/apache/seatunnel/connectors/seatunnel/assertion/sink/AssertSinkWriter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
2121
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
2222
import org.apache.seatunnel.connectors.seatunnel.assertion.excecutor.AssertExecutor;
23+
import org.apache.seatunnel.connectors.seatunnel.assertion.exception.AssertConnectorErrorCode;
24+
import org.apache.seatunnel.connectors.seatunnel.assertion.exception.AssertConnectorException;
2325
import org.apache.seatunnel.connectors.seatunnel.assertion.rule.AssertFieldRule;
2426
import org.apache.seatunnel.connectors.seatunnel.common.sink.AbstractSinkWriter;
2527

@@ -49,7 +51,8 @@ public void write(SeaTunnelRow element) {
4951
ASSERT_EXECUTOR
5052
.fail(element, seaTunnelRowType, assertFieldRules)
5153
.ifPresent(failRule -> {
52-
throw new IllegalStateException("row :" + element + " fail rule: " + failRule);
54+
throw new AssertConnectorException(AssertConnectorErrorCode.RULE_VALIDATION_FAILED,
55+
"row :" + element + " fail rule: " + failRule);
5356
});
5457
}
5558
}
@@ -67,7 +70,8 @@ public void close() {
6770
return false;
6871
}
6972
}).findFirst().ifPresent(failRule -> {
70-
throw new IllegalStateException("row num :" + LONG_ACCUMULATOR.longValue() + " fail rule: " + failRule);
73+
throw new AssertConnectorException(AssertConnectorErrorCode.RULE_VALIDATION_FAILED,
74+
"row num :" + LONG_ACCUMULATOR.longValue() + " fail rule: " + failRule);
7175
});
7276
}
7377
}

0 commit comments

Comments
 (0)