{"action":"created","issue":{"url":"https://api.github.com/repos/bebraw/pypandoc/issues/86","labels_url":"https://api.github.com/repos/bebraw/pypandoc/issues/86/labels{/name}","comments_url":"https://api.github.com/repos/bebraw/pypandoc/issues/86/comments","events_url":"https://api.github.com/repos/bebraw/pypandoc/issues/86/events","html_url":"https://github.com/bebraw/pypandoc/issues/86","id":121938072,"number":86,"title":"pypandoc.convert() doesn't handle errors properly","user":{"login":"marbu","id":710794,"avatar_url":"https://avatars.githubusercontent.com/u/710794?v=3","gravatar_id":"","url":"https://api.github.com/users/marbu","html_url":"https://github.com/marbu","followers_url":"https://api.github.com/users/marbu/followers","following_url":"https://api.github.com/users/marbu/following{/other_user}","gists_url":"https://api.github.com/users/marbu/gists{/gist_id}","starred_url":"https://api.github.com/users/marbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marbu/subscriptions","organizations_url":"https://api.github.com/users/marbu/orgs","repos_url":"https://api.github.com/users/marbu/repos","events_url":"https://api.github.com/users/marbu/events{/privacy}","received_events_url":"https://api.github.com/users/marbu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-13T19:29:17Z","updated_at":"2015-12-13T19:30:03Z","closed_at":null,"body":"Function `pypandoc.convert()` doesn't handle errors properly.\r\n\r\nWhen I call `pypandoc.convert(filepath, 'rst')` with filepath which doesn't\r\nexists, I got puzzling exception `RuntimeError: Missing format!` insdead of\r\nstatement of actual root cause of the error.\r\n\r\nSimilar issue happen when an empty string or int is passed as a filepath.\r\n\r\n## Reproducer\r\n\r\nHere is simple reproducer:\r\n\r\n```\r\n#!/usr/bin/env python\r\n# -*- coding: utf8 -*-\r\n\r\n\r\nimport traceback\r\nimport sys\r\n\r\nimport pypandoc\r\n\r\n\r\nfiles = [\r\n    '/home/martin/projects/pyp2rpm/README.md',\r\n    '/home/martin/projects/pypandoc/README.md',\r\n    '/home/martin/tmp/doesnotexists.md',\r\n    '',\r\n    42,\r\n    None,\r\n    ]\r\n\r\nfor filepath in files:\r\n    print(\"converting '{0}' (type: {1})\".format(filepath, type(filepath)))\r\n    try:\r\n        pypandoc.convert(filepath, 'rst')\r\n    except Exception:\r\n        traceback.print_exc(file=sys.stdout)\r\n    print()\r\n```\r\n\r\nWhen I run this script on my machine where 1st two files exists, I got\r\nthe following output:\r\n\r\n```\r\n$ ./reproducer.py\r\nconverting '/home/martin/projects/pyp2rpm/README.md' (type: <class 'str'>)\r\n\r\nconverting '/home/martin/projects/pypandoc/README.md' (type: <class 'str'>)\r\n\r\nconverting '/home/martin/tmp/doesnotexists.md' (type: <class 'str'>)\r\nTraceback (most recent call last):\r\n  File \"./reproducer.py\", line 23, in <module>\r\n    pypandoc.convert(filepath, 'rst')\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/site-packages/pypandoc-1.1.2-py3.4.egg/pypandoc/__init__.py\", line 50, in convert\r\n    outputfile=outputfile, filters=filters)\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/site-packages/pypandoc-1.1.2-py3.4.egg/pypandoc/__init__.py\", line 68, in _convert\r\n    raise RuntimeError('Missing format!')\r\nRuntimeError: Missing format!\r\n\r\nconverting '' (type: <class 'str'>)\r\nTraceback (most recent call last):\r\n  File \"./reproducer.py\", line 23, in <module>\r\n    pypandoc.convert(filepath, 'rst')\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/site-packages/pypandoc-1.1.2-py3.4.egg/pypandoc/__init__.py\", line 50, in convert\r\n    outputfile=outputfile, filters=filters)\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/site-packages/pypandoc-1.1.2-py3.4.egg/pypandoc/__init__.py\", line 68, in _convert\r\n    raise RuntimeError('Missing format!')\r\nRuntimeError: Missing format!\r\n\r\nconverting '42' (type: <class 'int'>)\r\nTraceback (most recent call last):\r\n  File \"./reproducer.py\", line 23, in <module>\r\n    pypandoc.convert(filepath, 'rst')\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/site-packages/pypandoc-1.1.2-py3.4.egg/pypandoc/__init__.py\", line 50, in convert\r\n    outputfile=outputfile, filters=filters)\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/site-packages/pypandoc-1.1.2-py3.4.egg/pypandoc/__init__.py\", line 68, in _convert\r\n    raise RuntimeError('Missing format!')\r\nRuntimeError: Missing format!\r\n\r\nconverting 'None' (type: <class 'NoneType'>)\r\nTraceback (most recent call last):\r\n  File \"./reproducer.py\", line 23, in <module>\r\n    pypandoc.convert(filepath, 'rst')\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/site-packages/pypandoc-1.1.2-py3.4.egg/pypandoc/__init__.py\", line 50, in convert\r\n    outputfile=outputfile, filters=filters)\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/site-packages/pypandoc-1.1.2-py3.4.egg/pypandoc/__init__.py\", line 55, in _convert\r\n    source, format, input_type = reader(source, format, encoding=encoding)\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/site-packages/pypandoc-1.1.2-py3.4.egg/pypandoc/__init__.py\", line 96, in _read_file\r\n    path = os.path.exists(source)\r\n  File \"/home/martin/projects/pypandoc/.env/lib/python3.4/genericpath.py\", line 19, in exists\r\n    os.stat(path)\r\nTypeError: stat: can't specify None for path argument\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/bebraw/pypandoc/issues/comments/164289585","html_url":"https://github.com/bebraw/pypandoc/issues/86#issuecomment-164289585","issue_url":"https://api.github.com/repos/bebraw/pypandoc/issues/86","id":164289585,"user":{"login":"bebraw","id":166921,"avatar_url":"https://avatars.githubusercontent.com/u/166921?v=3","gravatar_id":"","url":"https://api.github.com/users/bebraw","html_url":"https://github.com/bebraw","followers_url":"https://api.github.com/users/bebraw/followers","following_url":"https://api.github.com/users/bebraw/following{/other_user}","gists_url":"https://api.github.com/users/bebraw/gists{/gist_id}","starred_url":"https://api.github.com/users/bebraw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bebraw/subscriptions","organizations_url":"https://api.github.com/users/bebraw/orgs","repos_url":"https://api.github.com/users/bebraw/repos","events_url":"https://api.github.com/users/bebraw/events{/privacy}","received_events_url":"https://api.github.com/users/bebraw/received_events","type":"User","site_admin":false},"created_at":"2015-12-13T19:30:03Z","updated_at":"2015-12-13T19:30:03Z","body":"Great point. Do you want to PR?"}}