{"action":"closed","issue":{"url":"https://api.github.com/repos/amjith/pgcli/issues/28","labels_url":"https://api.github.com/repos/amjith/pgcli/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/amjith/pgcli/issues/28/comments","events_url":"https://api.github.com/repos/amjith/pgcli/issues/28/events","html_url":"https://github.com/amjith/pgcli/issues/28","id":53546812,"number":28,"title":"\"UnboundError\" with backslash-command without argument (\\c)","user":{"login":"narzeja","id":358564,"avatar_url":"https://avatars.githubusercontent.com/u/358564?v=3","gravatar_id":"","url":"https://api.github.com/users/narzeja","html_url":"https://github.com/narzeja","followers_url":"https://api.github.com/users/narzeja/followers","following_url":"https://api.github.com/users/narzeja/following{/other_user}","gists_url":"https://api.github.com/users/narzeja/gists{/gist_id}","starred_url":"https://api.github.com/users/narzeja/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/narzeja/subscriptions","organizations_url":"https://api.github.com/users/narzeja/orgs","repos_url":"https://api.github.com/users/narzeja/repos","events_url":"https://api.github.com/users/narzeja/events{/privacy}","received_events_url":"https://api.github.com/users/narzeja/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/amjith/pgcli/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-01-06T18:34:55Z","updated_at":"2015-01-07T08:36:32Z","closed_at":"2015-01-07T08:36:32Z","body":"I get an uncaught exception with backslash-commands that take arguments, like \\c.\r\n\r\nConsider the following interaction with a freshly installed database.\r\n```bash\r\n$ pgcli testdb\r\ntestdb> \\c testdb\r\nYou are now connected to database \"testdb\" as user \"<my_user>\"\r\ntestdb>\r\n```\r\n\r\nFrom here, if I type \\c without specifying which database I wish to connect to, I get an uncaught exception:\r\n```bash\r\ntestdb> \\c\r\n```\r\n```python\r\nTraceback (most recent call last):\r\n  File \"/home/<my_user>/.local/lib/python3.4/site-packages/pgcli/pgexecute.py\", line 89, in run\r\n    dbname = sql.split()[1]\r\nIndexError: list index out of range\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/<my_user>/.local/lib/python3.4/site-packages/pgcli/main.py\", line 104, in cli\r\n    res = pgexecute.run(document.text)\r\n  File \"/home/<my_user>/.local/lib/python3.4/site-packages/pgcli/pgexecute.py\", line 91, in run\r\n    _logger.debug('Failed to switch. DB missing: %r', dbname)\r\nUnboundLocalError: local variable 'dbname' referenced before assignment\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/home/<my_user>/.local/bin/pgcli\", line 9, in <module>\r\n    load_entry_point('pgcli==0.10.0', 'console_scripts', 'pgcli')()\r\n  File \"/home/<my_user>/.local/lib/python3.4/site-packages/click/core.py\", line 610, in __call__\r\n    return self.main(*args, **kwargs)\r\n  File \"/home/<my_user>/.local/lib/python3.4/site-packages/click/core.py\", line 590, in main\r\n    rv = self.invoke(ctx)\r\n  File \"/home/<my_user>/.local/lib/python3.4/site-packages/click/core.py\", line 782, in invoke\r\n    return ctx.invoke(self.callback, **ctx.params)\r\n  File \"/home/<my_user>/.local/lib/python3.4/site-packages/click/core.py\", line 416, in invoke\r\n    return callback(*args, **kwargs)\r\n  File \"/home/<my_user>/.local/lib/python3.4/site-packages/pgcli/main.py\", line 116, in cli\r\n    _logger.debug(\"sql: %r, error: %r\", document.text, e.message)\r\nAttributeError: 'UnboundLocalError' object has no attribute 'message'\r\n```\r\n\r\nA proper way of handling this is to inform the user that a database (or other argument for other backslash-commands) must be provided and return to the prompt gracefully.\r\n\r\nSystem details:\r\nOS: 3.17.6-1-ARCH\r\nPython 3.4.2\r\npostgres (PostgreSQL) 9.3.5\r\nLatest pip-release of pgcli."}}