View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0000009 | KafkaEsque | Improvement | public | 2018-11-25 22:06 | 2018-11-26 12:56 |
| Reporter | Oliver G. | Assigned To | patschuh | ||
| Priority | low | Severity | tweak | Reproducibility | always |
| Status | resolved | Resolution | fixed | ||
| Product Version | |||||
| Target Version | 0.12.0 | Fixed in Version | 0.12.0 | ||
| Summary | 0000009: Improve Error Alert for JSON Validation Errors | ||||
| Description | Show Message instead of RuntimeException and StackTrace. | ||||
| Tags | No tags attached. | ||||
|
Improved_Error_Alert_for_JSON_Validation.patch (7,214 bytes)
Index: src/main/java/com/modulo/kafkaesque/PublisherController.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/com/modulo/kafkaesque/PublisherController.java (revision 5403c717d55ee18a5cd03a66103c8b6db2aa29f5)
+++ src/main/java/com/modulo/kafkaesque/PublisherController.java (revision )
@@ -118,20 +118,29 @@
private boolean validateMessage(String key, String value) {
boolean result = true;
if (validateIsJsonKeyBox.isSelected()) {
- if (!JsonUtils.isJsonValid(key)) {
+ ValidationResult validationResult = JsonUtils.validate(key);
+
+ if (!validationResult.isValid()) {
result = false;
- ErrorAlert.show(new RuntimeException("key is not a valid json string"));
+ showError("key", validationResult);
}
}
if (validateIsJsonValueBox.isSelected()) {
- if (!JsonUtils.isJsonValid(value)) {
+ ValidationResult validationResult = JsonUtils.validate(value);
+
+ if (!validationResult.isValid()) {
result = false;
- ErrorAlert.show(new RuntimeException("value is not a valid json string"));
+ showError("value", validationResult);
}
}
return result;
}
+ private void showError(String inputName, ValidationResult validationResult) {
+ String message = String.format("%s is not a valid json String: %s ", inputName, validationResult.getValidationError());
+ ErrorAlert.show(new ValidationException(message), false);
+ }
+
@FXML
private void addHeaderClick(ActionEvent event) {
try {
Index: src/main/java/com/modulo/kafkaesque/alerts/ErrorAlert.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/com/modulo/kafkaesque/alerts/ErrorAlert.java (revision 5403c717d55ee18a5cd03a66103c8b6db2aa29f5)
+++ src/main/java/com/modulo/kafkaesque/alerts/ErrorAlert.java (revision )
@@ -10,34 +10,40 @@
import java.io.StringWriter;
public class ErrorAlert {
+
public static void show(Throwable ex){
+ show(ex,true);
+ }
+
+ public static void show(Throwable ex, boolean expandable) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(ex.getClass().getSimpleName());
alert.setHeaderText(ex.getClass().getName());
alert.setContentText(ex.getMessage());
Main.applyStylesheet(alert.getDialogPane().getScene());
-// Create expandable Exception.
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- ex.printStackTrace(pw);
- String exceptionText = sw.toString();
+ if (expandable) {
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ ex.printStackTrace(pw);
+ String exceptionText = sw.toString();
- TextArea textArea = new TextArea(exceptionText);
- textArea.setEditable(false);
- textArea.setWrapText(true);
+ TextArea textArea = new TextArea(exceptionText);
+ textArea.setEditable(false);
+ textArea.setWrapText(true);
- textArea.setMaxWidth(Double.MAX_VALUE);
- textArea.setMaxHeight(Double.MAX_VALUE);
- GridPane.setVgrow(textArea, Priority.ALWAYS);
- GridPane.setHgrow(textArea, Priority.ALWAYS);
+ textArea.setMaxWidth(Double.MAX_VALUE);
+ textArea.setMaxHeight(Double.MAX_VALUE);
+ GridPane.setVgrow(textArea, Priority.ALWAYS);
+ GridPane.setHgrow(textArea, Priority.ALWAYS);
- GridPane expContent = new GridPane();
- expContent.setMaxWidth(Double.MAX_VALUE);
- expContent.add(textArea, 0, 0);
+ GridPane expContent = new GridPane();
+ expContent.setMaxWidth(Double.MAX_VALUE);
+ expContent.add(textArea, 0, 0);
-// Set expandable Exception into the dialog pane.
- alert.getDialogPane().setExpandableContent(expContent);
+ // Set expandable Exception into the dialog pane.
+ alert.getDialogPane().setExpandableContent(expContent);
+ }
alert.showAndWait();
}
Index: src/main/java/com/modulo/kafkaesque/JsonUtils.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/com/modulo/kafkaesque/JsonUtils.java (revision 5403c717d55ee18a5cd03a66103c8b6db2aa29f5)
+++ src/main/java/com/modulo/kafkaesque/JsonUtils.java (revision )
@@ -8,16 +8,17 @@
private JsonUtils() {
}
- public static boolean isJsonValid(String jsonInString) {
+ public static ValidationResult validate(String jsonInString) {
if (jsonInString == null) {
- return true;
+ return new ValidationResult(true);
}
+
try {
final ObjectMapper mapper = new ObjectMapper();
mapper.readTree(jsonInString);
- return true;
+ return new ValidationResult(true);
} catch (IOException e) {
- return false;
+ return new ValidationResult(false, e.getMessage());
}
}
}
Index: src/main/java/com/modulo/kafkaesque/ValidationResult.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/com/modulo/kafkaesque/ValidationResult.java (revision )
+++ src/main/java/com/modulo/kafkaesque/ValidationResult.java (revision )
@@ -0,0 +1,26 @@
+package com.modulo.kafkaesque;
+
+public class ValidationResult {
+
+ private final boolean valid;
+
+ private final String validationError;
+
+ public ValidationResult(boolean valid) {
+ this.valid = valid;
+ this.validationError = null;
+ }
+
+ public ValidationResult(boolean valid, String validationError) {
+ this.valid = valid;
+ this.validationError = validationError;
+ }
+
+ public boolean isValid() {
+ return valid;
+ }
+
+ public String getValidationError() {
+ return validationError;
+ }
+}
Index: src/main/java/com/modulo/kafkaesque/ValidationException.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/com/modulo/kafkaesque/ValidationException.java (revision )
+++ src/main/java/com/modulo/kafkaesque/ValidationException.java (revision )
@@ -0,0 +1,8 @@
+package com.modulo.kafkaesque;
+
+public class ValidationException extends RuntimeException {
+
+ public ValidationException(String message) {
+ super(message);
+ }
+}
|
|
|
Reviewed and applied patch |
|
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2018-11-25 22:06 | Oliver G. | New Issue | |
| 2018-11-25 22:06 | Oliver G. | File Added: Improved_Error_Alert_for_JSON_Validation.patch | |
| 2018-11-26 06:39 | patschuh | Target Version | => 0.12.0 |
| 2018-11-26 06:39 | patschuh | Description Updated | View Revisions |
| 2018-11-26 12:55 | patschuh | Changeset attached | => KafkaEsque master 09dd8f5c |
| 2018-11-26 12:56 | patschuh | Assigned To | => patschuh |
| 2018-11-26 12:56 | patschuh | Status | new => resolved |
| 2018-11-26 12:56 | patschuh | Resolution | open => fixed |
| 2018-11-26 12:56 | patschuh | Fixed in Version | => 0.12.0 |
| 2018-11-26 12:56 | patschuh | Note Added: 0000008 |