Skip to content

Add validation for required files and environment variables #18

@slifty

Description

@slifty

Problem

Scripts use environment variables and assume files exist without validation, leading to cryptic failures or undefined behavior.

Specific Issues

  1. No check that .env exists and is properly sourced before using variables
  2. bootstrap.sh doesn't verify that local/config.json exists
  3. ssh/install.sh uses $USER_EMAIL without checking if it's set
  4. macos/install.sh uses $DEVICE_NAME without validation
  5. macos/install.sh:156,159 uses node and envsubst without checking if they're installed

Impact

  • Confusing error messages when required setup steps are skipped
  • Variables evaluate to empty strings, causing weird behavior
  • Hard to diagnose what went wrong
  • Poor user experience for first-time setup

Recommended Solution

1. Create a validation function in bootstrap.sh

validate_environment() {
  local errors=0
  
  if [ ! -f ".env" ]; then
    fail ".env file not found. Copy .env.template and fill in your details."
    errors=$((errors + 1))
  fi
  
  if [ ! -f "local/config.json" ]; then
    fail "local/config.json not found. Copy local/config.json.example and configure."
    errors=$((errors + 1))
  fi
  
  source .env
  
  if [ -z "$USER_EMAIL" ]; then
    fail "USER_EMAIL not set in .env"
    errors=$((errors + 1))
  fi
  
  if [ -z "$DEVICE_NAME" ]; then
    fail "DEVICE_NAME not set in .env"
    errors=$((errors + 1))
  fi
  
  if [ $errors -gt 0 ]; then
    exit 1
  fi
}

2. Add tool checks before use

# Before using node
if ! command -v node &> /dev/null; then
  fail "node is required but not installed"
fi

3. Run validation early in bootstrap

Call validate_environment before any other operations.

Success Criteria

  • Clear error messages when required files are missing
  • Early failure with helpful guidance
  • Validation before any system changes
  • All environment variables validated before use

Priority

MEDIUM - Significantly improves user experience

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions