From 7d09c6b6279d9b6a2c366aae560d75ee6085c3f9 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Tue, 17 Oct 2023 15:41:04 -0400 Subject: [PATCH] Improve Danger comment when CI jobs are canceled (#5285) This often happens when pushing a new commit to a PR while the Danger job for a previous commit is still running. --- Dangerfile | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Dangerfile b/Dangerfile index 6b29d2ef65..f44d086f65 100644 --- a/Dangerfile +++ b/Dangerfile @@ -52,10 +52,23 @@ end file = Tempfile.new('violations') force_flag = has_danger_changes ? "--force" : "" -Open3.popen3("tools/oss-check -v #{force_flag} 2> #{file.path}") do |_, stdout, _, _| - while char = stdout.getc - print char + +begin + Open3.popen3("tools/oss-check -v #{force_flag} 2> #{file.path}") do |_, stdout, _, _| + while char = stdout.getc + print char + end + end +rescue SignalException => e + if e.signo == Signal.list["TERM"] + # Post a nicer message here + fail "OSSCheck was cancelled" + else + raise e end +rescue => e + # Handle other exceptions + fail "OSSCheck error: #{e.message}" end lines = file.read.chomp