Index: openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/Attic/00-database-procs.tcl,v diff -u -r1.88.2.9 -r1.88.2.10 --- openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 29 Apr 2016 07:56:56 -0000 1.88.2.9 +++ openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 22 Sep 2016 17:30:35 -0000 1.88.2.10 @@ -2594,39 +2594,46 @@ } else { set pghost "-h [db_get_dbhost]" } + + set errno [catch { + cd [file dirname $file] + set fp [open "|[file join [db_get_pgbin] psql] $pghost $pgport $pguser -f $file [db_get_database] $pgpass" "r"] + } errorMsg] - cd [file dirname $file] - set fp [open "|[file join [db_get_pgbin] psql] $pghost $pgport $pguser -f $file [db_get_database] $pgpass" "r"] - - while { [gets $fp line] >= 0 } { - # Don't bother writing out lines which are purely whitespace. - if { ![string is space $line] } { - apm_callback_and_log $callback "[ns_quotehtml $line]\n" + if {$errno > 0} { + set error_found 1 + set error_lines $errorMsg + } else { + while { [gets $fp line] >= 0 } { + # Don't bother writing out lines which are purely whitespace. + if { ![string is space $line] } { + apm_callback_and_log $callback "[ns_quotehtml $line]\n" + } } - } - # PSQL dumps errors and notice information on stderr, and has no option to turn - # this off. So we have to chug through the "error" lines looking for those that - # really signal an error. + # PSQL dumps errors and notice information on stderr, and has no option to turn + # this off. So we have to chug through the "error" lines looking for those that + # really signal an error. - set errno [ catch { - close $fp - } error] + set errno [ catch { + close $fp + } error] - if { $errno == 2 } { - return $error - } + if { $errno == 2 } { + return $error + } - # Just filter out the "NOTICE" lines, so we get the stack dump along with real - # ERRORs. This could be done with a couple of opaque-looking regexps... + # Just filter out the "NOTICE" lines, so we get the stack dump along with real + # ERRORs. This could be done with a couple of opaque-looking regexps... - set error_found 0 - foreach line [split $error "\n"] { - if { [string first NOTICE $line] == -1 } { - append error_lines "$line\n" - set error_found [expr { $error_found - || [string first ERROR $line] != -1 - || [string first FATAL $line] != -1 } ] + set error_found 0 + foreach line [split $error "\n"] { + if { [string first NOTICE $line] == -1 } { + append error_lines "$line\n" + set error_found [expr { $error_found + || [string first ERROR $line] != -1 + || [string first FATAL $line] != -1 } ] + } } }