From 8543671d4c51e3b9f893333dc2316462a4e12d57 Mon Sep 17 00:00:00 2001 From: Ransom Briggs Date: Fri, 2 Sep 2016 11:29:30 -0500 Subject: [PATCH] Propegate exit code from psql rather than error --- lib/heroku/command/pg.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/heroku/command/pg.rb b/lib/heroku/command/pg.rb index 1417e2c93..b61e0c6b2 100644 --- a/lib/heroku/command/pg.rb +++ b/lib/heroku/command/pg.rb @@ -762,9 +762,19 @@ def exec_sql_on_uri(sql,uri) ENV["PGAPPNAME"] = "#{pgappname} non-interactive" user_part = uri.user ? "-U #{uri.user}" : "" output = `#{psql_cmd} -c "#{sql}" #{user_part} -h #{uri.host} -p #{uri.port || 5432} #{uri.path[1..-1]}` - if (! $?.success?) || output.nil? || output.empty? - raise "psql failed. exit status #{$?.to_i}, output: #{output.inspect}" + + # assume that psql printed something helpful to stderr + # and that dumping stdout at this point would be confusing + unless $?.success? + exit $?.exitstatus + end + + # I do not know the use case for this but keeping + # around for backward compatibility reasons + if output.nil? || output.empty? + raise "psql failed. exit status #{$?.to_i}" end + output rescue Errno::ENOENT output_with_bang "The local psql command could not be located"