You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/02/28 07:43:38 UTC
[GitHub] [shardingsphere] GLBB opened a new issue #9527: Exception message more detail
GLBB opened a new issue #9527:
URL: https://github.com/apache/shardingsphere/issues/9527
using yaml configuration, get exception message: "Exception in thread "main" java.lang.IllegalArgumentException: argument type mismatch", yaml has many lines and element, don't known which has error, hope has more detail exception, can know which line, column, element has error.
![image](https://user-images.githubusercontent.com/24810876/109411147-e19e2000-79da-11eb-95ad-1f45d92667e3.png)
my yaml configuration:
```
dataSources:
ds_0:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_0?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: xxx
password: 123
autoCommit: false
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/demo_ds_1?serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=UTF-8
username: xxx
password: 123
autoCommit: false
rules:
- !SHARDING
tables:
t_order:
actualDataNodes: ds_${0..1}.t_order_${0..1}
tableStrategy:
standard:
shardingColumn: order_id
shardingAlgorithmName: table_inline
keyGenerateStrategy:
column: order_id
keyGeneratorName: snowflake
defaultDatabaseStrategy:
standard:
shardingColumn: user_id
shardingAlgorithmName: database_inline
defaultTableStrategy:
none:
shardingAlgorithms:
database_inline:
type: INLINE
props:
algorithm-expression: ds_${user_id % 2}
table_inline:
type: INLINE
props:
algorithm-expression: t_order_${order_id % 2}
keyGenerators:
snowflake:
type: SNOWFLAKE
props:
worker-id: 123
props:
sql-show: false
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] GLBB edited a comment on issue #9527: Exception message more detail
Posted by GitBox <gi...@apache.org>.
GLBB edited a comment on issue #9527:
URL: https://github.com/apache/shardingsphere/issues/9527#issuecomment-789031303
hi, I have saw code.
in situation 1, cause by `setterMethod.get().invoke(result, entry.getValue());`, password type expect string type, I give integer type, my solution is when occur IllegalArgumentException, exception message contains yaml properties name.
occur exception code as follow:
```
/**
* Create data source.
*
* @return data source
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@SneakyThrows(ReflectiveOperationException.class)
public DataSource createDataSource() {
DataSource result = (DataSource) Class.forName(dataSourceClassName).getConstructor().newInstance();
Method[] methods = result.getClass().getMethods();
for (Entry<String, Object> entry : props.entrySet()) {
if (SKIPPED_PROPERTY_NAMES.contains(entry.getKey())) {
continue;
}
Optional<Method> setterMethod = findSetterMethod(methods, entry.getKey());
if (setterMethod.isPresent()) {
setterMethod.get().invoke(result, entry.getValue());
}
}
Optional<JDBCParameterDecorator> decorator = findJDBCParameterDecorator(result);
return decorator.isPresent() ? decorator.get().decorate(result) : result;
}
```
I want modify to:
```
@SuppressWarnings({"unchecked", "rawtypes"})
@SneakyThrows(ReflectiveOperationException.class)
public DataSource createDataSource() {
DataSource result = (DataSource) Class.forName(dataSourceClassName).getConstructor().newInstance();
Method[] methods = result.getClass().getMethods();
for (Entry<String, Object> entry : props.entrySet()) {
if (SKIPPED_PROPERTY_NAMES.contains(entry.getKey())) {
continue;
}
Optional<Method> setterMethodOpt = findSetterMethod(methods, entry.getKey());
setterMethodOpt.map(method -> setDataSourceProperty(result, method, entry.getValue(), entry.getKey()));
}
Optional<JDBCParameterDecorator> decorator = findJDBCParameterDecorator(result);
return decorator.isPresent() ? decorator.get().decorate(result) : result;
}
@SneakyThrows(ReflectiveOperationException.class)
private Void setDataSourceProperty(DataSource result, Method method, Object value, String propertyName) {
try {
method.invoke(result, value);
return null;
} catch (IllegalArgumentException ex) {
throw new ShardingSphereConfigurationException(ex, String.format("property %s configure error", propertyName));
}
}
-----------------------add ShardingSphereConfigurationException constructer -----------------------------
public ShardingSphereConfigurationException(final Exception cause, final String errorMessage) {
super(errorMessage, cause);
}
```
situation 2, I want to set origin cause exception look like more clear.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] GLBB commented on issue #9527: Exception message more detail
Posted by GitBox <gi...@apache.org>.
GLBB commented on issue #9527:
URL: https://github.com/apache/shardingsphere/issues/9527#issuecomment-789031303
hi, I have saw code.
in situation 1, cause by `setterMethod.get().invoke(result, entry.getValue());`, password type expect string type, I give integer type, my solution is when occur IllegalArgumentException, exception message contains yaml properties name.
occur exception code as follow:
```
/**
* Create data source.
*
* @return data source
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@SneakyThrows(ReflectiveOperationException.class)
public DataSource createDataSource() {
DataSource result = (DataSource) Class.forName(dataSourceClassName).getConstructor().newInstance();
Method[] methods = result.getClass().getMethods();
for (Entry<String, Object> entry : props.entrySet()) {
if (SKIPPED_PROPERTY_NAMES.contains(entry.getKey())) {
continue;
}
Optional<Method> setterMethod = findSetterMethod(methods, entry.getKey());
if (setterMethod.isPresent()) {
setterMethod.get().invoke(result, entry.getValue());
}
}
Optional<JDBCParameterDecorator> decorator = findJDBCParameterDecorator(result);
return decorator.isPresent() ? decorator.get().decorate(result) : result;
}
```
I want modify to:
```
@SuppressWarnings({"unchecked", "rawtypes"})
@SneakyThrows(ReflectiveOperationException.class)
public DataSource createDataSource() {
DataSource result = (DataSource) Class.forName(dataSourceClassName).getConstructor().newInstance();
Method[] methods = result.getClass().getMethods();
for (Entry<String, Object> entry : props.entrySet()) {
if (SKIPPED_PROPERTY_NAMES.contains(entry.getKey())) {
continue;
}
Optional<Method> setterMethodOpt = findSetterMethod(methods, entry.getKey());
setterMethodOpt.map(method -> setDataSourceProperty(result, method, entry.getValue(), entry.getKey()));
}
Optional<JDBCParameterDecorator> decorator = findJDBCParameterDecorator(result);
return decorator.isPresent() ? decorator.get().decorate(result) : result;
}
@SneakyThrows(ReflectiveOperationException.class)
private Void setDataSourceProperty(DataSource result, Method method, Object value, String propertyName) {
try {
method.invoke(result, value);
return null;
} catch (IllegalArgumentException ex) {
throw new ShardingSphereConfigurationException(ex, String.format("property %s configure error", propertyName));
}
}
public ShardingSphereConfigurationException(final Exception cause, final String errorMessage) {
super(errorMessage, cause);
}
```
situation 2, I want to set origin cause exception look like more clear.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] GLBB commented on issue #9527: Exception message more detail
Posted by GitBox <gi...@apache.org>.
GLBB commented on issue #9527:
URL: https://github.com/apache/shardingsphere/issues/9527#issuecomment-789817697
https://github.com/apache/shardingsphere/pull/9583
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] tristaZero commented on issue #9527: Exception message more detail
Posted by GitBox <gi...@apache.org>.
tristaZero commented on issue #9527:
URL: https://github.com/apache/shardingsphere/issues/9527#issuecomment-789416062
Hi @devfat ,
Thanks for your comment. Yep, the programming is correct, and there is no bug, so I define this issue as a to-enhance or to-improve one.
@GLBB The solution looks just requiring a little change. Could you raise a PR for that? Plus, it is better to add a unit test for it.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] tristaZero commented on issue #9527: Exception message more detail
Posted by GitBox <gi...@apache.org>.
tristaZero commented on issue #9527:
URL: https://github.com/apache/shardingsphere/issues/9527#issuecomment-787615085
Hi @GLBB ,
Thanks for your feedback.
I agree to throw the explicit exception to users. Do you have any solution for this enhancement?
We welcome the community to give it an improvement.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] GLBB closed issue #9527: Exception message more detail
Posted by GitBox <gi...@apache.org>.
GLBB closed issue #9527:
URL: https://github.com/apache/shardingsphere/issues/9527
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] devfat commented on issue #9527: Exception message more detail
Posted by GitBox <gi...@apache.org>.
devfat commented on issue #9527:
URL: https://github.com/apache/shardingsphere/issues/9527#issuecomment-788803604
In code respect, the code on `org/apache/shardingsphere/sharding/rule/single/SingleTableRuleLoader.java:65` is
`throw new ShardingSphereConfigurationException("Can not load table: ", ex.getMessage());`.
`ex.getMessage()` is return `java.lang.Throwable#detailMessage` , it looks right.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org