From 5fdf46049c1defabd53a46b74b3a959e8cbbe09a Mon Sep 17 00:00:00 2001 From: Oliver Tale-Yazdi Date: Mon, 5 Feb 2024 17:46:16 +0100 Subject: [PATCH] transpose: error instead of panic (#74) * Error instead of panic Signed-off-by: Oliver Tale-Yazdi * Bump to 1.0.2 Signed-off-by: Oliver Tale-Yazdi --------- Signed-off-by: Oliver Tale-Yazdi --- CHANGELOG.md | 5 +++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/cmd/transpose.rs | 12 ++++++++---- tests/integration/orml/release.yaml | 10 ++++------ tests/integration/sdk/transpose.yaml | 18 ++++++++---------- tests/ui/config/v1/basic.yaml | 10 +++++----- tests/ui/config/v1/finds_all.yaml | 16 ++++++++-------- tests/ui/config/v1/version_bin.yaml | 4 ++-- tests/ui/root-args/version.yaml | 4 ++-- 10 files changed, 44 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b6d78e..3396d9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [1.0.2] - 2024-02-02 + +### Fixed +- Let `transpose` exit with code 1 on error instead of panic. + ## [0.15.0] - 2023-11-14 ### Added diff --git a/Cargo.lock b/Cargo.lock index 8e38094..d4c1f0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1504,7 +1504,7 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zepter" -version = "1.0.1" +version = "1.0.2" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index 7aa7ba3..0dc41a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "zepter" -version = "1.0.1" +version = "1.0.2" edition = "2021" authors = [ "Oliver Tale-Yazdi" ] description = "Analyze, Fix and Format features in your Rust workspace." diff --git a/src/cmd/transpose.rs b/src/cmd/transpose.rs index 16f471c..ada24ed 100644 --- a/src/cmd/transpose.rs +++ b/src/cmd/transpose.rs @@ -160,16 +160,18 @@ impl LiftToWorkspaceCmd { }, }; let hint = format!("cargo upgrade -p {}@{version_hint}", &self.dependency); - panic!( + eprintln!( "\nFound {} different versions of '{}' in the workspace:\n\n{err}\nHint: {}\n", versions.len(), &self.dependency, g.bold(&hint), ); + std::process::exit(1); } let Some(version) = by_version.keys().next() else { - panic!("Could not find any dependency named '{}'", g.red(&self.dependency)); + eprintln!("Could not find any dependency named '{}'", g.red(&self.dependency)); + std::process::exit(1); }; let _ = version; let _found: usize = by_version.values().map(Vec::len).sum(); @@ -248,7 +250,8 @@ impl StripDevDepsCmd { for name in self.packages.iter().flatten() { if !meta.packages.iter().any(|p| p.name == *name) { - panic!("Could not find package named '{}'", g.red(name)); + eprintln!("Could not find package named '{}'", g.red(name)); + std::process::exit(1); } } @@ -278,7 +281,8 @@ impl StripDevDepsCmd { for dep in only_dev.iter() { // Account for renamed crates: let Some(dep) = resolve_dep(pkg, dep, &meta) else { - panic!("Could not resolve dependency '{}'", g.red(&dep.name)); + eprintln!("Could not resolve dependency '{}'", g.red(&dep.name)); + std::process::exit(1); }; fixer.remove_feature(&format!("{}/", dep.name())); diff --git a/tests/integration/orml/release.yaml b/tests/integration/orml/release.yaml index 6bf559f..f7fd2d5 100644 --- a/tests/integration/orml/release.yaml +++ b/tests/integration/orml/release.yaml @@ -5,15 +5,13 @@ cases: - cmd: transpose features strip-dev-only -p asdf stderr: | [WARN] Unstable feature - do not rely on this! - thread 'main' panicked at 'Could not find package named 'asdf'', src/cmd/transpose.rs:251:17 - note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace - code: 101 + Could not find package named 'asdf' + code: 1 - cmd: transpose features strip-dev-only -p orml-asset-registry,asdf stderr: | [WARN] Unstable feature - do not rely on this! - thread 'main' panicked at 'Could not find package named 'asdf'', src/cmd/transpose.rs:251:17 - note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace - code: 101 + Could not find package named 'asdf' + code: 1 - cmd: transpose features strip-dev-only stderr: | [WARN] Unstable feature - do not rely on this! diff --git a/tests/integration/sdk/transpose.yaml b/tests/integration/sdk/transpose.yaml index 8e2eaf1..0c3e89f 100644 --- a/tests/integration/sdk/transpose.yaml +++ b/tests/integration/sdk/transpose.yaml @@ -3,9 +3,9 @@ repo: ref: c86b633695299ed27053940d5ea5c5a2392964b3 cases: - cmd: transpose dependency lift-to-workspace parity-scale-codec - stderr: | + stderr: |+ [WARN] Unstable feature - do not rely on this! - thread 'main' panicked at ' + Found 6 different versions of 'parity-scale-codec' in the workspace: ^3.6.1: 244 times (frame-support, sp-api, sp-core, …) @@ -16,13 +16,12 @@ cases: ^3.4.0: 4 times (asset-hub-rococo-integration-tests, integration-tests-common, asset-hub-westend-integration-tests, …) Hint: cargo upgrade -p parity-scale-codec@3.6.4 - ', src/cmd/transpose.rs:163:13 - note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace - code: 101 + + code: 1 - cmd: transpose dependency lift-to-workspace log - stderr: | + stderr: |+ [WARN] Unstable feature - do not rely on this! - thread 'main' panicked at ' + Found 8 different versions of 'log' in the workspace: ^0.4.17: 135 times (frame-support, sp-api, sp-core, …) @@ -35,9 +34,8 @@ cases: ^0.4.8 : 1 time (sc-consensus-grandpa-rpc) Hint: cargo upgrade -p log@0.4.20 - ', src/cmd/transpose.rs:163:13 - note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace - code: 101 + + code: 1 - cmd: zepter transpose dependency lift-to-workspace macro_magic stderr: | [WARN] Unstable feature - do not rely on this! diff --git a/tests/ui/config/v1/basic.yaml b/tests/ui/config/v1/basic.yaml index b217916..98f2445 100644 --- a/tests/ui/config/v1/basic.yaml +++ b/tests/ui/config/v1/basic.yaml @@ -3,25 +3,25 @@ crates: cases: - cmd: run default stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version - cmd: run stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version - cmd: '' stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version - cmd: run my_version stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'my_version' [INFO] 1/1 --version @@ -38,7 +38,7 @@ cases: [INFO] 1/1 debug --no-benchmark - cmd: run both stdout: |+ - zepter 1.0.1 + zepter 1.0.2 Num workspace members: 1 Num dependencies: 1 DAG nodes: 0, links: 0 diff --git a/tests/ui/config/v1/finds_all.yaml b/tests/ui/config/v1/finds_all.yaml index 62c06c4..18aa925 100644 --- a/tests/ui/config/v1/finds_all.yaml +++ b/tests/ui/config/v1/finds_all.yaml @@ -3,7 +3,7 @@ crates: cases: - cmd: '' stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version @@ -19,7 +19,7 @@ cases: - [ '--version' ] - cmd: '' stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version @@ -35,7 +35,7 @@ cases: - [ '--version' ] - cmd: '' stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version @@ -51,7 +51,7 @@ cases: - [ '--version' ] - cmd: run default stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version @@ -67,7 +67,7 @@ cases: - [ '--version' ] - cmd: run default stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version @@ -83,7 +83,7 @@ cases: - [ '--version' ] - cmd: run default stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version @@ -99,7 +99,7 @@ cases: - [ '--version' ] - cmd: run default --config .cargo/polkadot.yaml stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version @@ -115,7 +115,7 @@ cases: - [ '--version' ] - cmd: run default -c .cargo/polkadot.yaml stdout: | - zepter 1.0.1 + zepter 1.0.2 stderr: | [INFO] Running workflow 'default' [INFO] 1/1 --version diff --git a/tests/ui/config/v1/version_bin.yaml b/tests/ui/config/v1/version_bin.yaml index 777d598..02b5c36 100644 --- a/tests/ui/config/v1/version_bin.yaml +++ b/tests/ui/config/v1/version_bin.yaml @@ -3,7 +3,7 @@ crates: cases: - cmd: run default stderr: | - thread 'main' panicked at 'Invalid config file: "Config file version is too new. The file requires at least version 2.0.0, but the current version is 1.0.1. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."', src/cmd/run.rs:27:46 + thread 'main' panicked at 'Invalid config file: "Config file version is too new. The file requires at least version 2.0.0, but the current version is 1.0.2. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."', src/cmd/run.rs:27:46 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace code: 101 - cmd: run default --check-cfg-compatibility=off @@ -11,7 +11,7 @@ cases: Error: Command '' failed with exit code 101 stderr: | [INFO] Running workflow 'default' - thread 'main' panicked at 'Invalid config file: "Config file version is too new. The file requires at least version 2.0.0, but the current version is 1.0.1. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."', src/cmd/run.rs:27:46 + thread 'main' panicked at 'Invalid config file: "Config file version is too new. The file requires at least version 2.0.0, but the current version is 1.0.2. Please update Zepter or ignore this check with `--check-cfg-compatibility=off`."', src/cmd/run.rs:27:46 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace code: 1 configs: diff --git a/tests/ui/root-args/version.yaml b/tests/ui/root-args/version.yaml index 45c2968..0047b51 100644 --- a/tests/ui/root-args/version.yaml +++ b/tests/ui/root-args/version.yaml @@ -2,7 +2,7 @@ crates: [] cases: - cmd: --version stdout: | - zepter 1.0.1 + zepter 1.0.2 - cmd: -V stdout: | - zepter 1.0.1 + zepter 1.0.2