Skip to content

Commit 564dbf3

Browse files
committed
Improve error handling
1 parent 660ad2d commit 564dbf3

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

src/main/java/org/commonwl/view/cwl/CWLService.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.commonwl.view.graphviz.ModelDotWriter;
4040
import org.commonwl.view.graphviz.RDFDotWriter;
4141
import org.commonwl.view.workflow.Workflow;
42+
import org.commonwl.view.workflow.WorkflowNotFoundException;
4243
import org.commonwl.view.workflow.WorkflowOverview;
4344
import org.slf4j.Logger;
4445
import org.slf4j.LoggerFactory;
@@ -169,19 +170,30 @@ public Workflow parseWorkflowNative(File workflowFile, String packedWorkflowId)
169170
// Parse file as yaml
170171
JsonNode cwlFile = yamlStringToJson(readFileToString(workflowFile));
171172

173+
// Check packed workflow occurs
172174
if (packedWorkflowId != null) {
173-
for (JsonNode jsonNode : cwlFile.get(DOC_GRAPH)) {
174-
if (extractProcess(jsonNode) == CWLProcess.WORKFLOW) {
175-
String currentId = jsonNode.get(ID).asText();
176-
if (currentId.startsWith("#")) {
177-
currentId = currentId.substring(1);
178-
}
179-
if (currentId.equals(packedWorkflowId)) {
180-
cwlFile = jsonNode;
181-
break;
175+
boolean found = false;
176+
if (cwlFile.has(DOC_GRAPH)) {
177+
for (JsonNode jsonNode : cwlFile.get(DOC_GRAPH)) {
178+
if (extractProcess(jsonNode) == CWLProcess.WORKFLOW) {
179+
String currentId = jsonNode.get(ID).asText();
180+
if (currentId.startsWith("#")) {
181+
currentId = currentId.substring(1);
182+
}
183+
if (currentId.equals(packedWorkflowId)) {
184+
cwlFile = jsonNode;
185+
found = true;
186+
break;
187+
}
182188
}
183189
}
184190
}
191+
if (!found) throw new WorkflowNotFoundException();
192+
} else {
193+
// Check the current json node is a workflow
194+
if (extractProcess(cwlFile) != CWLProcess.WORKFLOW) {
195+
throw new WorkflowNotFoundException();
196+
}
185197
}
186198

187199
// Use filename for label if there is no defined one

src/main/java/org/commonwl/view/cwl/CWLToolRunner.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.commonwl.view.cwl;
2121

22+
import org.apache.jena.query.QueryException;
2223
import org.commonwl.view.researchobject.ROBundleFactory;
2324
import org.commonwl.view.workflow.QueuedWorkflow;
2425
import org.commonwl.view.workflow.QueuedWorkflowRepository;
@@ -88,19 +89,22 @@ public void createWorkflowFromQueued(QueuedWorkflow queuedWorkflow, File workflo
8889

8990
// Mark success on queue
9091
queuedWorkflow.setCwltoolStatus(CWLToolStatus.SUCCESS);
91-
queuedWorkflowRepository.save(queuedWorkflow);
9292

93+
} catch (QueryException ex) {
94+
logger.error("Jena query exception ", ex);
95+
queuedWorkflow.setCwltoolStatus(CWLToolStatus.ERROR);
96+
queuedWorkflow.setMessage("An error occurred when executing a query on the SPARQL store");
9397
} catch (CWLValidationException ex) {
9498
logger.error(ex.getMessage(), ex);
9599
queuedWorkflow.setCwltoolStatus(CWLToolStatus.ERROR);
96100
queuedWorkflow.setMessage(ex.getMessage());
97-
queuedWorkflowRepository.save(queuedWorkflow);
98101
} catch (Exception ex) {
99102
logger.error("Unexpected error", ex);
100103
queuedWorkflow.setCwltoolStatus(CWLToolStatus.ERROR);
101104
queuedWorkflow.setMessage("Whoops! Cwltool ran successfully, but an unexpected " +
102105
"error occurred in CWLViewer!\n" +
103106
"Help us by reporting it on Gitter or a Github issue\n");
107+
} finally {
104108
queuedWorkflowRepository.save(queuedWorkflow);
105109
}
106110

src/main/java/org/commonwl/view/workflow/WorkflowController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redir
506506
logger.warn("git.notFound " + workflowForm, ex);
507507
errors.rejectValue("url", "git.notFound", "The workflow could not be found within the repository");
508508
} catch (IOException ex) {
509-
logger.warn("git.parsingError " + workflowForm, ex);
509+
logger.warn("url.parsingError " + workflowForm, ex);
510510
errors.rejectValue("url", "url.parsingError", "The workflow could not be parsed from the given URL");
511511
}
512512
}

0 commit comments

Comments
 (0)