This is an automated email from the ASF dual-hosted git repository.
zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new b8f20290561 Refactor FileIOException (#30340)
b8f20290561 is described below
commit b8f20290561740e3b13afec21f1a386bc0000fae
Author: Raigor <[email protected]>
AuthorDate: Wed Feb 28 17:24:01 2024 +0800
Refactor FileIOException (#30340)
* Refactor FileIOException
* Update error doc
---
docs/document/content/user-manual/error-code/sql-error-code.cn.md | 2 +-
docs/document/content/user-manual/error-code/sql-error-code.en.md | 2 +-
.../shardingsphere/proxy/backend/exception/FileIOException.java | 6 +++---
.../distsql/ral/queryable/ConvertYamlConfigurationExecutor.java | 4 ++--
.../distsql/ral/updatable/ImportDatabaseConfigurationExecutor.java | 4 ++--
.../handler/distsql/ral/updatable/ImportMetaDataExecutor.java | 4 ++--
.../org/apache/shardingsphere/proxy/backend/util/ExportUtils.java | 6 +++---
.../ral/queryable/ExportDatabaseConfigurationExecutorTest.java | 2 +-
8 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index 34a017e9b68..31b94c7c38c 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -105,7 +105,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| SQL State | Vendor Code | 错误信息
|
|-----------|-------------|-----------------------------------------------------|
| HY000 | 17000 | Work ID assigned failed, which can not exceed
1024. |
-| HY000 | 17002 | File access failed, reason is: %s
|
+| HY000 | 17002 | File access failed, file is: %s
|
| HY000 | 17010 | Cluster persist repository error, reason is: %s
|
### 迁移
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 679edc9a11a..75a77c5e0d4 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -105,7 +105,7 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| SQL State | Vendor Code | Reason
|
|-----------|-------------|-----------------------------------------------------|
| HY000 | 17000 | Work ID assigned failed, which can not exceed
1024. |
-| HY000 | 17002 | File access failed, reason is: %s
|
+| HY000 | 17002 | File access failed, file is: %s
|
| HY000 | 17010 | Cluster persist repository error, reason is: %s
|
### Migration
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/exception/FileIOException.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/exception/FileIOException.java
index fdf1876768e..972a92cd4e5 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/exception/FileIOException.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/exception/FileIOException.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.proxy.backend.exception;
import
org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
import
org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.ClusterSQLException;
-import java.io.IOException;
+import java.io.File;
/**
* File IO exception.
@@ -29,7 +29,7 @@ public final class FileIOException extends
ClusterSQLException {
private static final long serialVersionUID = 1104839422339487793L;
- public FileIOException(final IOException cause) {
- super(XOpenSQLState.GENERAL_ERROR, 2, "File access failed, reason is:
%s", cause.getMessage());
+ public FileIOException(final File file) {
+ super(XOpenSQLState.GENERAL_ERROR, 2, "File access failed, file is:
%s", file.getAbsolutePath());
}
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
index 9b68b1370bd..81e7210eabb 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationExecutor.java
@@ -69,8 +69,8 @@ public final class ConvertYamlConfigurationExecutor
implements DistSQLQueryExecu
YamlProxyDatabaseConfiguration yamlConfig;
try {
yamlConfig = YamlEngine.unmarshal(file,
YamlProxyDatabaseConfiguration.class);
- } catch (final IOException ex) {
- throw new FileIOException(ex);
+ } catch (final IOException ignore) {
+ throw new FileIOException(file);
}
Preconditions.checkNotNull(yamlConfig, "Invalid yaml file `%s`",
file.getName());
Preconditions.checkNotNull(yamlConfig.getDatabaseName(),
"`databaseName` in file `%s` is required.", file.getName());
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutor.java
index 4593a3b7fa8..f914fd98eca 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationExecutor.java
@@ -42,8 +42,8 @@ public final class ImportDatabaseConfigurationExecutor
implements DistSQLUpdateE
YamlProxyDatabaseConfiguration yamlConfig;
try {
yamlConfig = YamlEngine.unmarshal(file,
YamlProxyDatabaseConfiguration.class);
- } catch (final IOException ex) {
- throw new FileIOException(ex);
+ } catch (final IOException ignore) {
+ throw new FileIOException(file);
}
databaseConfigImportExecutor.importDatabaseConfiguration(yamlConfig);
}
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutor.java
index 94d03c81f0d..d4d317bd0fc 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportMetaDataExecutor.java
@@ -55,8 +55,8 @@ public final class ImportMetaDataExecutor implements
DistSQLUpdateExecutor<Impor
File file = new File(sqlStatement.getFilePath().get());
try {
jsonMetaDataConfig = FileUtils.readFileToString(file,
Charset.defaultCharset());
- } catch (final IOException ex) {
- throw new FileIOException(ex);
+ } catch (final IOException ignore) {
+ throw new FileIOException(file);
}
} else {
jsonMetaDataConfig = new
String(Base64.decodeBase64(sqlStatement.getMetaDataValue()));
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
index 6acff06f1a4..cec7854a721 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/util/ExportUtils.java
@@ -54,14 +54,14 @@ public final class ExportUtils {
@SuppressWarnings("ResultOfMethodCallIgnored")
public static void exportToFile(final String filePath, final String
exportedData) {
File file = new File(filePath);
- if (!file.exists()) {
+ if (!file.exists() && null != file.getParentFile()) {
file.getParentFile().mkdirs();
}
try (OutputStream output =
Files.newOutputStream(Paths.get(file.toURI()))) {
output.write(exportedData.getBytes());
output.flush();
- } catch (final IOException ex) {
- throw new FileIOException(ex);
+ } catch (final IOException ignore) {
+ throw new FileIOException(file);
}
}
diff --git
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java
index 7e54705b773..3393f7e8b04 100644
---
a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java
+++
b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ExportDatabaseConfigurationExecutorTest.java
@@ -143,7 +143,7 @@ class ExportDatabaseConfigurationExecutorTest {
BufferedReader reader = new BufferedReader(fileReader)) {
String line;
while (null != (line = reader.readLine())) {
- if (!line.startsWith("#") && !"".equals(line.trim())) {
+ if (!line.startsWith("#") && !line.trim().isEmpty()) {
result.append(line).append(System.lineSeparator());
}
}