Skip to content

Commit 24d041d

Browse files
committed
Handle errors in CSAR generation
1 parent 6f2836f commit 24d041d

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

ToscaDesigner/src/main/java/fr/softeam/toscadesigner/export/AbstractToscaFileGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ private Handlebars setupHandlebars() {
7070
TNodeTemplate node = tRequirement.getNode();
7171
propertyStringValue = node != null ? node.getName() : "''";
7272
} else if (searchedPropertyName.equals("capability")) {
73-
propertyStringValue = tRequirement.getCapability().getElement().getName();
73+
fr.softeam.toscadesigner.api.tosca.standard.class_.TCapabilityDefinition capability = tRequirement.getCapability();
74+
propertyStringValue = capability != null ? capability.getElement().getName() : "";
7475
}
7576
} else if (stereotype.getName().equals("TRequirementDefinition")) {
7677

@@ -79,7 +80,8 @@ private Handlebars setupHandlebars() {
7980
if (searchedPropertyName.equals("node")) {
8081
propertyStringValue = tRequirementDefinition.getNodeType().getName();
8182
} else if (searchedPropertyName.equals("capability")) {
82-
propertyStringValue = tRequirementDefinition.getCapability().getElement().getName();
83+
fr.softeam.toscadesigner.api.tosca.standard.class_.TCapabilityDefinition capability = tRequirementDefinition.getCapability();
84+
propertyStringValue = capability.getElement().getName();
8385
} else if (searchedPropertyName.equals("relationshipType")) {
8486
propertyStringValue = tRequirementDefinition.getRelationshipType().getElement().getName();
8587
} else if (searchedPropertyName.equals("lowerBound")) {

ToscaDesigner/src/main/java/fr/softeam/toscadesigner/export/ToscaFileGenerator.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import org.modelio.api.module.context.log.ILogService;
99
import org.modelio.vcore.smkernel.mapi.MObject;
1010

11+
import com.github.jknack.handlebars.HandlebarsException;
12+
1113
class ToscaFileGenerator extends AbstractToscaFileGenerator {
1214
private static final String[] TOSCA_FILE_EXTENSIONS = { "*.tosca" };
1315
private ILogService logger;
@@ -39,7 +41,15 @@ public void generateContent(MObject object) throws IOException {
3941
logger.error(ex);
4042
MessageDialog.openError(Display.getCurrent().getActiveShell(), getFileType() + " export error",
4143
ex.getLocalizedMessage());
42-
}
44+
} catch (HandlebarsException ex) {
45+
logger.error(ex);
46+
MessageDialog.openError(Display.getCurrent().getActiveShell(), "Handlebars Error",
47+
"An error occurred while rendering the Handlebars template: " + ex.getMessage());
48+
} catch (NullPointerException ex) {
49+
logger.error(ex);
50+
MessageDialog.openError(Display.getCurrent().getActiveShell(), "NullPointerException",
51+
"A NullPointerException occurred. See log for details.");
52+
}
4353
}
4454
}
4555

7.52 KB
Binary file not shown.
7.73 KB
Binary file not shown.

0 commit comments

Comments
 (0)