Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Propegate exit code from psql rather than error #2008

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions lib/heroku/command/pg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down