{"action":"created","issue":{"url":"https://api.github.com/repos/getpelican/pelican/issues/1759","repository_url":"https://api.github.com/repos/getpelican/pelican","labels_url":"https://api.github.com/repos/getpelican/pelican/issues/1759/labels{/name}","comments_url":"https://api.github.com/repos/getpelican/pelican/issues/1759/comments","events_url":"https://api.github.com/repos/getpelican/pelican/issues/1759/events","html_url":"https://github.com/getpelican/pelican/issues/1759","id":88804663,"number":1759,"title":"sys.exit called on rst parse errors","user":{"login":"valhallasw","id":31531,"avatar_url":"https://avatars.githubusercontent.com/u/31531?v=3","gravatar_id":"","url":"https://api.github.com/users/valhallasw","html_url":"https://github.com/valhallasw","followers_url":"https://api.github.com/users/valhallasw/followers","following_url":"https://api.github.com/users/valhallasw/following{/other_user}","gists_url":"https://api.github.com/users/valhallasw/gists{/gist_id}","starred_url":"https://api.github.com/users/valhallasw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/valhallasw/subscriptions","organizations_url":"https://api.github.com/users/valhallasw/orgs","repos_url":"https://api.github.com/users/valhallasw/repos","events_url":"https://api.github.com/users/valhallasw/events{/privacy}","received_events_url":"https://api.github.com/users/valhallasw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2015-06-16T18:34:37Z","updated_at":"2016-12-13T18:32:06Z","closed_at":null,"body":"The docutils.core.Publisher backend is called in a such a way that it doesn't raise an Exception, but calls sys.exit instead. This makes it harder to use pelican as library.\n\nHow to reproduce this?\n\nUsing an rst file with invalid syntax, run:\n\n```\nfrom pelican import Pelican\nfrom pelican.settings import read_settings\n\np = Pelican(read_settings('pelicanconf.py'))\ntry:\n    p.run()\nexcept Exception as e:\n   print \"Caught exception: \", e\n\nprint \"Continue after failure\"\n```\n\nExpected behavior:\n\n```\n$ python test.py\n....../file.rst:29: (ERROR/3) Unknown directive type \"fdsaf\".\n\n<details>\n\nCaught exception: SomeException\nContinue after failure\n```\n\nActual behavior:\n\n```\n$ python test.py\n....../file.rst:29: (ERROR/3) Unknown directive type \"fdsaf\".\n\n<details>\n\n$ (silently exits)\n```\n\nThis is caused because of  `enable_exit_status=True` which is passed to docutils.core.Publisher.publish since #1224 was merged.\n\nUnfortunately, I don't know enough about the internal structure of Pelican to suggest where the docutils Exception should be changed into a sys.exit, but I'm inclined to say this should be close to the entry point. This allows people who call Pelican as a library to catch an Exception as-is, instead of resorting to the workaround\n\n```\ntry:\n    p.run()\nexcept SystemExit as e:\n   print \"Caught sys.exit.\"\n```\n"},"comment":{"url":"https://api.github.com/repos/getpelican/pelican/issues/comments/266821495","html_url":"https://github.com/getpelican/pelican/issues/1759#issuecomment-266821495","issue_url":"https://api.github.com/repos/getpelican/pelican/issues/1759","id":266821495,"user":{"login":"leotrs","id":1096704,"avatar_url":"https://avatars.githubusercontent.com/u/1096704?v=3","gravatar_id":"","url":"https://api.github.com/users/leotrs","html_url":"https://github.com/leotrs","followers_url":"https://api.github.com/users/leotrs/followers","following_url":"https://api.github.com/users/leotrs/following{/other_user}","gists_url":"https://api.github.com/users/leotrs/gists{/gist_id}","starred_url":"https://api.github.com/users/leotrs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leotrs/subscriptions","organizations_url":"https://api.github.com/users/leotrs/orgs","repos_url":"https://api.github.com/users/leotrs/repos","events_url":"https://api.github.com/users/leotrs/events{/privacy}","received_events_url":"https://api.github.com/users/leotrs/received_events","type":"User","site_admin":false},"created_at":"2016-12-13T18:32:06Z","updated_at":"2016-12-13T18:32:06Z","body":"@omiday did that PR ever get done?"}}
{"actor":{"display_login":"leotrs"}}