terrymanu commented on code in PR #30900:
URL: https://github.com/apache/shardingsphere/pull/30900#discussion_r1566753404
##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java:
##########
@@ -66,7 +69,14 @@ public Object getValue(final int columnIndex, final Class<?>
type) throws SQLExc
EncryptColumn encryptColumn =
encryptRule.getEncryptTable(originalTableName).getEncryptColumn(originalColumnName);
String schemaName =
selectStatementContext.getTablesContext().getSchemaName().orElseGet(() -> new
DatabaseTypeRegistry(selectStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName()));
- return encryptColumn.getCipher().decrypt(database.getName(),
schemaName, originalTableName, originalColumnName, cipherValue);
+ try {
+ return encryptColumn.getCipher().decrypt(database.getName(),
schemaName, originalTableName, originalColumnName, cipherValue);
+ // CHECKSTYLE:OFF
+ } catch (final Exception ex) {
+ // CHECKSTYLE:ON
+ log.error("Failed to decrypt the ciphertext '{}' in the column
'{}' of table '{}'.", cipherValue, originalColumnName, originalTableName, ex);
Review Comment:
If exception thrown, the log maybe unnecessary.
##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/exception/data/DecryptFailedException.java:
##########
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.encrypt.exception.data;
+
+import org.apache.shardingsphere.encrypt.exception.EncryptSQLException;
+import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
+
+/**
+ * Decrypt failed exception.
+ */
+public final class DecryptFailedException extends EncryptSQLException {
+
+ private static final long serialVersionUID = 1122241238288845667L;
+
+ public DecryptFailedException(final String ciphertext, final String
column, final String table) {
Review Comment:
How about use SQLExceptionIdentifier to instead of column and table?
##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/merge/dql/EncryptMergedResult.java:
##########
@@ -66,7 +69,14 @@ public Object getValue(final int columnIndex, final Class<?>
type) throws SQLExc
EncryptColumn encryptColumn =
encryptRule.getEncryptTable(originalTableName).getEncryptColumn(originalColumnName);
String schemaName =
selectStatementContext.getTablesContext().getSchemaName().orElseGet(() -> new
DatabaseTypeRegistry(selectStatementContext.getDatabaseType()).getDefaultSchemaName(database.getName()));
- return encryptColumn.getCipher().decrypt(database.getName(),
schemaName, originalTableName, originalColumnName, cipherValue);
+ try {
+ return encryptColumn.getCipher().decrypt(database.getName(),
schemaName, originalTableName, originalColumnName, cipherValue);
+ // CHECKSTYLE:OFF
+ } catch (final Exception ex) {
Review Comment:
Can one or more specific exceptions be thrown?
##########
docs/document/content/user-manual/error-code/sql-error-code.cn.md:
##########
@@ -223,6 +223,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 21004 | HY000 | '%s' column's encrypt algorithm '%s' should
support %s in database '%s'. |
| 21010 | 44000 | Altered column '%s' must use same encrypt
algorithm with previous column '%s' in table '%s'. |
| 21020 | 0A000 | The SQL clause '%s' is unsupported in encrypt
feature. |
+| 21030 | 22000 | Failed to decrypt the ciphertext '%s' in the
column '%s' of table '%s'. |
Review Comment:
Please add to en docs too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]