diff --git a/src/backend/distributed/master/master_citus_tools.c b/src/backend/distributed/master/master_citus_tools.c index 3ccc56aa1..139ede690 100644 --- a/src/backend/distributed/master/master_citus_tools.c +++ b/src/backend/distributed/master/master_citus_tools.c @@ -435,19 +435,22 @@ static void StoreErrorMessage(PGconn *connection, StringInfo queryResultString) { char *errorMessage = PQerrorMessage(connection); - char *firstNewlineIndex = strchr(errorMessage, '\n'); - - /* trim the error message at the line break */ - if (firstNewlineIndex != NULL) - { - *firstNewlineIndex = '\0'; - } /* put a default error message if no error message is reported */ if (errorMessage == NULL) { errorMessage = "An error occurred while running the query"; } + else + { + char *firstNewlineIndex = strchr(errorMessage, '\n'); + + /* trim the error message at the line break */ + if (firstNewlineIndex != NULL) + { + *firstNewlineIndex = '\0'; + } + } appendStringInfo(queryResultString, "%s", errorMessage); }