Skip to content

Commit 00fcdcf

Browse files
authored
chore: improve json process error log (#209)
* chore: improve json process error log * chore: fix github CI/CD for mongo
1 parent db9828a commit 00fcdcf

4 files changed

Lines changed: 8 additions & 8 deletions

File tree

.github/workflows/maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
cache: 'maven'
3838

3939
- name: Start MongoDB
40-
uses: supercharge/mongodb-github-action@1.11.0
40+
uses: supercharge/mongodb-github-action@1.12.1
4141
with:
4242
mongodb-version: '7.0'
4343
mongodb-replica-set: rs0

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.github.thunderz99</groupId>
55
<artifactId>java-cosmos</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.8.24</version>
7+
<version>0.8.25</version>
88
<name>${project.groupId}:${project.artifactId}$</name>
99
<description>A lightweight Azure CosmosDB client for Java</description>
1010
<url>https://github.com/thunderz99/java-cosmos</url>

src/main/java/io/github/thunderz99/cosmos/util/JsonUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,9 @@ public static <T> T fromMap(Map<String, Object> map, Class<T> classOfT) {
476476
}
477477

478478
private static void processException(Object object, Exception e) {
479-
log.warn("json process error. e = \n{}", exceptionToString(e));
480-
log.warn("json process error. object = {}", object);
481-
throw new IllegalArgumentException("json process error.", e);
479+
log.warn("json process error. object = {}", object, e);
480+
String detail = e.getMessage() == null ? e.getClass().getName() : e.getMessage();
481+
throw new IllegalArgumentException("json process error: " + detail, e);
482482
}
483483

484484
static String exceptionToString(Throwable throwable) {
@@ -509,4 +509,4 @@ public static ObjectMapper getObjectMapper() {
509509
return newObjectMapper();
510510
}
511511

512-
}
512+
}

src/test/java/io/github/thunderz99/cosmos/util/JsonUtilTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void shouldBeError() {
9696
var json = "{\"id\":1, \"name\":}";
9797
assertThatThrownBy(() -> JsonUtil.fromJson(json, Data.class))
9898
.isInstanceOf(IllegalArgumentException.class)
99-
.hasMessage("json process error.");
99+
.hasMessageStartingWith("json process error: Unexpected character");
100100
}
101101

102102
@Test
@@ -116,4 +116,4 @@ void exceptionToStringShouldBeOk() {
116116
assertThat(JsonUtil.exceptionToString(ex)).startsWith("java.security.InvalidParameterException: invalid parameter\n" +
117117
"\tat io.github.thunderz99.cosmos.util.JsonUtilTest.exceptionToStringShouldBeOk(JsonUtilTest.java:115)");
118118
}
119-
}
119+
}

0 commit comments

Comments
 (0)