Skip to content

Commit c6d4da3

Browse files
committed
improve exception reporting
1 parent d5e1f5b commit c6d4da3

File tree

6 files changed

+98
-21
lines changed

6 files changed

+98
-21
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,9 @@ private String extractDoc(Map<String, Object> cwlFile) {
965965
if (cwlFile != null) {
966966
if (cwlFile.containsKey(DOC)) {
967967
Object doc = cwlFile.get(DOC);
968+
if (doc == null) {
969+
return null;
970+
}
968971
if (doc.getClass().isAssignableFrom(String.class)) {
969972
return (String) doc;
970973
}

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

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import org.commonwl.view.workflow.Workflow;
3434
import org.commonwl.view.workflow.WorkflowRepository;
3535
import org.eclipse.jgit.api.Git;
36+
import org.eclipse.jgit.api.errors.TransportException;
37+
import org.eclipse.jgit.errors.MissingObjectException;
3638
import org.slf4j.Logger;
3739
import org.slf4j.LoggerFactory;
3840
import org.springframework.beans.factory.annotation.Autowired;
@@ -105,22 +107,66 @@ public void createWorkflowFromQueued(QueuedWorkflow queuedWorkflow)
105107
queuedWorkflow.setCwltoolStatus(CWLToolStatus.SUCCESS);
106108

107109
} catch (QueryException ex) {
108-
logger.error("Jena query exception ", ex);
110+
logger.error("Jena query exception for workflow " + queuedWorkflow.getId(), ex);
109111
queuedWorkflow.setCwltoolStatus(CWLToolStatus.ERROR);
110112
queuedWorkflow.setMessage("An error occurred when executing a query on the SPARQL store");
111113
FileUtils.deleteGitRepository(repo);
112114
} catch (CWLValidationException ex) {
113-
logger.error(ex.getMessage(), ex);
115+
String message = ex.getMessage();
116+
logger.error(
117+
"Workflow " + queuedWorkflow.getId() + " from " + gitInfo.toSummary() + " : " + message,
118+
ex);
114119
queuedWorkflow.setCwltoolStatus(CWLToolStatus.ERROR);
115-
queuedWorkflow.setMessage(ex.getMessage());
120+
queuedWorkflow.setMessage(message);
121+
FileUtils.deleteGitRepository(repo);
122+
} catch (TransportException ex) {
123+
String message = ex.getMessage();
124+
logger.error(
125+
"Workflow retrieval error while processing "
126+
+ queuedWorkflow.getId()
127+
+ " from "
128+
+ gitInfo.toSummary()
129+
+ " : "
130+
+ message,
131+
ex);
132+
queuedWorkflow.setCwltoolStatus(CWLToolStatus.ERROR);
133+
if (message.contains(
134+
"Authentication is required but no CredentialsProvider has been registered")) {
135+
queuedWorkflow.setMessage(
136+
"Unable to retrieve the Git repository: it may be private, misnamed, or removed. "
137+
+ message);
138+
} else {
139+
queuedWorkflow.setMessage(message);
140+
}
141+
FileUtils.deleteGitRepository(repo);
142+
} catch (MissingObjectException ex) {
143+
String message = ex.getMessage();
144+
logger.error(
145+
"Workflow retrieval error while processing "
146+
+ queuedWorkflow.getId()
147+
+ " from "
148+
+ gitInfo.toSummary()
149+
+ " : "
150+
+ message,
151+
ex);
152+
queuedWorkflow.setCwltoolStatus(CWLToolStatus.ERROR);
153+
queuedWorkflow.setMessage("Unable to retrieve a needed Git object: " + message);
116154
FileUtils.deleteGitRepository(repo);
117155
} catch (Exception ex) {
118-
logger.error("Unexpected error", ex);
156+
logger.error(
157+
"Unexpected error processing workflow "
158+
+ queuedWorkflow.getId()
159+
+ " from "
160+
+ gitInfo.toSummary()
161+
+ " : "
162+
+ ex.getMessage(),
163+
ex);
119164
queuedWorkflow.setCwltoolStatus(CWLToolStatus.ERROR);
120165
queuedWorkflow.setMessage(
121166
"Whoops! Cwltool ran successfully, but an unexpected "
122167
+ "error occurred in CWLViewer!\n"
123-
+ "Help us by reporting it on Gitter or a Github issue\n");
168+
+ ex.getMessage()
169+
+ "\nHelp us by reporting it at https://github.com/common-workflow-language/cwlviewer/issues/new/choose\n");
124170
FileUtils.deleteGitRepository(repo);
125171
} finally {
126172
gitSemaphore.release(repoUrl);

src/main/java/org/commonwl/view/git/GitDetails.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,9 @@ public boolean equals(Object o) {
271271
public int hashCode() {
272272
return Objects.hash(repoUrl, branch, path, packedId);
273273
}
274+
275+
public String toSummary() {
276+
return String.format(
277+
"repoUrl: %s branch: %s path: %s packedId: %s", repoUrl, branch, path, packedId);
278+
}
274279
}

src/main/java/org/commonwl/view/researchobject/ROBundleFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public ROBundleFactory(ROBundleService roBundleService, WorkflowRepository workf
6363
*/
6464
@Async
6565
public void createWorkflowRO(Workflow workflow) throws IOException, InterruptedException {
66-
logger.info("Creating Research Object Bundle");
66+
logger.info("Creating Research Object Bundle for workflow " + workflow.getID());
6767

6868
// Get the whole containing folder, not just the workflow itself
6969
GitDetails githubInfo = workflow.getRetrievedFrom();
@@ -91,6 +91,6 @@ public void createWorkflowRO(Workflow workflow) throws IOException, InterruptedE
9191
// Add RO Bundle to associated workflow model
9292
workflow.setRoBundlePath(bundleLocation.toString());
9393
workflowRepository.save(workflow);
94-
logger.info("Finished saving Research Object Bundle");
94+
logger.info("Finished saving Research Object Bundle for workflow " + workflow.getID());
9595
}
9696
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@
2424

2525
/** Exception thrown when a workflow ID does not exist */
2626
@ResponseStatus(value = HttpStatus.NOT_FOUND)
27-
public class WorkflowNotFoundException extends RuntimeException {}
27+
public class WorkflowNotFoundException extends RuntimeException {
28+
29+
public WorkflowNotFoundException(String message) {
30+
super(message);
31+
}
32+
33+
public WorkflowNotFoundException() {
34+
super();
35+
}
36+
}

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

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ public QueuedWorkflow createQueuedWorkflow(GitDetails gitInfo)
343343
List<WorkflowOverview> overviews =
344344
cwlService.getWorkflowOverviewsFromPacked(workflowFile.toFile());
345345
if (overviews.size() == 0) {
346-
throw new IOException("No workflow was found within the packed CWL file");
346+
throw new IOException(
347+
"No workflow was found within the packed CWL file. " + gitInfo.toSummary());
347348
} else {
348349
// Dummy queued workflow object to return the list
349350
QueuedWorkflow overviewList = new QueuedWorkflow();
@@ -375,14 +376,14 @@ public QueuedWorkflow createQueuedWorkflow(GitDetails gitInfo)
375376
try {
376377
cwlToolRunner.createWorkflowFromQueued(queuedWorkflow);
377378
} catch (Exception e) {
378-
logger.error("Could not update workflow with cwltool", e);
379+
logger.error("Could not update workflow with cwltool: " + gitInfo.toSummary(), e);
379380
}
380381

381382
} catch (GitAPIException | RuntimeException | IOException e) {
382383
logger.warn(
383384
String.format(
384-
"Failed to create Queued Workflow: %s - Temporary files will be deleted",
385-
e.getMessage()),
385+
"Failed to create Queued Workflow: %s - Temporary files will be deleted for %s.",
386+
e.getMessage(), gitInfo.toSummary()),
386387
e);
387388
FileUtils.deleteGitRepository(repo);
388389
throw e;
@@ -406,7 +407,7 @@ public void retryCwltool(QueuedWorkflow queuedWorkflow) {
406407
try {
407408
cwlToolRunner.createWorkflowFromQueued(queuedWorkflow);
408409
} catch (Exception e) {
409-
logger.error("Could not update workflow with cwltool", e);
410+
logger.error("Could not update workflow " + queuedWorkflow.getId() + " with cwltool.", e);
410411
}
411412
}
412413

@@ -481,13 +482,14 @@ public PathResource getWorkflowGraph(String format, GitDetails gitDetails)
481482
extension = "dot";
482483
break;
483484
default:
484-
throw new WorkflowNotFoundException();
485+
throw new WorkflowNotFoundException("Format " + format + " not recognized.");
485486
}
486487

487488
// Get workflow
488489
Workflow workflow = getWorkflow(gitDetails);
489490
if (workflow == null) {
490-
throw new WorkflowNotFoundException();
491+
throw new WorkflowNotFoundException(
492+
"Unable to retrieve workflow for " + gitDetails.toSummary());
491493
}
492494

493495
// Generate graph and serve the file
@@ -506,7 +508,9 @@ private void generateROBundle(Workflow workflow) {
506508
try {
507509
ROBundleFactory.createWorkflowRO(workflow);
508510
} catch (Exception ex) {
509-
logger.error("Error creating RO Bundle", ex);
511+
logger.error(
512+
"Error creating RO Bundle for workflow from " + workflow.getRetrievedFrom().toSummary(),
513+
ex);
510514
}
511515
}
512516

@@ -520,9 +524,9 @@ private void removeWorkflow(Workflow workflow) {
520524
if (workflow.getRoBundlePath() != null) {
521525
File roBundle = new File(workflow.getRoBundlePath());
522526
if (roBundle.delete()) {
523-
logger.debug("Deleted Research Object Bundle");
527+
logger.debug("Deleted Research Object Bundle for workflow " + workflow.getID());
524528
} else {
525-
logger.debug("Failed to delete Research Object Bundle");
529+
logger.info("Failed to delete Research Object Bundle for workflow " + workflow.getID());
526530
}
527531
}
528532

@@ -556,7 +560,8 @@ private boolean cacheExpired(Workflow workflow) {
556560
if (expirationDate.before(new Date())) {
557561
// Cache expiry time has elapsed
558562
// Check current head of the branch with the cached head
559-
logger.info("Time has expired for caching, checking commits...");
563+
logger.info(
564+
"Time has expired for caching, checking commits for workflow " + workflow.getID());
560565
String currentHead;
561566
boolean safeToAccess = gitSemaphore.acquire(workflow.getRetrievedFrom().getRepoUrl());
562567
try {
@@ -565,7 +570,13 @@ private boolean cacheExpired(Workflow workflow) {
565570
} finally {
566571
gitSemaphore.release(workflow.getRetrievedFrom().getRepoUrl());
567572
}
568-
logger.info("Current: " + workflow.getLastCommit() + ", HEAD: " + currentHead);
573+
logger.info(
574+
"Current: "
575+
+ workflow.getLastCommit()
576+
+ ", HEAD: "
577+
+ currentHead
578+
+ " for workflow "
579+
+ workflow.getID());
569580

570581
// Reset date in database if there are still no changes
571582
boolean expired = !workflow.getLastCommit().equals(currentHead);
@@ -579,7 +590,10 @@ private boolean cacheExpired(Workflow workflow) {
579590
}
580591
} catch (Exception ex) {
581592
// Default to no expiry if there was an API error
582-
logger.error("API Error when checking for latest commit ID for caching", ex);
593+
logger.error(
594+
"API Error when checking for latest commit ID for caching for workflow "
595+
+ workflow.getID(),
596+
ex);
583597
}
584598
}
585599
return false;

0 commit comments

Comments
 (0)