History

Fix #85

Sebastian Thiel committed 5 years ago

Commit 39fb6121 parent b792ff77 files · +58 −3Browse files

Unified · Split

7 files
  1. src/porcelain/main.rs +9 −0
  2. src/porcelain/options.rs +2 −0
  3. src/shared.rs +18 −3
  4. tests/snapshots/panic-behaviour/expected-failure +2 −0
  5. tests/snapshots/panic-behaviour/expected-failure-in-thread +2 −0
  6. tests/snapshots/panic-behaviour/expected-failure-in-thread-with-progress +3 −0
  7. tests/stateless-journey.sh +22 −0
src/porcelain/main.rs+9−0
@@ -13,6 +13,15 @@ pub fn main() -> Result<()> { · 12 unmodified lines
13 let progress_keep_open = args.progress_keep_open;13 let progress_keep_open = args.progress_keep_open;
14 14
15 match args.cmd {15 match args.cmd {
16 #[cfg(debug_assertions)]
17 Subcommands::Panic => prepare_and_run(
18 "panic-behaviour",
19 verbose,
20 progress,
21 progress_keep_open,
22 crate::shared::STANDARD_RANGE,
23 move |_progress, _out, _err| panic!("something went very wrong"),
24 ),
16 Subcommands::Init { directory } => core::repository::init(directory),25 Subcommands::Init { directory } => core::repository::init(directory),
17 Subcommands::Tools(tool) => match tool {26 Subcommands::Tools(tool) => match tool {
18 ToolCommands::EstimateHours(EstimateHours {27 ToolCommands::EstimateHours(EstimateHours {
src/porcelain/options.rs+2−0
@@ -40,6 +40,8 @@ pub enum Subcommands { · 39 unmodified lines
40 #[clap(setting = AppSettings::ColoredHelp, setting = AppSettings::DisableVersion, setting = AppSettings::SubcommandRequired)]40 #[clap(setting = AppSettings::ColoredHelp, setting = AppSettings::DisableVersion, setting = AppSettings::SubcommandRequired)]
41 #[clap(visible_alias = "t")]41 #[clap(visible_alias = "t")]
42 Tools(ToolCommands),42 Tools(ToolCommands),
43 #[cfg(debug_assertions)]
44 Panic,
43}45}
44 46
45#[derive(Debug, Clap)]47#[derive(Debug, Clap)]
src/shared.rs+18−3
@@ -91,6 +91,7 @@ pub mod pretty { · 90 unmodified lines
91 (true, false) => {91 (true, false) => {
92 enum Event<T> {92 enum Event<T> {
93 UiDone,93 UiDone,
94 ComputationFailed,
94 ComputationDone(Result<T>),95 ComputationDone(Result<T>),
95 }96 }
96 let progress = crate::shared::progress_tree();97 let progress = crate::shared::progress_tree();
@@ -109,19 +110,33 @@ pub mod pretty { · 12 unmodified lines
109 });110 });
110 // LIMITATION: This will hang if the thread panics as no message is send and the renderer thread will wait forever.111 // LIMITATION: This will hang if the thread panics as no message is send and the renderer thread will wait forever.
111 // `catch_unwind` can't be used as a parking lot mutex is not unwind safe, coming from prodash.112 // `catch_unwind` can't be used as a parking lot mutex is not unwind safe, coming from prodash.
112 std::thread::spawn(move || {113 let join_handle = std::thread::spawn(move || {
113 let res = run(Some(sub_progress), &mut stdout(), &mut stderr());114 let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
114 tx.send(Event::ComputationDone(res)).ok();115 run(Some(sub_progress), &mut stdout(), &mut stderr())
116 }));
117 match res {
118 Ok(res) => tx.send(Event::ComputationDone(res)).ok(),
119 Err(err) => {
120 tx.send(Event::ComputationFailed).ok();
121 std::panic::resume_unwind(err)
122 }
123 }
115 });124 });
116 match rx.recv()? {125 match rx.recv()? {
117 Event::UiDone => {126 Event::UiDone => {
118 ui_handle.shutdown_and_wait();127 ui_handle.shutdown_and_wait();
128 drop(join_handle);
119 Err(anyhow!("Operation cancelled by user"))129 Err(anyhow!("Operation cancelled by user"))
120 }130 }
121 Event::ComputationDone(res) => {131 Event::ComputationDone(res) => {
122 ui_handle.shutdown_and_wait();132 ui_handle.shutdown_and_wait();
133 join_handle.join().ok();
123 res134 res
124 }135 }
136 Event::ComputationFailed => match join_handle.join() {
137 Ok(_) => unreachable!("The thread has panicked and unwrap is expected to show it"),
138 Err(err) => std::panic::resume_unwind(err),
139 },
125 }140 }
126 }141 }
127 (true, true) | (false, true) => {142 (true, true) | (false, true) => {
tests/snapshots/panic-behaviour/expected-failure+2−0
@@ -0,0 +1,2 @@
1thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:23:42
2note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
tests/snapshots/panic-behaviour/expected-failure-in-thread+2−0
@@ -0,0 +1,2 @@
1thread '<unnamed>' panicked at 'something went very wrong', src/porcelain/main.rs:23:42
2note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
tests/snapshots/panic-behaviour/expected-failure-in-thread-with-progress+3−0
@@ -0,0 +1,3 @@
1[?1049h[?25lthread '<unnamed>' panicked at 'something went very wrong', src/porcelain/main.rs:23:42
2note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
3[?25h[?1049lError: receiving on a closed channel
tests/stateless-journey.sh+22−0
@@ -80,6 +80,28 @@ function small-repo-in-sandbox() { · 79 unmodified lines
80if test "$kind" = "max"; then80if test "$kind" = "max"; then
81title "Porcelain ${kind}"81title "Porcelain ${kind}"
82(82(
83 (when "running a debug-only panic test"
84 snapshot="$snapshot/panic-behaviour"
85 (with "the --quiet option set"
86 it "fails as expected" && {
87 WITH_SNAPSHOT="$snapshot/expected-failure" \
88 expect_run_sh 101 "$exe -q panic"
89 }
90 )
91
92 (with "NO --quiet option set"
93 it "fails as expected" && {
94 WITH_SNAPSHOT="$snapshot/expected-failure-in-thread" \
95 expect_run_sh 101 "$exe panic"
96 }
97 )
98 (with "progress option set"
99 it "fails as expected" && {
100 WITH_SNAPSHOT="$snapshot/expected-failure-in-thread-with-progress" \
101 expect_run_sh $WITH_FAILURE "$exe --progress panic"
102 }
103 )
104 )
83 snapshot="$snapshot/porcelain"105 snapshot="$snapshot/porcelain"
84 (with_program tree106 (with_program tree
85 (when "using the 'tools' subcommand"107 (when "using the 'tools' subcommand"

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t