normogen/backend/MAIN-RS-DEBUG-FIX.md

1.3 KiB

Backend Silent Crash - Fixed

Problem

The backend container was starting, compiling, and then exiting immediately with NO output.

Root Cause

The application was failing (likely at config loading or MongoDB connection), but:

  1. dotenv::dotenv() was failing silently (no .env in Docker)
  2. Errors were only going to the logger (which wasn't initialized yet)
  3. No output to confirm the binary was even running

Solution Applied

Added eprintln! statements throughout main.rs to:

  • Confirm the binary is starting
  • Show each initialization step
  • Display errors immediately (not just in logs)
  • Debug configuration loading

Changes Made

  • src/main.rs: Added debug eprintln statements at each step
  • Removed ok() from config loading to surface errors
  • Better error handling with match statements

Test

Now when you restart the container, you'll see:

NORMOGEN BACKEND STARTING...
Loading environment variables...
No .env file found (this is OK in Docker): ...
Initializing logging...
Config loaded: DB=normogen_dev, Port=8000
Connecting to MongoDB...
MongoDB connection successful
Server is running on http://0.0.0.0:8000

Next Steps

Restart the container and check the logs:

docker compose -f backend/docker-compose.dev.yml restart backend
docker logs normogen-backend-dev -f