From 69b7244723e4bb9472f53147ea035b1b37fc1f40 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Mon, 26 Jan 2026 11:04:44 -0800 Subject: [PATCH 1/2] feat: Add a check for monogodb uri corruption --- on-prem/.env.example | 1 + on-prem/scripts/check-env.sh | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/on-prem/.env.example b/on-prem/.env.example index 8db0054..8752c61 100644 --- a/on-prem/.env.example +++ b/on-prem/.env.example @@ -82,6 +82,7 @@ CLICKHOUSE_USERNAME=currents # MongoDB MONGODB_USERNAME=currents-user MONGODB_DATABASE=currents +# NOTE: Long line - if editing in nano, use `nano -w .env` to prevent line wrapping MONGODB_URI=mongodb://${MONGODB_USERNAME}:${MONGODB_PASSWORD}@mongodb:27017/${MONGODB_DATABASE}?authSource=admin&replicaSet=rs0 # Domain configuration for Traefik routing diff --git a/on-prem/scripts/check-env.sh b/on-prem/scripts/check-env.sh index c0c5b57..74b8006 100755 --- a/on-prem/scripts/check-env.sh +++ b/on-prem/scripts/check-env.sh @@ -58,6 +58,43 @@ while IFS= read -r line || [ -n "$line" ]; do fi done < "$EXAMPLE_FILE" +# ============================================================================= +# Check for corrupted values (e.g., line wrapping from terminal editors) +# ============================================================================= +CORRUPTED=() + +# Check MONGODB_URI for spaces (indicates line wrapping corruption) +if grep -q "^MONGODB_URI=" "$ENV_FILE"; then + mongodb_uri=$(grep "^MONGODB_URI=" "$ENV_FILE" | cut -d'=' -f2-) + if [[ "$mongodb_uri" =~ [[:space:]] ]]; then + CORRUPTED+=("MONGODB_URI contains spaces - likely corrupted by editor line wrapping") + fi + # Check if it looks like it was split across lines (missing expected parts) + if [[ ! "$mongodb_uri" =~ "mongodb://" ]] || [[ ! "$mongodb_uri" =~ "@" ]]; then + CORRUPTED+=("MONGODB_URI appears incomplete - may have been split by line wrapping") + fi +fi + +# Check for orphan lines that look like continuation of MONGODB_URI +if grep -qE "^(authSource|replicaSet|mongodb:|27017)" "$ENV_FILE"; then + CORRUPTED+=("Found orphan lines that may be fragments of a wrapped MONGODB_URI") +fi + +if [ ${#CORRUPTED[@]} -gt 0 ]; then + echo -e "${RED}Corrupted values detected:${NC}" + for msg in "${CORRUPTED[@]}"; do + echo -e " ${RED}!${NC} $msg" + done + echo "" + echo -e "${YELLOW}This usually happens when editing .env with a terminal editor that wraps long lines.${NC}" + echo "To fix:" + echo " 1. Delete the corrupted lines from .env" + echo " 2. Re-edit using: nano -w .env (the -w flag disables line wrapping)" + echo " 3. Or copy the original from .env.example: grep 'MONGODB_URI' .env.example" + echo "" + exit 1 +fi + if [ ${#MISSING[@]} -eq 0 ] && [ ${#COMMENTED[@]} -eq 0 ]; then echo -e "${GREEN}All environment variables are present in .env${NC}" exit 0 From 62bb202a2156b4a801125aec9f672916438a64c3 Mon Sep 17 00:00:00 2001 From: DJ Mountney Date: Mon, 26 Jan 2026 11:41:19 -0800 Subject: [PATCH 2/2] Update on-prem/scripts/check-env.sh Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- on-prem/scripts/check-env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/on-prem/scripts/check-env.sh b/on-prem/scripts/check-env.sh index 74b8006..c335f57 100755 --- a/on-prem/scripts/check-env.sh +++ b/on-prem/scripts/check-env.sh @@ -70,7 +70,7 @@ if grep -q "^MONGODB_URI=" "$ENV_FILE"; then CORRUPTED+=("MONGODB_URI contains spaces - likely corrupted by editor line wrapping") fi # Check if it looks like it was split across lines (missing expected parts) - if [[ ! "$mongodb_uri" =~ "mongodb://" ]] || [[ ! "$mongodb_uri" =~ "@" ]]; then + if [[ ! "$mongodb_uri" =~ ^mongodb(\+srv)?:\/\/ ]] || [[ ! "$mongodb_uri" =~ "@" ]]; then CORRUPTED+=("MONGODB_URI appears incomplete - may have been split by line wrapping") fi fi