cytoscape / cyREST

Core App: REST API module for Cytoscape
https://github.com/cytoscape/cyREST/wiki
MIT License
30 stars 13 forks source link

Cytoscape JS reading throws inadequate errors #84

Closed dotasek closed 5 years ago

dotasek commented 6 years ago

When accessing Cytoscape from Python 3 using py2cytoscape, one of our users had a script that sent invalid Cytoscape JS json:

"data": {
"source": ["HI-III", "BioPlex"],
"target": "17",
"relevance": 0.0216777,
"pred_used": 1,
"screens": [1, 2, 3],
"assays": [1],
"num_screens": 3,
"num_assays": 1
}

This was sent to POST /v1/networks, and resulted in this:

{'cause': {'cause': None, 'stackTrace': [{'methodName': 'addEdgeInternal', 'fileName': 'SimpleNetwork.java', 'lineNumber': 305, 'className': 'org.cytoscape.model.internal.SimpleNetwork', 'nativeMethod': False}, {'methodName': 'addEdge', 'fileName': 'CyRootNetworkImpl.java', 'lineNumber': 388, 'className': 'org.cytoscape.model.internal.CyRootNetworkImpl', 'nativeMethod': False}, {'methodName': 'addEdge', 'fileName': 'CySubNetworkImpl.java', 'lineNumber': 157, 'className': 'org.cytoscape.model.internal.CySubNetworkImpl', 'nativeMethod': False}, {'methodName': 'addEdges', 'fileName': 'CytoscapejsMapper.java', 'lineNumber': 242, 'className': 'org.cytoscape.io.internal.read.json.CytoscapejsMapper', 'nativeMethod': False}, {'methodName': 'createNetwork', 'fileName': 'CytoscapejsMapper.java', 'lineNumber': 71, 'className': 'org.cytoscape.io.internal.read.json.CytoscapejsMapper', 'nativeMethod': False}, {'methodName': 'run', 'fileName': 'CytoscapeJsNetworkReader.java', 'lineNumber': 109, 'className': 'org.cytoscape.io.internal.read.json.CytoscapeJsNetworkReader', 'nativeMethod': False}, {'methodName': 'createNetwork', 'fileName': 'NetworkResource.java', 'lineNumber': 922, 'className': 'org.cytoscape.rest.internal.resource.NetworkResource', 'nativeMethod': False}, {'methodName': 'invoke0', 'fileName': 'NativeMethodAccessorImpl.java', 'lineNumber': -2, 'className': 'sun.reflect.NativeMethodAccessorImpl', 'nativeMethod': True}, {'methodName': 'invoke', 'fileName': 'NativeMethodAccessorImpl.java', 'lineNumber': 62, 'className': 'sun.reflect.NativeMethodAccessorImpl', 'nativeMethod': False}, {'methodName': 'invoke', 'fileName': 'DelegatingMethodAccessorImpl.java', 'lineNumber': 43, 'className': 'sun.reflect.DelegatingMethodAccessorImpl', 'nativeMethod': False}, {'methodName': 'invoke', 'fileName': 'Method.java', 'lineNumber': 498, 'className': 'java.lang.reflect.Method', 'nativeMethod': False}, {'methodName': 'invoke', 'fileName': 'ResourceMethodInvocationHandlerFactory.java', 'lineNumber': 81, 'className': 

The root of the error is not obvious in this situation, but it turned out to be that the source field was originally a node, but was overwritten by a 'source' column in the original data. Renaming the edge column to 'origin' fixed the error.

This kind of error is problematic, because the Cytoscape JS reader should have sent an exception explicitly saying that the source was invalid, and CyREST should have passed that on (now possible in #79).

dotasek commented 6 years ago

Added a quick fix in 76d0982a1841a5b522faeaaf154f58ddc65fedca