@@ -278,7 +278,8 @@ libpqrcv_get_conninfo(WalReceiverConn *conn)
278
278
279
279
if (conn_opts == NULL )
280
280
ereport (ERROR ,
281
- (errmsg ("could not parse connection string: %s" ,
281
+ (errcode (ERRCODE_OUT_OF_MEMORY ),
282
+ errmsg ("could not parse connection string: %s" ,
282
283
_ ("out of memory" ))));
283
284
284
285
/* build a clean connection string from pieces */
@@ -350,7 +351,8 @@ libpqrcv_identify_system(WalReceiverConn *conn, TimeLineID *primary_tli)
350
351
{
351
352
PQclear (res );
352
353
ereport (ERROR ,
353
- (errmsg ("could not receive database system identifier and timeline ID from "
354
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
355
+ errmsg ("could not receive database system identifier and timeline ID from "
354
356
"the primary server: %s" ,
355
357
pchomp (PQerrorMessage (conn -> streamConn )))));
356
358
}
@@ -361,7 +363,8 @@ libpqrcv_identify_system(WalReceiverConn *conn, TimeLineID *primary_tli)
361
363
362
364
PQclear (res );
363
365
ereport (ERROR ,
364
- (errmsg ("invalid response from primary server" ),
366
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
367
+ errmsg ("invalid response from primary server" ),
365
368
errdetail ("Could not identify system: got %d rows and %d fields, expected %d rows and %d or more fields." ,
366
369
ntuples , nfields , 3 , 1 )));
367
370
}
@@ -437,13 +440,15 @@ libpqrcv_startstreaming(WalReceiverConn *conn,
437
440
pubnames_str = stringlist_to_identifierstr (conn -> streamConn , pubnames );
438
441
if (!pubnames_str )
439
442
ereport (ERROR ,
440
- (errmsg ("could not start WAL streaming: %s" ,
443
+ (errcode (ERRCODE_OUT_OF_MEMORY ), /* likely guess */
444
+ errmsg ("could not start WAL streaming: %s" ,
441
445
pchomp (PQerrorMessage (conn -> streamConn )))));
442
446
pubnames_literal = PQescapeLiteral (conn -> streamConn , pubnames_str ,
443
447
strlen (pubnames_str ));
444
448
if (!pubnames_literal )
445
449
ereport (ERROR ,
446
- (errmsg ("could not start WAL streaming: %s" ,
450
+ (errcode (ERRCODE_OUT_OF_MEMORY ), /* likely guess */
451
+ errmsg ("could not start WAL streaming: %s" ,
447
452
pchomp (PQerrorMessage (conn -> streamConn )))));
448
453
appendStringInfo (& cmd , ", publication_names %s" , pubnames_literal );
449
454
PQfreemem (pubnames_literal );
@@ -472,7 +477,8 @@ libpqrcv_startstreaming(WalReceiverConn *conn,
472
477
{
473
478
PQclear (res );
474
479
ereport (ERROR ,
475
- (errmsg ("could not start WAL streaming: %s" ,
480
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
481
+ errmsg ("could not start WAL streaming: %s" ,
476
482
pchomp (PQerrorMessage (conn -> streamConn )))));
477
483
}
478
484
PQclear (res );
@@ -495,7 +501,8 @@ libpqrcv_endstreaming(WalReceiverConn *conn, TimeLineID *next_tli)
495
501
if (PQputCopyEnd (conn -> streamConn , NULL ) <= 0 ||
496
502
PQflush (conn -> streamConn ))
497
503
ereport (ERROR ,
498
- (errmsg ("could not send end-of-streaming message to primary: %s" ,
504
+ (errcode (ERRCODE_CONNECTION_FAILURE ),
505
+ errmsg ("could not send end-of-streaming message to primary: %s" ,
499
506
pchomp (PQerrorMessage (conn -> streamConn )))));
500
507
501
508
* next_tli = 0 ;
@@ -517,7 +524,8 @@ libpqrcv_endstreaming(WalReceiverConn *conn, TimeLineID *next_tli)
517
524
*/
518
525
if (PQnfields (res ) < 2 || PQntuples (res ) != 1 )
519
526
ereport (ERROR ,
520
- (errmsg ("unexpected result set after end-of-streaming" )));
527
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
528
+ errmsg ("unexpected result set after end-of-streaming" )));
521
529
* next_tli = pg_strtoint32 (PQgetvalue (res , 0 , 0 ));
522
530
PQclear (res );
523
531
@@ -531,7 +539,8 @@ libpqrcv_endstreaming(WalReceiverConn *conn, TimeLineID *next_tli)
531
539
/* End the copy */
532
540
if (PQendcopy (conn -> streamConn ))
533
541
ereport (ERROR ,
534
- (errmsg ("error while shutting down streaming COPY: %s" ,
542
+ (errcode (ERRCODE_CONNECTION_FAILURE ),
543
+ errmsg ("error while shutting down streaming COPY: %s" ,
535
544
pchomp (PQerrorMessage (conn -> streamConn )))));
536
545
537
546
/* CommandComplete should follow */
@@ -540,15 +549,17 @@ libpqrcv_endstreaming(WalReceiverConn *conn, TimeLineID *next_tli)
540
549
541
550
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
542
551
ereport (ERROR ,
543
- (errmsg ("error reading result of streaming command: %s" ,
552
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
553
+ errmsg ("error reading result of streaming command: %s" ,
544
554
pchomp (PQerrorMessage (conn -> streamConn )))));
545
555
PQclear (res );
546
556
547
557
/* Verify that there are no more results */
548
558
res = libpqrcv_PQgetResult (conn -> streamConn );
549
559
if (res != NULL )
550
560
ereport (ERROR ,
551
- (errmsg ("unexpected result after CommandComplete: %s" ,
561
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
562
+ errmsg ("unexpected result after CommandComplete: %s" ,
552
563
pchomp (PQerrorMessage (conn -> streamConn )))));
553
564
}
554
565
@@ -574,7 +585,8 @@ libpqrcv_readtimelinehistoryfile(WalReceiverConn *conn,
574
585
{
575
586
PQclear (res );
576
587
ereport (ERROR ,
577
- (errmsg ("could not receive timeline history file from "
588
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
589
+ errmsg ("could not receive timeline history file from "
578
590
"the primary server: %s" ,
579
591
pchomp (PQerrorMessage (conn -> streamConn )))));
580
592
}
@@ -585,7 +597,8 @@ libpqrcv_readtimelinehistoryfile(WalReceiverConn *conn,
585
597
586
598
PQclear (res );
587
599
ereport (ERROR ,
588
- (errmsg ("invalid response from primary server" ),
600
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
601
+ errmsg ("invalid response from primary server" ),
589
602
errdetail ("Expected 1 tuple with 2 fields, got %d tuples with %d fields." ,
590
603
ntuples , nfields )));
591
604
}
@@ -746,7 +759,8 @@ libpqrcv_receive(WalReceiverConn *conn, char **buffer,
746
759
/* Try consuming some data. */
747
760
if (PQconsumeInput (conn -> streamConn ) == 0 )
748
761
ereport (ERROR ,
749
- (errmsg ("could not receive data from WAL stream: %s" ,
762
+ (errcode (ERRCODE_CONNECTION_FAILURE ),
763
+ errmsg ("could not receive data from WAL stream: %s" ,
750
764
pchomp (PQerrorMessage (conn -> streamConn )))));
751
765
752
766
/* Now that we've consumed some input, try again */
@@ -782,7 +796,8 @@ libpqrcv_receive(WalReceiverConn *conn, char **buffer,
782
796
return -1 ;
783
797
784
798
ereport (ERROR ,
785
- (errmsg ("unexpected result after CommandComplete: %s" ,
799
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
800
+ errmsg ("unexpected result after CommandComplete: %s" ,
786
801
PQerrorMessage (conn -> streamConn ))));
787
802
}
788
803
@@ -797,13 +812,15 @@ libpqrcv_receive(WalReceiverConn *conn, char **buffer,
797
812
{
798
813
PQclear (res );
799
814
ereport (ERROR ,
800
- (errmsg ("could not receive data from WAL stream: %s" ,
815
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
816
+ errmsg ("could not receive data from WAL stream: %s" ,
801
817
pchomp (PQerrorMessage (conn -> streamConn )))));
802
818
}
803
819
}
804
820
if (rawlen < -1 )
805
821
ereport (ERROR ,
806
- (errmsg ("could not receive data from WAL stream: %s" ,
822
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
823
+ errmsg ("could not receive data from WAL stream: %s" ,
807
824
pchomp (PQerrorMessage (conn -> streamConn )))));
808
825
809
826
/* Return received messages to caller */
@@ -822,7 +839,8 @@ libpqrcv_send(WalReceiverConn *conn, const char *buffer, int nbytes)
822
839
if (PQputCopyData (conn -> streamConn , buffer , nbytes ) <= 0 ||
823
840
PQflush (conn -> streamConn ))
824
841
ereport (ERROR ,
825
- (errmsg ("could not send data to WAL stream: %s" ,
842
+ (errcode (ERRCODE_CONNECTION_FAILURE ),
843
+ errmsg ("could not send data to WAL stream: %s" ,
826
844
pchomp (PQerrorMessage (conn -> streamConn )))));
827
845
}
828
846
@@ -875,7 +893,8 @@ libpqrcv_create_slot(WalReceiverConn *conn, const char *slotname,
875
893
{
876
894
PQclear (res );
877
895
ereport (ERROR ,
878
- (errmsg ("could not create replication slot \"%s\": %s" ,
896
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
897
+ errmsg ("could not create replication slot \"%s\": %s" ,
879
898
slotname , pchomp (PQerrorMessage (conn -> streamConn )))));
880
899
}
881
900
@@ -920,7 +939,8 @@ libpqrcv_processTuples(PGresult *pgres, WalRcvExecResult *walres,
920
939
/* Make sure we got expected number of fields. */
921
940
if (nfields != nRetTypes )
922
941
ereport (ERROR ,
923
- (errmsg ("invalid query response" ),
942
+ (errcode (ERRCODE_PROTOCOL_VIOLATION ),
943
+ errmsg ("invalid query response" ),
924
944
errdetail ("Expected %d fields, got %d fields." ,
925
945
nRetTypes , nfields )));
926
946
0 commit comments