Commits

Lars Kanis committed 12a4cbe

Use distinct error class in case the connection is broken.

From 4d5c4301128b81c750d2dbbd0e7e0e6825b4685c Mon Sep 17 00:00:00 2001

  • Participants
  • Parent commits a0972c3

Comments (0)

Files changed (2)

 VALUE rb_hErrors;
 VALUE rb_ePGerror;
 VALUE rb_eServerError;
+VALUE rb_eUnableToSend;
 
 static VALUE
 define_error_class(const char *name, const char *baseclass_code)
 		/* Unable to retrieve the PG_DIAG_SQLSTATE.
 		 * Use the generic error instead.
 		 */
-		klass = rb_ePGerror;
+		klass = rb_eUnableToSend;
 	}
 
 	return klass;
 	rb_define_attr( rb_ePGerror, "result", 1, 0 );
 
 	rb_eServerError = rb_define_class_under( rb_mPG, "ServerError", rb_ePGerror );
+	rb_eUnableToSend = rb_define_class_under( rb_mPG, "UnableToSend", rb_ePGerror );
 
 	#include "errorcodes.def"
 }

spec/pg/connection_spec.rb

 		conn.should be_finished()
 	end
 
+	it "raises proper error when sending fails" do
+		conn = described_class.connect_start( '127.0.0.1', 54320, "", "", "me", "xxxx", "somedb" )
+		expect{ conn.exec 'SELECT 1' }.to raise_error(PG::UnableToSend, /no connection/)
+	end
+
 	it "doesn't leave stale server connections after finish" do
 		described_class.connect(@conninfo).finish
 		sleep 0.5