Repository: sphinx-doc/sphinx

Issue:
autosummary crashes with wrong autosummary_generate
**Describe the bug**
Sphinx and autosummary are crashed if autosummary_generate has wrong value.

**To Reproduce**
Steps to reproduce the behavior:
```
.. autosummary::
   :toctree: generated

   example.Base
```
```
autosummary_generate = ['foo']
extensions.append('sphinx.ext.autosummary')
```
```
Running Sphinx v2.2.0+
making output directory... done
[autosummary] generating autosummary for: foo.rst

Exception occurred:
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/generate.py", line 279, in find_autosummary_in_files
    with open(filename, encoding='utf-8', errors='ignore') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/tkomiya/work/tmp/doc/foo.rst'
The full traceback has been saved in /var/folders/rj/80_5mv452nsfnhkvkyqjwj040000gp/T/sphinx-err-je2ykn1a.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [html] Error 2
```
```
# Loaded extensions:
Traceback (most recent call last):
  File "/Users/tkomiya/work/sphinx/sphinx/cmd/build.py", line 283, in build_main
    args.tags, args.verbosity, args.jobs, args.keep_going)
  File "/Users/tkomiya/work/sphinx/sphinx/application.py", line 268, in __init__
    self._init_builder()
  File "/Users/tkomiya/work/sphinx/sphinx/application.py", line 329, in _init_builder
    self.events.emit('builder-inited')
  File "/Users/tkomiya/work/sphinx/sphinx/events.py", line 103, in emit
    results.append(callback(self.app, *args))
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/__init__.py", line 758, in process_generate_options
    app=app, imported_members=imported_members)
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/generate.py", line 168, in generate_autosummary_docs
    items = find_autosummary_in_files(sources)
  File "/Users/tkomiya/work/sphinx/sphinx/ext/autosummary/generate.py", line 279, in find_autosummary_in_files
    with open(filename, encoding='utf-8', errors='ignore') as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/tkomiya/work/tmp/doc/foo.rst'
```

**Expected behavior**
Build successfully (with warning)

**Your project**
None

**Screenshots**
None

**Environment info**
- OS: Mac
- Python version: 3.7.3
- Sphinx version: 2.1.1
- Sphinx extensions:  sphinx.ext.autosummary


Discussion:

Patch:
diff --git a/CHANGES b/CHANGES
index e5c83ddb0..088fae434 100644
--- a/CHANGES
+++ b/CHANGES
@@ -41,6 +41,7 @@ Bugs fixed
 * #5502: linkcheck: Consider HTTP 503 response as not an error
 * #6439: Make generated download links reproducible
 * #6486: UnboundLocalError is raised if broken extension installed
+* #6498: autosummary: crashed with wrong autosummary_generate setting
 
 Testing
 --------
diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py
index 6eb0fea9b..19c400609 100644
--- a/sphinx/ext/autosummary/__init__.py
+++ b/sphinx/ext/autosummary/__init__.py
@@ -58,6 +58,7 @@
 import re
 import sys
 import warnings
+from os import path
 from types import ModuleType
 from typing import List, cast
 
@@ -731,26 +732,31 @@ def process_generate_options(app):
     # type: (Sphinx) -> None
     genfiles = app.config.autosummary_generate
 
-    if genfiles and not hasattr(genfiles, '__len__'):
+    if genfiles is True:
         env = app.builder.env
         genfiles = [env.doc2path(x, base=None) for x in env.found_docs
                     if os.path.isfile(env.doc2path(x))]
+    else:
+        ext = list(app.config.source_suffix)
+        genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
+                    for genfile in genfiles]
+
+        for entry in genfiles[:]:
+            if not path.isfile(path.join(app.srcdir, entry)):
+                logger.warning(__('autosummary_generate: file not found: %s'), entry)
+                genfiles.remove(entry)
 
     if not genfiles:
         return
 
-    from sphinx.ext.autosummary.generate import generate_autosummary_docs
-
-    ext = list(app.config.source_suffix)
-    genfiles = [genfile + (not genfile.endswith(tuple(ext)) and ext[0] or '')
-                for genfile in genfiles]
-
     suffix = get_rst_suffix(app)
     if suffix is None:
         logger.warning(__('autosummary generats .rst files internally. '
                           'But your source_suffix does not contain .rst. Skipped.'))
         return
 
+    from sphinx.ext.autosummary.generate import generate_autosummary_docs
+
     imported_members = app.config.autosummary_imported_members
     with mock(app.config.autosummary_mock_imports):
         generate_autosummary_docs(genfiles, builder=app.builder,
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index 5419e41df..b6ced2256 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -208,25 +208,23 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
     if info:
         warnings.warn('info argument for generate_autosummary_docs() is deprecated.',
                       RemovedInSphinx40Warning)
-        _info = info
     else:
-        _info = logger.info
+        info = logger.info
 
     if warn:
         warnings.warn('warn argument for generate_autosummary_docs() is deprecated.',
                       RemovedInSphinx40Warning)
-        _warn = warn
     else:
-        _warn = logger.warning
+        warn = logger.warning
 
     showed_sources = list(sorted(sources))
     if len(showed_sources) > 20:
         showed_sources = showed_sources[:10] + ['...'] + showed_sources[-10:]
-    _info(__('[autosummary] generating autosummary for: %s') %
-          ', '.join(showed_sources))
+    info(__('[autosummary] generating autosummary for: %s') %
+         ', '.join(showed_sources))
 
     if output_dir:
-        _info(__('[autosummary] writing to %s') % output_dir)
+        info(__('[autosummary] writing to %s') % output_dir)
 
     if base_path is not None:
         sources = [os.path.join(base_path, filename) for filename in sources]
@@ -252,7 +250,7 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
         try:
             name, obj, parent, mod_name = import_by_name(name)
         except ImportError as e:
-            _warn('[autosummary] failed to import %r: %s' % (name, e))
+            warn('[autosummary] failed to import %r: %s' % (name, e))
             continue
 
         fn = os.path.join(path, name + suffix)


Test patch:
diff --git a/tests/roots/test-images/index.rst b/tests/roots/test-images/index.rst
index 14a2987a0..67b742b27 100644
--- a/tests/roots/test-images/index.rst
+++ b/tests/roots/test-images/index.rst
@@ -26,4 +26,4 @@ test-image
 .. image:: https://www.python.org/static/img/python-logo.png
 
 .. non-exist remote image
-.. image:: https://www.google.com/NOT_EXIST.PNG
+.. image:: http://example.com/NOT_EXIST.PNG
diff --git a/tests/roots/test-intl/external_links.txt b/tests/roots/test-intl/external_links.txt
index 1cecbeeb8..96e3973de 100644
--- a/tests/roots/test-intl/external_links.txt
+++ b/tests/roots/test-intl/external_links.txt
@@ -23,8 +23,8 @@ link to external1_ and external2_.
 
 link to `Sphinx Site <http://sphinx-doc.org>`_ and `Python Site <http://python.org>`_.
 
-.. _external1: https://www.google.com/external1
-.. _external2: https://www.google.com/external2
+.. _external1: http://example.com/external1
+.. _external2: http://example.com/external2
 
 
 Multiple references in the same line
diff --git a/tests/roots/test-linkcheck/links.txt b/tests/roots/test-linkcheck/links.txt
index fa8f11e4c..ac5ed3246 100644
--- a/tests/roots/test-linkcheck/links.txt
+++ b/tests/roots/test-linkcheck/links.txt
@@ -6,11 +6,11 @@ This is from CPython documentation.
 
 Some additional anchors to exercise ignore code
 
-* `Example Bar invalid <https://www.google.com/#!bar>`_
-* `Example Bar invalid <https://www.google.com#!bar>`_ tests that default ignore anchor of #! does not need to be prefixed with /
-* `Example Bar invalid <https://www.google.com/#top>`_
+* `Example Bar invalid <http://example.com/#!bar>`_
+* `Example Bar invalid <http://example.com#!bar>`_ tests that default ignore anchor of #! does not need to be prefixed with /
+* `Example Bar invalid <http://example.com/#top>`_
 * `Example anchor invalid <http://www.sphinx-doc.org/en/1.7/intro.html#does-not-exist>`_
 * `Complete nonsense <https://localhost:7777/doesnotexist>`_
 
-.. image:: https://www.google.com/image.png
-.. figure:: https://www.google.com/image2.png
+.. image:: http://example.com/image.png
+.. figure:: http://example.com/image2.png
diff --git a/tests/test_build_html.py b/tests/test_build_html.py
index 3255bb71e..352166d94 100644
--- a/tests/test_build_html.py
+++ b/tests/test_build_html.py
@@ -1240,25 +1240,25 @@ def test_html_entity(app):
 def test_html_inventory(app):
     app.builder.build_all()
     with open(app.outdir / 'objects.inv', 'rb') as f:
-        invdata = InventoryFile.load(f, 'https://www.google.com', os.path.join)
+        invdata = InventoryFile.load(f, 'http://example.com', os.path.join)
     assert set(invdata.keys()) == {'std:label', 'std:doc'}
     assert set(invdata['std:label'].keys()) == {'modindex', 'genindex', 'search'}
     assert invdata['std:label']['modindex'] == ('Python',
                                                 '',
-                                                'https://www.google.com/py-modindex.html',
+                                                'http://example.com/py-modindex.html',
                                                 'Module Index')
     assert invdata['std:label']['genindex'] == ('Python',
                                                 '',
-                                                'https://www.google.com/genindex.html',
+                                                'http://example.com/genindex.html',
                                                 'Index')
     assert invdata['std:label']['search'] == ('Python',
                                               '',
-                                              'https://www.google.com/search.html',
+                                              'http://example.com/search.html',
                                               'Search Page')
     assert set(invdata['std:doc'].keys()) == {'index'}
     assert invdata['std:doc']['index'] == ('Python',
                                            '',
-                                           'https://www.google.com/index.html',
+                                           'http://example.com/index.html',
                                            'The basic Sphinx documentation for testing')
 
 
diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py
index 56dfa7ca4..13bb22e96 100644
--- a/tests/test_build_latex.py
+++ b/tests/test_build_latex.py
@@ -1242,7 +1242,7 @@ def test_latex_images(app, status, warning):
     # not found images
     assert '\\sphinxincludegraphics{{NOT_EXIST}.PNG}' not in result
     assert ('WARNING: Could not fetch remote image: '
-            'https://www.google.com/NOT_EXIST.PNG [404]' in warning.getvalue())
+            'http://example.com/NOT_EXIST.PNG [404]' in warning.getvalue())
 
     # an image having target
     assert ('\\sphinxhref{https://www.sphinx-doc.org/}'
diff --git a/tests/test_build_linkcheck.py b/tests/test_build_linkcheck.py
index 4bf47a962..6d25058eb 100644
--- a/tests/test_build_linkcheck.py
+++ b/tests/test_build_linkcheck.py
@@ -25,8 +25,8 @@ def test_defaults(app, status, warning):
     # looking for non-existent URL should fail
     assert " Max retries exceeded with url: /doesnotexist" in content
     # images should fail
-    assert "Not Found for url: https://www.google.com/image.png" in content
-    assert "Not Found for url: https://www.google.com/image2.png" in content
+    assert "Not Found for url: http://example.com/image.png" in content
+    assert "Not Found for url: http://example.com/image2.png" in content
     assert len(content.splitlines()) == 5
 
 
@@ -36,8 +36,8 @@ def test_defaults(app, status, warning):
                    'linkcheck_ignore': [
                        'https://localhost:7777/doesnotexist',
                        'http://www.sphinx-doc.org/en/1.7/intro.html#',
-                       'https://www.google.com/image.png',
-                       'https://www.google.com/image2.png']
+                       'http://example.com/image.png',
+                       'http://example.com/image2.png']
                    })
 def test_anchors_ignored(app, status, warning):
     app.builder.build_all()
diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py
index ae97d3b57..ae2b2d585 100644
--- a/tests/test_ext_autosummary.py
+++ b/tests/test_ext_autosummary.py
@@ -302,3 +302,9 @@ def test_generate_autosummary_docs_property(app):
                        ".. currentmodule:: target.methods\n"
                        "\n"
                        ".. autoproperty:: Base.prop")
+
+
+@pytest.mark.sphinx('dummy', testroot='ext-autosummary',
+                    confoverrides={'autosummary_generate': ['unknown']})
+def test_invalid_autosummary_generate(app, status, warning):
+    assert 'WARNING: autosummary_generate: file not found: unknown.rst' in warning.getvalue()
diff --git a/tests/test_intl.py b/tests/test_intl.py
index 9790f50a3..a052266b8 100644
--- a/tests/test_intl.py
+++ b/tests/test_intl.py
@@ -885,8 +885,8 @@ def test_xml_keep_external_links(app):
     assert_elem(
         para1[0],
         ['LINK TO', 'external2', 'AND', 'external1', '.'],
-        ['https://www.google.com/external2',
-         'https://www.google.com/external1'])
+        ['http://example.com/external2',
+         'http://example.com/external1'])
     assert_elem(
         para1[1],
         ['LINK TO', 'THE PYTHON SITE', 'AND', 'THE SPHINX SITE', '.'],
diff --git a/tests/test_markup.py b/tests/test_markup.py
index b8c9b66d9..006d19caa 100644
--- a/tests/test_markup.py
+++ b/tests/test_markup.py
@@ -279,9 +279,9 @@ def get(name):
     (
         # in URIs
         'verify_re',
-        '`test <https://www.google.com/~me/>`_',
+        '`test <http://example.com/~me/>`_',
         None,
-        r'\\sphinxhref{https://www.google.com/~me/}{test}.*',
+        r'\\sphinxhref{http://example.com/~me/}{test}.*',
     ),
     (
         # description list: simple