I’m working on the py4cytoscape branch called ReturnVals … I haven’t merged my changes into Master yet. Please take a look and let me know whether my changes are sound and consider making the same changes to RCy3. Generally, I did the following:
Made all console output call the new narrate() function, which checks to see whether iPython is running. If so, it prints the message (e.g., “Layout complete”); otherwise, the message is not printed. In R, I suspect the right thing to do is something along the lines of this: https://rstudio.github.io/rstudioapi/reference/isAvailable.html
Created an exception class called CyError, which returns an error description string to the caller. The error description contains text describing the error, gives the offending value(s), and possibly recommends some action. It does not contain the name of the function in which the error occurred – that is prepended to the error description automatically by the CyError constructor. The mechanics of this may differ in R, as I understand that R doesn’t have exception classes, but does have stop(). Even so, a central function in R could find the caller name (https://stackoverflow.com/questions/15595478/how-to-get-the-name-of-the-calling-function-inside-the-called-routine) and do the prepend, then do the stop().
Changed the documentation for each function that now throws CyError instead of returning “”, None, or error text. Note that CyError is not a RCy3 concept … I added it a while ago to better enable error checking that RCy3 started. To see the extent and types of CyError, do a global search on CyError and observe how/where it’s used.
Changed property value validation to call verify_* functions in py4cytoscape_utils.py. These functions will validate colors, opacities, and dimensions … either as single values, a list of values, or None. So, the loops that repeatedly called functions like is_not_hex_color() have been replaced by a single call to functions like verify_hex_colors(). Similarly, a verify_slot() function centralizes slot number checking in custom graphics.
The functions I changed (relative to Master, which is last week’s release) are below. Most are self-explanatory, but I have added comments as needed:
Module
Function
Comment
Commands.py
*
Changed _handle_error to not pass function name … CyError now figures out the function name. Note that code is organized somewhat differently than in RCy3
_command_2_post_query_body
Changed error text so it shows more context
_handle_error
Figures out caller name so CyError can add it to the error message
Cytoscape_system
Cytoscape_ping
Changed print() to narrate()
Cytoscape_version_infoCytoscape_free_memory
Eliminated writing error text and added CyError
CyError
*
Created error class constructor that adds name of caller to error message text
In coordination with py4cytoscape via Barry: