Skip to content

Commit 3ed3409

Browse files
committed
detect non-Workflow CWL documents and give a better error message
1 parent 7fed9ae commit 3ed3409

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.commonwl.view.cwl;
21+
22+
/** Exception thrown when the provided CWL document is not a Workflow. */
23+
public class CWLNotAWorkflowException extends CWLValidationException {
24+
25+
public CWLNotAWorkflowException(String message) {
26+
super(message);
27+
}
28+
29+
public CWLNotAWorkflowException(Throwable throwable) {
30+
super(throwable);
31+
}
32+
33+
public CWLNotAWorkflowException(String message, Throwable throwable) {
34+
super(message, throwable);
35+
}
36+
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ public List<WorkflowOverview> getWorkflowOverviewsFromPacked(File packedFile) th
181181
* @return The constructed workflow object
182182
*/
183183
public Workflow parseWorkflowNative(
184-
InputStream workflowStream, String packedWorkflowId, String defaultLabel) throws IOException {
184+
InputStream workflowStream, String packedWorkflowId, String defaultLabel)
185+
throws IOException, WorkflowNotFoundException, CWLValidationException {
185186
// Parse file as yaml
186187
Map<String, Object> cwlFile = yamlStreamToJson(workflowStream);
187188

@@ -205,9 +206,11 @@ public Workflow parseWorkflowNative(
205206
}
206207
if (!found && !packedWorkflowId.isEmpty()) throw new WorkflowNotFoundException();
207208
}
208-
if (!found && extractProcess(cwlFile) == CWLProcess.WORKFLOW) {
209-
// Check the current json node is a workflow
209+
if (!found && (extractProcess(cwlFile) == CWLProcess.WORKFLOW)) {
210210
found = true;
211+
} else if (found && (extractProcess(cwlFile) != CWLProcess.WORKFLOW)) {
212+
throw new CWLNotAWorkflowException(
213+
"Not a 'class: Workflow' CWL document, is a " + extractProcess(cwlFile));
211214
}
212215
if (!found) {
213216
throw new WorkflowNotFoundException();
@@ -248,7 +251,7 @@ public Workflow parseWorkflowNative(
248251
* @return The constructed workflow object
249252
*/
250253
public Workflow parseWorkflowNative(Path workflowFile, String packedWorkflowId)
251-
throws IOException {
254+
throws IOException, WorkflowNotFoundException, CWLValidationException {
252255

253256
// Check file size limit before parsing
254257
long fileSizeBytes = Files.size(workflowFile);

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
import java.util.List;
3131
import org.apache.commons.lang.StringUtils;
3232
import org.commonwl.view.WebConfig;
33+
import org.commonwl.view.cwl.CWLNotAWorkflowException;
3334
import org.commonwl.view.cwl.CWLService;
3435
import org.commonwl.view.cwl.CWLToolStatus;
36+
import org.commonwl.view.cwl.CWLValidationException;
3537
import org.commonwl.view.git.GitDetails;
3638
import org.commonwl.view.graphviz.GraphVizService;
3739
import org.eclipse.jgit.api.errors.GitAPIException;
@@ -163,6 +165,10 @@ public ModelAndView createWorkflow(
163165
logger.warn("git.notFound " + workflowForm, ex);
164166
bindingResult.rejectValue("url", "git.notFound");
165167
return new ModelAndView("index");
168+
} catch (CWLNotAWorkflowException ex) {
169+
logger.warn("cwl.notAWorkflow " + workflowForm, ex);
170+
bindingResult.rejectValue("url", "cwl.notAWorkflow");
171+
return new ModelAndView("index");
166172
} catch (Exception ex) {
167173
logger.warn("url.parsingError " + workflowForm, ex);
168174
bindingResult.rejectValue("url", "url.parsingError");
@@ -629,7 +635,11 @@ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redir
629635
} catch (WorkflowNotFoundException ex) {
630636
logger.warn("git.notFound " + workflowForm, ex);
631637
errors.rejectValue(
632-
"url", "git.notFound", "The workflow could not be found within the repository");
638+
"url", "git.notFound", "The workflow could not be found within the repository.");
639+
} catch (CWLValidationException ex) {
640+
logger.warn("cwl.invalid " + workflowForm, ex);
641+
errors.rejectValue(
642+
"url", "cwl.invalid", "The workflow had a parsing error: " + ex.getMessage());
633643
} catch (IOException ex) {
634644
logger.warn("url.parsingError " + workflowForm, ex);
635645
errors.rejectValue(
@@ -658,7 +668,8 @@ private ModelAndView getWorkflow(GitDetails gitDetails, RedirectAttributes redir
658668
}
659669
}
660670

661-
private Resource getGraphFromInputStream(InputStream in, String format) throws IOException {
671+
private Resource getGraphFromInputStream(InputStream in, String format)
672+
throws IOException, WorkflowNotFoundException, CWLValidationException {
662673
Workflow workflow =
663674
cwlService.parseWorkflowNative(in, null, "workflow"); // first workflow will do
664675
InputStream out = graphVizService.getGraphStream(workflow.getVisualisationDot(), format);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.commonwl.view.cwl.CWLService;
3434
import org.commonwl.view.cwl.CWLToolRunner;
3535
import org.commonwl.view.cwl.CWLToolStatus;
36+
import org.commonwl.view.cwl.CWLValidationException;
3637
import org.commonwl.view.git.GitDetails;
3738
import org.commonwl.view.git.GitSemaphore;
3839
import org.commonwl.view.git.GitService;
@@ -308,7 +309,7 @@ public File getROBundle(GitDetails gitDetails) throws ROBundleNotFoundException
308309
* @throws IOException Other file handling exceptions
309310
*/
310311
public QueuedWorkflow createQueuedWorkflow(GitDetails gitInfo)
311-
throws GitAPIException, WorkflowNotFoundException, IOException {
312+
throws GitAPIException, WorkflowNotFoundException, IOException, CWLValidationException {
312313
QueuedWorkflow queuedWorkflow;
313314

314315
Git repo = null;
@@ -338,7 +339,7 @@ public QueuedWorkflow createQueuedWorkflow(GitDetails gitInfo)
338339

339340
// Check workflow is readable
340341
if (!Files.isReadable(workflowFile)) {
341-
throw new WorkflowNotFoundException();
342+
throw new WorkflowNotFoundException("Unable to read workflow file on disk.");
342343
}
343344

344345
// Handling of packed workflows

src/main/resources/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,8 @@ git.retrievalError = The workflow could not be retrieved from the Git repository
66
git.notFound = The workflow could not be found within the repository
77
git.sshError = SSH URLs are not supported, please provide a HTTPS URL for the repository or submodules
88

9+
cwl.invalid = An error with the CWL workflow itself
10+
cwl.notAWorkflow = The provided CWL document is not a "class: Workflow" file.
11+
912
url.parsingError = An unexpected error occurred when parsing the workflow
1013
url.noWorkflowsInDirectory = No workflow files were found in the given directory

0 commit comments

Comments
 (0)