{"action":"created","issue":{"url":"https://api.github.com/repos/PCMDI/cmor/issues/65","repository_url":"https://api.github.com/repos/PCMDI/cmor","labels_url":"https://api.github.com/repos/PCMDI/cmor/issues/65/labels{/name}","comments_url":"https://api.github.com/repos/PCMDI/cmor/issues/65/comments","events_url":"https://api.github.com/repos/PCMDI/cmor/issues/65/events","html_url":"https://github.com/PCMDI/cmor/issues/65","id":160639362,"number":65,"title":"Error handling in CMOR 3.1","user":{"login":"ehogan","id":918142,"avatar_url":"https://avatars.githubusercontent.com/u/918142?v=3","gravatar_id":"","url":"https://api.github.com/users/ehogan","html_url":"https://github.com/ehogan","followers_url":"https://api.github.com/users/ehogan/followers","following_url":"https://api.github.com/users/ehogan/following{/other_user}","gists_url":"https://api.github.com/users/ehogan/gists{/gist_id}","starred_url":"https://api.github.com/users/ehogan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ehogan/subscriptions","organizations_url":"https://api.github.com/users/ehogan/orgs","repos_url":"https://api.github.com/users/ehogan/repos","events_url":"https://api.github.com/users/ehogan/events{/privacy}","received_events_url":"https://api.github.com/users/ehogan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-16T11:29:29Z","updated_at":"2016-06-16T13:01:32Z","closed_at":null,"body":"Thank you for making the changes required to prevent the core dumps :)\r\n\r\nI have discovered some differing behaviours in the way CMOR 3.1 handles errors.\r\n\r\n**Example 1**\r\n\r\nError terminates the Python interpreter:\r\n```\r\n% ipython\r\nPython 2.7.6 (default, Jan  3 2014, 16:42:21) \r\nType \"copyright\", \"credits\" or \"license\" for more information.\r\n\r\nIPython 2.2.0 -- An enhanced Interactive Python.\r\n?         -> Introduction and overview of IPython's features.\r\n%quickref -> Quick reference.\r\nhelp      -> Python's own help system.\r\nobject?   -> Details about 'object', use 'object??' for extra details.\r\n\r\nIn [1]: import cmor\r\n\r\nIn [2]: cmor.dataset_json('')\r\nC Traceback:\r\n! In function: cmor_is_setup\r\n! called from: cmor_dataset_json\r\n! \r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!\r\n! Error: You need to run cmor_setup before calling any cmor_function\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n%\r\n```\r\n**Example 2**\r\n\r\nError causes a `KeyboardInterrupt` exception to be thrown with no message. In addition, there is no log message, unless `cmor.close()` is called:\r\n\r\n``` \r\n% ipython\r\nPython 2.7.6 (default, Jan  3 2014, 16:42:21) \r\nType \"copyright\", \"credits\" or \"license\" for more information.\r\n\r\nIPython 2.2.0 -- An enhanced Interactive Python.\r\n?         -> Introduction and overview of IPython's features.\r\n%quickref -> Quick reference.\r\nhelp      -> Python's own help system.\r\nobject?   -> Details about 'object', use 'object??' for extra details.\r\n\r\nIn [1]: import cmor\r\n\r\nIn [2]: cmor.setup(logfile='cmor.log')\r\n\r\nIn [3]: cmor.dataset_json('')\r\n---------------------------------------------------------------------------\r\nKeyboardInterrupt                         Traceback (most recent call last)\r\nKeyboardInterrupt: \r\n\r\nIn [4]: more cmor.log\r\n\r\nIn [5]: cmor.close()\r\nOut[5]: 0\r\n\r\nIn [6]: more cmor.log\r\n\r\nC Traceback:\r\n! In function: cmor_open_inpathFile\r\n! called from: cmor_dataset_json\r\n! \r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!\r\n! Error: Could not understand file \"./\" Is this a JSON CMOR table?\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n\r\nC Traceback:\r\n! In function: cmor_dataset_json\r\n! \r\n\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n!\r\n! Error: JSON resource file not found\r\n!\r\n!!!!!!!!!!!!!!!!!!!!!!!!!\r\n\r\n! ------\r\n! CMOR is now closed.\r\n! ------\r\n! During execution we encountered:\r\n!   1 Warning(s)\r\n!   2 Error(s)\r\n! ------\r\n! Please review them.\r\n! ------\r\n! \r\n\r\nIn [7]: \r\n```\r\nWould it be possible to:\r\n\r\n1. not exit the python interpreter when there is an error.\r\n2. print to the log after each command is executed, rather than only when `cmor.close()` is executed.\r\n3. use the message that is sent to the log as the exception message.\r\n\r\nThis ticket provides information relevant to CMOR 3.1, so #27 can probably be closed as a duplicate.\r\n\r\n[Edited to remove \"raise a more appropriate exception than `KeyboardInterrupt`\"; I just noticed a comment from Denis in an e-mail that says \"Now you will see a new message `Keyboard Interrupt`. There is nothing I can do about this, if I want to trap the signal.\" and trapping the signal is definitely more important than the exception type :)]"},"comment":{"url":"https://api.github.com/repos/PCMDI/cmor/issues/comments/226478052","html_url":"https://github.com/PCMDI/cmor/issues/65#issuecomment-226478052","issue_url":"https://api.github.com/repos/PCMDI/cmor/issues/65","id":226478052,"user":{"login":"ehogan","id":918142,"avatar_url":"https://avatars.githubusercontent.com/u/918142?v=3","gravatar_id":"","url":"https://api.github.com/users/ehogan","html_url":"https://github.com/ehogan","followers_url":"https://api.github.com/users/ehogan/followers","following_url":"https://api.github.com/users/ehogan/following{/other_user}","gists_url":"https://api.github.com/users/ehogan/gists{/gist_id}","starred_url":"https://api.github.com/users/ehogan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ehogan/subscriptions","organizations_url":"https://api.github.com/users/ehogan/orgs","repos_url":"https://api.github.com/users/ehogan/repos","events_url":"https://api.github.com/users/ehogan/events{/privacy}","received_events_url":"https://api.github.com/users/ehogan/received_events","type":"User","site_admin":false},"created_at":"2016-06-16T13:01:32Z","updated_at":"2016-06-16T13:01:32Z","body":"Possibly related to this, in the [CMIP6 example](https://github.com/PCMDI/cmor/blob/master/Test/test_python_CMIP6_experimentID.py) the following command is used:\r\n```\r\nerror_flag = cmor.dataset_json(\"Test/test_python_CMIP6_experimentID.json\")\r\n```\r\nIn the CMOR2 User Guide, both Fortran and C return 0 upon success, whereas Python returns None. Is there a way for the exit code to be returned to `pywrapper.py` in the same way as Fortran and C? I understand there are cases where CMOR should explicitly fail, but if the underlying function returns the exit code rather than exiting itself, couldn’t the code in `pywrapper.py` check the exit code and then raise an exception / return the correct exit code, depending on what you want CMOR3 to do in each case?\r\n"}}
{"actor":{"display_login":"ehogan"}}