From 8959d595faeb04bebc0d65d5d6236a9ab1505c6d Mon Sep 17 00:00:00 2001 From: Tung Nguyen Date: Fri, 7 May 2021 00:58:40 +0000 Subject: [PATCH] fix smart auto retry --- lib/terraspace/shell.rb | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/terraspace/shell.rb b/lib/terraspace/shell.rb index d9a261a1..f23404bb 100644 --- a/lib/terraspace/shell.rb +++ b/lib/terraspace/shell.rb @@ -53,14 +53,30 @@ def handle_streams(stdin, stdout, stderr) lines = buffer.split("\n") lines.each do |line| - terraform_to_stdout(line) - handle_input(stdin, line) + if f.fileno == stdout.fileno + handle_stdout(line) + handle_input(stdin, line) + else + handle_stderr(line) + end end end end end end + def handle_stderr(line) + @error ||= Error.new + @error.lines << line # aggregate all error lines + + return if @error.known? + # Sometimes may print a "\e[31m\n" which like during dependencies fetcher init + # suppress it so dont get a bunch of annoying "newlines" + return if line == "\e[31m\n" && @options[:suppress_error_color] + + logger.error(line) + end + def all_eof?(files) files.find { |f| !f.eof }.nil? end @@ -93,7 +109,7 @@ def exit_status(status) end end - def terraform_to_stdout(line) + def handle_stdout(line) prompted = line.include?('Enter a value') @prompt_shown ||= prompted return if @prompt_shown && prompted