Repository: praw-dev/praw

Issue:
Users attempting to run old code are confused by configparser.NoSectionError. Should they get a different help message?
Over the past couple of months, I've been getting a lot of reddit PMs from people who find PRAW3 tutorials and resources online, and are confused by:


    >>> r = praw.Reddit('useragent')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python36\lib\site-packages\praw\reddit.py", line 103, in __init__
        **config_settings)
      File "C:\Python36\lib\site-packages\praw\config.py", line 66, in __init__
        self.custom = dict(Config.CONFIG.items(site_name), **settings)
      File "C:\Python36\lib\configparser.py", line 846, in items
        raise NoSectionError(section)
    configparser.NoSectionError: No section: 'useragent'

When filled positionally, that argument lands in  [site_name](https://github.com/praw-dev/praw/blob/e142a508076625a994814e75d78f245c1e83d65d/praw/reddit.py#L75), so we can check for `site_name is not None and config_settings == {}`.

When `user_agent` is filled by name, the error is instead `praw.exceptions.ClientException: Required configuration setting 'client_id' missing`. However, I have not been getting any messages about this so I don't think PRAW3 authors did this very much. It's a low enough priority that I would not add the help message in this case.

Should the `Reddit` constructor try to detect this event and give some info on the v3-v4 distinction? I don't know if making direct references to prior releases is generally favored but it's frustrating for new users.


Discussion:
I think we could catch the `configparser.NoSectionError: No section: 'useragent'` exception and add additional pointers to the documentation, or a direct example before re-raising the exception. Aside from that, however, I don't think we should try to be smart about what people are trying to do.

Want to make a PR for that? Really great idea thinking about how to make this transition more user-friendly.
Sounds like a good balance. I think the readthedocs articles for [The Reddit Instance](https://praw.readthedocs.io/en/latest/code_overview/reddit_instance.html) and [Configuring PRAW](https://praw.readthedocs.io/en/latest/getting_started/configuration.html) are appropriate. I'll open a PR in just a moment.

Resolving patch:
diff --git a/praw/reddit.py b/praw/reddit.py
--- a/praw/reddit.py
+++ b/praw/reddit.py
@@ -14,7 +14,7 @@
 
 from .exceptions import ClientException
 from .config import Config
-from .const import __version__, API_PATH, USER_AGENT_FORMAT
+from .const import __version__, API_PATH, USER_AGENT_FORMAT, configparser
 from .objector import Objector
 from . import models
 
@@ -99,8 +99,22 @@ def __init__(self, site_name=None, **config_settings):
         self._core = self._authorized_core = self._read_only_core = None
         self._objector = None
         self._unique_counter = 0
-        self.config = Config(site_name or os.getenv('praw_site') or 'DEFAULT',
-                             **config_settings)
+
+        try:
+            config_section = site_name or os.getenv('praw_site') or 'DEFAULT'
+            self.config = Config(config_section, **config_settings)
+        except configparser.NoSectionError as exc:
+            help_message = ('You provided the name of a praw.ini '
+                            'configuration which does not exist.\n\nFor help '
+                            'with creating a Reddit instance, visit\n'
+                            'https://praw.readthedocs.io/en/latest/code_overvi'
+                            'ew/reddit_instance.html\n\n'
+                            'For help on configuring PRAW, visit\n'
+                            'https://praw.readthedocs.io/en/latest/getting_sta'
+                            'rted/configuration.html')
+            if site_name is not None:
+                exc.message += '\n' + help_message
+            raise
 
         required_message = ('Required configuration setting {!r} missing. \n'
                             'This setting can be provided in a praw.ini file, '


Test patch:
diff --git a/tests/unit/test_reddit.py b/tests/unit/test_reddit.py
--- a/tests/unit/test_reddit.py
+++ b/tests/unit/test_reddit.py
@@ -3,6 +3,7 @@
 import mock
 import pytest
 from praw import __version__, Reddit
+from praw.const import configparser
 from praw.exceptions import ClientException
 
 from . import UnitTest
@@ -117,6 +118,11 @@ def test_reddit__required_settings_set_to_none(self):
                                                  'setting \'{}\' missing.'
                                                  .format(setting))
 
+    def test_reddit__site_name_no_section(self):
+        with pytest.raises(configparser.NoSectionError) as excinfo:
+            Reddit('bad_site_name')
+        assert 'praw.readthedocs.io' in excinfo.value.message
+
     def test_submission(self):
         assert self.reddit.submission('2gmzqe').id == '2gmzqe'