Repository: conan-io/conan

Issue:
Remote lookup in offline mode 
Hello,

Following up the small issue that I had during my demo at swampUP:

I was trying to create a package for which I had every build requirement recipe already exported and thus available.

I was expecting to get an error:

>no such package with current options/settings: **build requirement package**

However, it seems that Conan did try to check this package in remotes (with no internet access, it failed). The expected behavior would be for Conan to check the local cache after remotes.

Passing `--build missing` to `conan create` did not fix the issue.

Using Conan v1.3.3

- [x] I've read the [CONTRIBUTING guide](https://raw.githubusercontent.com/conan-io/conan/develop/.github/CONTRIBUTING.md).
- [x] I've specified the Conan version, operating system version and any tool that can be relevant.
- [x] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.




Discussion:
Well, it could be problematic. If you have remotes configured, and Conan can't connect with the remotes, for me it is not an automatic thing to do to continue as no packages had been found, because something not expected happened.

I'm not suggesting to do it, but in these cases, some explicit user intervention like activating an "offline mode" could be valid, but without user intervention, your suggestion could be dangerous for a CI server, where you expect the build to fail if internet fails.

By the way, many thanks for your talk in swampup, it was amazing, we really appreciate your effort and long travel! 👍 
Thanks! Was great to be there and meet you guys (after some travel difficulties).

Indeed, I did not take the CI server use-case into account, so an offline mode as an opt-in seems good.
The bigger issue is that there's no output telling you which dependency is causing conan to go out and search on a remote in the first place.

Assuming you have the conan recipes for your dependencies available locally, it becomes a guessing game to figure out what you need to go and build.

The alternative is to remove the remote entirely, so at least you are told which dependency can't be found.
@remleduff Thanks for reporting.
Do you have a recent trace (console output) to help? Something should be printed telling you what is trying to download and not being found. 
The situation is a little more complicated than I realized. I believe that the missing output only happens if you have the recipe in your cache, but don't have the package for the correct build type.

Reproduce by (using conan-boost as an example):
1) cd conan-boost
2) conan remove zlib
3) disableNetwork && conan create . user/channel -s buildType=Release
 > #This fails with a useful error message
 > zlib/1.2.11@conan/stable: Not found in local cache, looking in remotes...
 > zlib/1.2.11@conan/stable: Trying with 'conan-center'...
 > ERROR: Failed requirement 'zlib/1.2.11@conan/stable' from 'boost/1.63.0@aaron/foo'
 > ERROR: HTTPSConnectionPool(host='conan.bintray.com', port=443): Max retries exceeded with url:  > /v1/ping (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f7ce2983290>: Failed to establish a new connection: [Errno -2] Name or service not known',))
 > 
 > Unable to connect to conan-center=https://conan.bintray.com
4) enableNetwork && conan install  zlib/1.2.11@conan/stable -s buildType=Debug # install zlib with wrong build type
5) disableNetwork && conan create . user/channel -s buildType=Release
 > #This fails with an unhelpful error message
 > ERROR: HTTPSConnectionPool(host='conan.bintray.com', port=443): Max retries exceeded with url: /v1/ping  
 > (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f1ade35db90>: Failed to establish a new connection: [Errno -2] Name or service not known',))
  > 
  > Unable to connect to conan-center=https://conan.bintray.com
  > 

Transcript follows:
[output.txt](https://github.com/conan-io/conan/files/3027017/output.txt)

 
Same problem in slack:

https://cpplang.slack.com/archives/C41CWV9HA/p1554172467257200

Actually, this is the same issue with worse symptoms. If the remote is down but your internet is up, you would expect to be able to build other versions of the package, because you have the recipe in your cache.

Resolving patch:
diff --git a/conans/client/graph/graph_binaries.py b/conans/client/graph/graph_binaries.py
--- a/conans/client/graph/graph_binaries.py
+++ b/conans/client/graph/graph_binaries.py
@@ -121,6 +121,9 @@ def _evaluate_node(self, node, build_mode, update, evaluated_nodes, remote_name)
                     remote_info, pref = self._remote_manager.get_package_info(pref, remote)
                 except NotFoundException:
                     pass
+                except Exception:
+                    conanfile.output.error("Error downloading binary package: '{}'".format(pref))
+                    raise
 
             # If the "remote" came from the registry but the user didn't specified the -r, with
             # revisions iterate all remotes


Test patch:
diff --git a/conans/test/integration/install_update_test.py b/conans/test/integration/install_update_test.py
--- a/conans/test/integration/install_update_test.py
+++ b/conans/test/integration/install_update_test.py
@@ -7,7 +7,8 @@
 from conans.model.ref import ConanFileReference, PackageReference
 from conans.paths import CONAN_MANIFEST
 from conans.test.utils.cpp_test_files import cpp_hello_conan_files
-from conans.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient, TestServer
+from conans.test.utils.tools import NO_SETTINGS_PACKAGE_ID, TestClient, TestServer, \
+    TurboTestClient, GenConanfile
 from conans.util.files import load, save
 
 
@@ -292,3 +293,22 @@ def package(self):
         pref = PackageReference(ref, NO_SETTINGS_PACKAGE_ID)
         header = os.path.join(client.cache.package(pref), "header.h")
         self.assertEqual(load(header), "mycontent2")
+
+    def fail_usefully_when_failing_retrieving_package_test(self):
+        ref = ConanFileReference.loads("lib/1.0@conan/stable")
+        ref2 = ConanFileReference.loads("lib2/1.0@conan/stable")
+        client = TurboTestClient(servers={"default": TestServer()})
+        pref1 = client.create(ref)
+        client.upload_all(ref)
+
+        client.create(ref2, conanfile=GenConanfile().with_requirement(ref))
+        client.upload_all(ref2)
+
+        # remove only the package from pref1
+        client.run("remove {} -p {} -f".format(pref1.ref, pref1.id))
+
+        # Now fake the remote url to force a network failure
+        client.run("remote update default http://this_not_exist8823.com")
+        # Try to install ref2, it will try to download the binary for ref1
+        client.run("install {}".format(ref2), assert_error=True)
+        self.assertIn("ERROR: Error downloading binary package: '{}'".format(pref1), client.out)
\ No newline at end of file