Skip to content

Commit e02a499

Browse files
committed
Better (shorter) error message when handling invalid XML
1 parent d85922e commit e02a499

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

Diff for: .github/workflows/release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
workflow_dispatch:
55
inputs:
66
tag:
7+
description: tag
78
required: true
89

910
run-name: Native Images ${{ inputs.tag }} by @${{ github.actor }}

Diff for: umlet-cli/pom.xml

+11
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@
1414
</properties>
1515

1616
<artifactId>umlet</artifactId>
17+
<name>umlet-cli</name>
1718

1819
<dependencies>
1920
<dependency>
2021
<groupId>com.umlet</groupId>
2122
<artifactId>umlet-mini</artifactId>
2223
<version>${project.version}</version>
2324
</dependency>
25+
<dependency>
26+
<groupId>org.slf4j</groupId>
27+
<artifactId>slf4j-api</artifactId>
28+
<version>2.0.7</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>ch.qos.logback</groupId>
32+
<artifactId>logback-classic</artifactId>
33+
<version>1.4.7</version>
34+
</dependency>
2435
</dependencies>
2536

2637
<build>

Diff for: umlet-cli/src/main/java/io/kroki/umlet/UmletConverter.java

+16-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.baselet.control.util.Utils;
77
import com.baselet.diagram.DiagramHandler;
88
import com.baselet.diagram.io.OutputHandler;
9+
import org.xml.sax.SAXParseException;
910

1011
import java.io.BufferedReader;
1112
import java.io.ByteArrayOutputStream;
@@ -22,11 +23,20 @@ public class UmletConverter {
2223
}
2324

2425
public static byte[] convert(String source, String outputFormat) throws Exception {
25-
DiagramHandler handler = DiagramHandler.forExport(source);
26-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
27-
OutputHandler.createToStream(outputFormat, baos, handler);
28-
byte[] result = baos.toByteArray();
29-
handler.close();
30-
return result;
26+
try {
27+
DiagramHandler handler = DiagramHandler.forExport(source);
28+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
29+
OutputHandler.createToStream(outputFormat, baos, handler);
30+
byte[] result = baos.toByteArray();
31+
handler.close();
32+
return result;
33+
} catch (Exception e) {
34+
if (e instanceof RuntimeException && e.getCause() instanceof SAXParseException) {
35+
// gives a better error message when handling invalid XML
36+
// https://github.com/yuzutech/kroki/issues/1556
37+
throw new IllegalArgumentException(e.getCause().getMessage());
38+
}
39+
throw e;
40+
}
3141
}
3242
}

Diff for: umlet-cli/src/main/resources/logback.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE configuration>
3+
4+
<configuration>
5+
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
6+
<import class="ch.qos.logback.core.ConsoleAppender"/>
7+
8+
<appender name="STDOUT" class="ConsoleAppender">
9+
<encoder class="PatternLayoutEncoder">
10+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%kvp- %msg%n</pattern>
11+
</encoder>
12+
</appender>
13+
14+
<root level="WARN">
15+
<appender-ref ref="STDOUT"/>
16+
</root>
17+
</configuration>

0 commit comments

Comments
 (0)