Skip to content

Commit

Permalink
transpose: error instead of panic (#74)
Browse files Browse the repository at this point in the history
* Error instead of panic

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Bump to 1.0.2

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
  • Loading branch information
ggwpez authored Feb 5, 2024
1 parent 84a505e commit 5fdf460
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 39 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
12 changes: 8 additions & 4 deletions src/cmd/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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()));
Expand Down
10 changes: 4 additions & 6 deletions tests/integration/orml/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
18 changes: 8 additions & 10 deletions tests/integration/sdk/transpose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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, …)
Expand All @@ -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, …)
Expand All @@ -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!
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/config/v1/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/config/v1/finds_all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/config/v1/version_bin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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
stdout: |
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:
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/root-args/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5fdf460

Please sign in to comment.