Skip to content

Commit 710c8f9

Browse files
committed
Omit coloring expected query error message
1 parent f4d9c61 commit 710c8f9

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

scripts/executeQuery.sh

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ set -o errexit -o pipefail
2121
NEO4J_HTTP_PORT=${NEO4J_HTTP_PORT:-"7474"} # Neo4j HTTP API port for executing queries
2222
NEO4J_HTTP_TRANSACTION_ENDPOINT=${NEO4J_HTTP_TRANSACTION_ENDPOINT:-"db/neo4j/tx/commit"} # Neo4j v5: "db/<name>/tx/commit", Neo4j v4: "db/data/transaction/commit"
2323

24+
# Local constants
25+
ERROR_COLOR='\033[0;31m'
26+
NO_COLOR='\033[0m'
27+
2428
# Check if environment variable is set
2529
if [ -z "${NEO4J_INITIAL_PASSWORD}" ]; then
2630
echo "executeQuery requires environment variable NEO4J_INITIAL_PASSWORD to be set first. Use 'export NEO4J_INITIAL_PASSWORD=<your-own-password>'." >&2
@@ -30,13 +34,15 @@ fi
3034
# Input Arguments: Initialize arguments and set default values for optional ones
3135
cypher_query_file_name=""
3236
no_source_reference=false
37+
omit_query_error_highlighting=false
3338
query_parameters=""
3439

3540
# Input Arguments: Function to print usage information
3641
print_usage() {
37-
echo "executeQuery Usage: $0 <filename> [--no-source-reference-column]" >&2
42+
echo "executeQuery Usage: $0 <filename> [--no-source-reference-column] [--omit-query-error-highlighting]" >&2
3843
echo "Options:" >&2
3944
echo " --no-source-reference-column: Exclude the source reference column" >&2
45+
echo " --omit-query-error-highlighting: Log query errors in same color as infos" >&2
4046
}
4147

4248
# Input Arguments: Parse the command-line arguments
@@ -48,6 +54,10 @@ while [[ $# -gt 0 ]]; do
4854
no_source_reference=true
4955
shift
5056
;;
57+
--omit_query_error_highlighting)
58+
omit_query_error_highlighting=true
59+
shift
60+
;;
5161
*)
5262
if [[ -z "${cypher_query_file_name}" ]]; then
5363
# Input Arguments: Read the first unnamed input argument containing the name of the cypher file
@@ -78,6 +88,13 @@ done
7888

7989
#echo "executeQuery: query_parameters: ${query_parameters}"
8090

91+
# Set the color for error messages
92+
error_message_color="${ERROR_COLOR}"
93+
if [ "${omit_query_error_highlighting}" = "true" ] ; then
94+
error_message_color="${NO_COLOR}"
95+
echo "executeQuery: Ommiting error highlighting" >&2
96+
fi
97+
8198
# Read the file that contains the Cypher query
8299
original_cypher_query=$(<"${cypher_query_file_name}")
83100
#echo "executeQuery: Original Query: $original_cypher_query"
@@ -102,21 +119,18 @@ if ! cypher_query_result=$(curl --silent -S --fail-with-body -H Accept:applicati
102119
"http://localhost:${NEO4J_HTTP_PORT}/${NEO4J_HTTP_TRANSACTION_ENDPOINT}" \
103120
-d "${cypher_query_for_api}" 2>&1) ;
104121
then
105-
redColor='\033[0;31m'
106-
noColor='\033[0m'
107-
echo -e "${redColor}${cypher_query_file_name}: ${cypher_query_result}${noColor}" >&2
108-
echo -e "${redColor}Parameters: ${query_parameters}${noColor}" >&2
122+
echo -e "${error_message_color}${cypher_query_file_name}: ${cypher_query_result}${NO_COLOR}" >&2
123+
echo -e "${error_message_color}Parameters: ${query_parameters}${NO_COLOR}" >&2
109124
exit 1
110125
fi
111126
#echo "executeQuery: Cypher Query OK Result: ${cypher_query_result}"
112127

113-
# If there is a error message print it to syserr >&2 in red color
128+
# If there is a error message print it to syserr >&2 in error color
114129
error_message=$( echo "${cypher_query_result}" | jq -r '.errors[0] // empty' )
115-
if [[ -n "${error_message}" ]]; then
116-
redColor='\033[0;31m'
117-
noColor='\033[0m'
118-
echo -e "${redColor}${cypher_query_file_name}: ${error_message}${noColor}" >&2
119-
echo -e "${redColor}Parameters: ${query_parameters}${noColor}" >&2
130+
if [[ -n "${error_message}" ]]; then
131+
# Set the message color to red if the query errors should be highlighted
132+
echo -e "${error_message_color}${cypher_query_file_name}: ${error_message}${NO_COLOR}" >&2
133+
echo -e "${error_message_color}Parameters: ${query_parameters}${NO_COLOR}" >&2
120134
exit 1
121135
fi
122136

scripts/waitForNeo4jHttpFunctions.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ echo "waitForNeo4jHttp: CYPHER_DIR=${CYPHER_DIR}"
2424
# Define functions to execute a Cypher query from within the given file (first and only argument)
2525
source "${SCRIPTS_DIR}/executeQueryFunctions.sh"
2626

27-
queryDatabase() {
28-
execute_cypher "${CYPHER_DIR}/Count_nodes_and_relationships.cypher" "--no-source-reference-column"
27+
testDatabase() {
28+
execute_cypher "${CYPHER_DIR}/Count_nodes_and_relationships.cypher" "--no-source-reference-column" "--omit_query_error_highlighting"
2929
}
3030

3131
isDatabaseQueryable() {
3232
local cypher_elements_query_result
33-
if cypher_elements_query_result=$(queryDatabase);
33+
if cypher_elements_query_result=$(testDatabase);
3434
then
3535
echo "true"
3636
else
@@ -56,7 +56,7 @@ waitUntilDatabaseIsQueryable() {
5656
continue; # query failed -> try again
5757
fi
5858

59-
local queryResult=$(queryDatabase || true)
59+
local queryResult=$(testDatabase || true)
6060
if [[ -n "${queryResult}" ]]; then
6161
echo "waitForNeo4jHttp: Successfully accessed Neo4j HTTP API."
6262
echo "${queryResult}"

0 commit comments

Comments
 (0)