Repository: iterative/dvc

Issue:
import: Doesn't remove temporary files when download failed
*DVC version*: 0.23.2

`dvc import 'https://en.wikipedia.org/wiki/Main_Page'`

```
Importing 'https://en.wikipedia.org/wiki/Main_Page' -> '/home/mroutis/tmp/Main_Page'
[##############################] 100% Main_Page
Error: failed to import https://en.wikipedia.org/wiki/Main_Page - could not find an ETag for 'https://en.wikipedia.org/wiki/Main_Page'
```

`ls ~/tmp` -> `Main_Page`

---

`dvc import https://s3-us-west-2.amazonaws.com/dvc-share/get-started/data.xml`

```
Importing 'https://s3-us-west-2.amazonaws.com/dvc-share/get-started/data.xml' -> '/home/mroutis/tmp/data.xml'
[##                            ] 7% data.xml^CError: interrupted by the user

Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!
```

`ls ~/tmp` -> `data.xml.e5f6cf5a-a919-43bf-949b-dfd3754227f1`


Discussion:
Although, it would be great if you could resume "importing" big files :thinking: 
Also, there's the oportunity to show a better message, like: `failed te import x... You can add it with dvc add` or something more acitonable

Resolving patch:
diff --git a/dvc/command/imp.py b/dvc/command/imp.py
--- a/dvc/command/imp.py
+++ b/dvc/command/imp.py
@@ -17,6 +17,8 @@ def run(self):
 
             self.project.imp(self.args.url, out)
         except DvcException:
-            logger.error('failed to import {}'.format(self.args.url))
+            logger.error('failed to import {}. You could also try downloading '
+                         'it manually and adding it with `dvc add` command.'
+                         .format(self.args.url))
             return 1
         return 0


Test patch:
diff --git a/tests/test_import.py b/tests/test_import.py
--- a/tests/test_import.py
+++ b/tests/test_import.py
@@ -1,10 +1,17 @@
 import os
 from uuid import uuid4
 
+from dvc import logger
+from dvc.exceptions import DvcException
 from dvc.main import main
-
+from mock import patch
 from tests.basic_env import TestDvc
 
+try:
+    from StringIO import StringIO
+except ImportError:
+    from io import StringIO
+
 
 class TestCmdImport(TestDvc):
     def test(self):
@@ -33,3 +40,28 @@ def test(self):
         self.assertEqual(ret, 0)
         self.assertTrue(os.path.exists(filename))
         self.assertEqual(open(filename).read(), 'content')
+
+
+class TestFailedImportMessage(TestDvc):
+    color_patch = patch.object(logger, 'colorize', new=lambda x, color='': x)
+
+    def test(self):
+        self.color_patch.start()
+        self._test()
+        self.color_patch.stop()
+
+    @patch('dvc.command.imp.urlparse')
+    def _test(self, imp_urlparse_patch):
+        logger.logger.handlers[1].stream = StringIO()
+        page_address = 'http://somesite.com/file_name'
+
+        def dvc_exception(*args, **kwargs):
+            raise DvcException('message')
+
+        imp_urlparse_patch.side_effect = dvc_exception
+        main(['import', page_address])
+        self.assertIn('Error: failed to import '
+                      'http://somesite.com/file_name. You could also try '
+                      'downloading it manually and adding it with `dvc add` '
+                      'command.',
+                      logger.logger.handlers[1].stream.getvalue())