diff --git a/lib/spack/spack/installer.py b/lib/spack/spack/installer.py
index db82844cc5acae8b625bded16052ffd062d4ada4..bd38d11ea2e99596df4991e5919584889b9a1dee 100755
--- a/lib/spack/spack/installer.py
+++ b/lib/spack/spack/installer.py
@@ -1154,7 +1154,7 @@ def build_process():
         except StopIteration as e:
             # A StopIteration exception means that do_install was asked to
             # stop early from clients.
-            tty.msg('{0} {1}'.format(self.pid, e.message))
+            tty.msg('{0} {1}'.format(self.pid, str(e)))
             tty.msg('Package stage directory : {0}'
                     .format(pkg.stage.source_path))
 
diff --git a/lib/spack/spack/test/installer.py b/lib/spack/spack/test/installer.py
index eadebfd3e45b2575d3842b39a8a0ca84f5b99453..e2e0705e931b4756e6976df4f440c6239c7f991a 100644
--- a/lib/spack/spack/test/installer.py
+++ b/lib/spack/spack/test/installer.py
@@ -391,6 +391,27 @@ def test_install_task_use_cache(install_mockery, monkeypatch):
     assert spec.package.name in installer.installed
 
 
+def test_install_task_stop_iter(install_mockery, monkeypatch, capfd):
+    """Test _install_task to cover the StopIteration exception."""
+    mock_err_msg = 'mock stop iteration'
+
+    def _raise(installer, pkg):
+        raise StopIteration(mock_err_msg)
+
+    spec, installer = create_installer('a')
+    task = create_build_task(spec.package)
+
+    monkeypatch.setattr(spack.package.PackageBase, 'unit_test_check', _true)
+    monkeypatch.setattr(inst.PackageInstaller, '_setup_install_dir', _raise)
+
+    installer._install_task(task)
+    out = capfd.readouterr()[0]
+
+    assert mock_err_msg in out
+    assert 'Package stage directory' in out
+    assert spec.package.stage.source_path in out
+
+
 def test_release_lock_write_n_exception(install_mockery, tmpdir, capsys):
     """Test _release_lock for supposed write lock with exception."""
     spec, installer = create_installer('trivial-install-test-package')