From dc7168c2eba754d85de7e252dd9310670f86ab6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Wed, 31 Jan 2024 11:14:14 +0100 Subject: [PATCH] Output a readable error for missing `Cargo.toml` file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michał Górny --- pycargoebuild/__main__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pycargoebuild/__main__.py b/pycargoebuild/__main__.py index 10a2935..71543c9 100644 --- a/pycargoebuild/__main__.py +++ b/pycargoebuild/__main__.py @@ -249,7 +249,15 @@ def repack_crates(tar_out: tarfile.TarFile, crates: typing.Set[Crate] = set() pkg_metas = [] for directory in args.directory: - with open(directory / "Cargo.toml", "rb") as f: + try: + f = open(directory / "Cargo.toml", "rb") + except FileNotFoundError: + logging.error(f"'Cargo.toml' not found in {str(directory)!r}") + logging.info( + "Please pass the path to a directory containing 'Cargo.toml' " + "as an argument.") + return 1 + with f: workspace = get_workspace_root(directory) crates.update(workspace.crates) pkg_metas.append(