Repository: napari/napari

Issue:
Clicking File > Open Folder then cancelling causes a crash
## 🐛 Bug

If I click on File > Open Folder but then hit cancel (in this case, because I actually wanted to open a file, not a folder), I get the following traceback:

```pytb
WARNING: Traceback (most recent call last):
  File "/home/jni/projects/napari/napari/_qt/qt_viewer.py", line 233, in _open_folder
    self._add_files([folder])
  File "/home/jni/projects/napari/napari/_qt/qt_viewer.py", line 247, in _add_files
    self.viewer.add_image(path=filenames)
  File "/home/jni/projects/napari/napari/components/viewer_model.py", line 485, in add_image
    data = io.magic_imread(path)
  File "/home/jni/projects/napari/napari/util/io.py", line 71, in magic_imread
    image = io.imread(filename)
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/skimage/io/_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/skimage/io/manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/skimage/io/_plugins/imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/imageio/core/functions.py", line 264, in imread
    reader = read(uri, format, "i", **kwargs)
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/imageio/core/functions.py", line 182, in get_reader
    "Could not find a format to read the specified file " "in mode %r" % mode
ValueError: Could not find a format to read the specified file in mode 'i'
WARNING:vispy:Traceback (most recent call last):
  File "/home/jni/projects/napari/napari/_qt/qt_viewer.py", line 233, in _open_folder
    self._add_files([folder])
  File "/home/jni/projects/napari/napari/_qt/qt_viewer.py", line 247, in _add_files
    self.viewer.add_image(path=filenames)
  File "/home/jni/projects/napari/napari/components/viewer_model.py", line 485, in add_image
    data = io.magic_imread(path)
  File "/home/jni/projects/napari/napari/util/io.py", line 71, in magic_imread
    image = io.imread(filename)
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/skimage/io/_io.py", line 48, in imread
    img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/skimage/io/manage_plugins.py", line 210, in call_plugin
    return func(*args, **kwargs)
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/skimage/io/_plugins/imageio_plugin.py", line 10, in imread
    return np.asarray(imageio_imread(*args, **kwargs))
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/imageio/core/functions.py", line 264, in imread
    reader = read(uri, format, "i", **kwargs)
  File "/home/jni/miniconda3/envs/f7/lib/python3.7/site-packages/imageio/core/functions.py", line 182, in get_reader
    "Could not find a format to read the specified file " "in mode %r" % mode
ValueError: Could not find a format to read the specified file in mode 'i'
Aborted (core dumped)
```

We probably need to add a check for when the return value is None.


Discussion:

Resolving patch:
diff --git a/napari/_qt/qt_viewer.py b/napari/_qt/qt_viewer.py
--- a/napari/_qt/qt_viewer.py
+++ b/napari/_qt/qt_viewer.py
@@ -219,7 +219,7 @@ def _open_images(self):
             caption='Select image(s)...',
             directory=self._last_visited_dir,  # home dir by default
         )
-        if filenames is not None:
+        if (filenames != []) and (filenames is not None):
             self._add_files(filenames)
 
     def _open_folder(self):
@@ -229,7 +229,7 @@ def _open_folder(self):
             caption='Select folder...',
             directory=self._last_visited_dir,  # home dir by default
         )
-        if folder is not None:
+        if folder not in {'', None}:
             self._add_files([folder])
 
     def _add_files(self, filenames):


Test patch: