Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve error messages in ConanApi init failures #14735

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions conans/client/cache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ def __init__(self, cache_folder):
self._store_folder = self.new_config.get("core.cache:storage_path") or \
os.path.join(self.cache_folder, "p")

mkdir(self._store_folder)
db_filename = os.path.join(self._store_folder, 'cache.sqlite3')
self._data_cache = DataCache(self._store_folder, db_filename)
try:
mkdir(self._store_folder)
db_filename = os.path.join(self._store_folder, 'cache.sqlite3')
self._data_cache = DataCache(self._store_folder, db_filename)
except Exception as e:
raise ConanException(f"Couldn't initialize storage in {self._store_folder}: {e}")

@property
def temp_folder(self):
Expand Down
8 changes: 8 additions & 0 deletions conans/test/integration/ui/exit_with_code_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from conans.paths import CONANFILE
from conans.test.utils.tools import TestClient
from conans.util.files import save


class ExitWithCodeTest(unittest.TestCase):
Expand All @@ -27,3 +28,10 @@ def build(self):
error_code = client.run("build .", assert_error=True)
self.assertEqual(error_code, 34)
self.assertIn("Exiting with code: 34", client.out)


def test_wrong_home_error():
client = TestClient()
save(client.cache.new_config_path, "core.cache:storage_path=P:")
client.run("--version")
assert "Error in Conan initialization: Couldn't initialize storage in" in client.out
12 changes: 8 additions & 4 deletions conans/test/utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
from requests.exceptions import HTTPError
from webtest.app import TestApp

from conan.cli.exit_codes import SUCCESS
from conan.cli.exit_codes import SUCCESS, ERROR_GENERAL
from conan.internal.cache.cache import PackageLayout, RecipeLayout
from conans import REVISIONS
from conan.api.conan_api import ConanAPI
from conan.api.model import Remote
from conan.cli.cli import Cli
from conans.client.cache.cache import ClientCache
from conans.util.env import environment_update
from conans.errors import NotFoundException
from conans.errors import NotFoundException, ConanException
from conans.model.manifest import FileTreeManifest
from conans.model.package_ref import PkgReference
from conans.model.profile import Profile
Expand Down Expand Up @@ -489,8 +489,12 @@ def _run_cli(self, command_line, assert_error=False):

args = shlex.split(command_line)

self.api = ConanAPI(cache_folder=self.cache_folder)
command = Cli(self.api)
try:
self.api = ConanAPI(cache_folder=self.cache_folder)
command = Cli(self.api)
except ConanException as e:
sys.stderr.write("Error in Conan initialization: {}".format(e))
return ERROR_GENERAL

error = SUCCESS
trace = None
Expand Down