@@ -21,6 +21,10 @@ set -o errexit -o pipefail
2121NEO4J_HTTP_PORT=${NEO4J_HTTP_PORT:- " 7474" } # Neo4j HTTP API port for executing queries
2222NEO4J_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
2529if [ -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
3034# Input Arguments: Initialize arguments and set default values for optional ones
3135cypher_query_file_name=" "
3236no_source_reference=false
37+ omit_query_error_highlighting=false
3338query_parameters=" "
3439
3540# Input Arguments: Function to print usage information
3641print_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
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
8299original_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 ) ;
104121then
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
110125fi
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
114129error_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
121135fi
122136
0 commit comments