Skip to content

Commit 68b221c

Browse files
committed
Don't throw exception from associate command.
Refs #498
1 parent 5befb76 commit 68b221c

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

EnrichmentMapPlugin/src/main/java/org/baderlab/csplugins/enrichmentmap/commands/AssociateNetworkCommandTask.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,34 @@ public AssociateNetworkCommandTask() {
3535

3636
@Override
3737
public void run(TaskMonitor tm) {
38-
if(emNetworkSUID == null)
39-
throw new IllegalArgumentException("emNetworkSUID is null");
40-
if(!emManager.isEnrichmentMap(emNetworkSUID))
41-
throw new IllegalArgumentException("emNetworkSUID is not an EnrichmentMap network");
42-
if(associatedNetworkSUID == null)
43-
throw new IllegalArgumentException("associatedNetworkSUID is null");
44-
38+
// AutoAnnotate may call this command on non-EM networks, so we need to fail gracefully, ie don't throw an Exception.
39+
if(emNetworkSUID == null) {
40+
tm.showMessage(TaskMonitor.Level.ERROR, "emNetworkSUID is null");
41+
return;
42+
}
43+
if(associatedNetworkSUID == null) {
44+
tm.showMessage(TaskMonitor.Level.ERROR, "associatedNetworkSUID is null");
45+
return;
46+
}
47+
if(!emManager.isEnrichmentMap(emNetworkSUID)) {
48+
tm.showMessage(TaskMonitor.Level.WARN, "emNetworkSUID is not an EnrichmentMap network");
49+
return;
50+
}
4551
var network = netManager.getNetwork(associatedNetworkSUID);
46-
if(network == null)
47-
throw new IllegalArgumentException("associatedNetworkSUID is invalid");
48-
49-
var map = emManager.getEnrichmentMap(emNetworkSUID);
52+
if(network == null) {
53+
tm.showMessage(TaskMonitor.Level.ERROR, "associatedNetworkSUID is invalid");
54+
return;
55+
}
5056

5157
AssociatedApp assApp;
5258
try {
5359
assApp = AssociatedApp.valueOf(app.getSelectedValue());
5460
} catch(IllegalArgumentException | NullPointerException e) {
55-
throw new IllegalArgumentException("app is invalid");
61+
tm.showMessage(TaskMonitor.Level.ERROR, "app is invalid");
62+
return;
5663
}
5764

65+
var map = emManager.getEnrichmentMap(emNetworkSUID);
5866
map.addAssociatedNetworkID(network.getSUID());
5967
emManager.addAssociatedAppAttributes(network, map, assApp);
6068
}

0 commit comments

Comments
 (0)