# Portainer U+200E Error - Quick Fix Guide

## ✅ AUTOMATIC FIX NOW AVAILABLE

**Good News!** Starting from the latest version, the container automatically sanitizes environment variables on startup, removing invisible Unicode characters like U+200E. This means the error should no longer occur even if you copy-paste variable names in Portainer.

However, if you're still experiencing issues or using an older image, follow the manual fixes below.

## The Error

```
Failed to deploy a stack: unable to get the environment from the env file: 
failed to read /data/compose/42/stack.env: line 8: unexpected character "\u200e" 
in variable name "ADMIN_USER\u200e=user"
```

## What Causes This?

Invisible Unicode characters (like U+200E "Left-to-Right Mark") get copied into your environment variable names or values. You can't see them, but they break Docker/Portainer's env file parser.

Common sources:
- ✗ Copy-pasting from web browsers
- ✗ Copy-pasting from PDFs
- ✗ Copy-pasting from Word/rich text editors
- ✗ Copy-pasting from some IDEs with formatting

## Quick Fix (5 minutes)

### Option 0: Rebuild/Update Your Container (Recommended)

If you're using an older version of the image, pull/rebuild to get the automatic sanitization:

```bash
# Pull latest image
docker pull your-registry/shopify-ai-builder:latest

# Or rebuild locally
cd shopify-ai
docker compose build

# Redeploy in Portainer
```

The new version automatically removes invisible Unicode characters on startup!

### Option 1: Retype in Portainer (Manual Fix)

1. Go to your stack in Portainer
2. Click on the stack → Editor
3. Scroll to environment variables section
4. **Delete ALL environment variables**
5. **Manually type** each variable (don't paste):
   ```
   ADMIN_USER=admin
   ADMIN_PASSWORD=yourpassword
   OPENROUTER_API_KEY=yourkey
   ```
6. Save and redeploy

### Option 2: Use Clean Template

1. Download fresh [.env.example](https://raw.githubusercontent.com/southseact-3d/shopify-ai/main/.env.example)
2. Open in **plain text editor** (Notepad++, VS Code, Sublime, nano, vim - NOT Word!)
3. Fill in your values by typing (not pasting)
4. Copy the clean values to Portainer
5. Deploy

### Option 3: Clean Existing File

If you have an existing .env file:

```bash
# 1. Validate it has problems
./scripts/validate-env.sh .env

# 2. Clean it
./scripts/clean-env.sh .env

# 3. Verify it's fixed
./scripts/validate-env.sh .env

# 4. Use the cleaned file
```

## Prevention

**Always manually type environment variable names** in Portainer's web UI. Only copy-paste the values (API keys, passwords) and only from plain text sources.

### Safe to copy from:
- ✓ Plain text files (.txt, .env opened in plain editor)
- ✓ Terminal output
- ✓ Password managers (usually)
- ✓ Code editors (VS Code, Sublime, vim, nano)

### Unsafe to copy from:
- ✗ Web browsers (especially formatted text)
- ✗ Microsoft Word or Google Docs
- ✗ PDFs
- ✗ Some markdown renderers
- ✗ Slack/Discord (sometimes)

## Verify Your Fix

After fixing, your stack should deploy successfully. Verify:

```bash
# Check container is running
docker ps | grep shopify-ai-builder

# Test the service
curl http://localhost:4000
```

You should see the Shopify AI App Builder homepage.

## Still Having Issues?

See the full guide: [PORTAINER.md](PORTAINER.md)

## Technical Details

The U+200E character is encoded as `E2 80 8E` in UTF-8. Bash/sh can't parse it in variable names:

```bash
# This fails:
ADMIN_USER‎=test    # Contains invisible U+200E after R

# This works:
ADMIN_USER=test     # Clean ASCII
```

Docker Compose `.env` file format requires pure ASCII variable names. Any Unicode characters cause parsing errors.
