Debugging Guide

Comprehensive guide for debugging LuaBeans - Community Manager issues.

Debug Mode

Enable debug mode in development:

NODE_ENV=development

This will:

  • Show detailed error messages

  • Enable verbose logging

  • Disable production optimizations

Logging

Application Logs

Application logs are output to the console (stdout/stderr). In production, redirect these to log files:

node src/server.js >> /var/log/luabeans/app.log 2>&1

Log Levels

  • Info: Normal operation messages

  • Warn: Warning messages (non-critical issues)

  • Error: Error messages (critical issues)

Common Log Messages

Startup:

Database Connection:

Discord Bot:

Database Debugging

Check Database Connection

View Table Structure

Check Table Exists

View Data

Check Indexes

View Foreign Key Constraints

Common Database Issues

Connection Refused:

  • Check MySQL is running: sudo systemctl status mysql

  • Verify credentials in .env

  • Check firewall rules

Table Doesn't Exist:

  • Run schema: mysql -u user -p database < db/schema.sql

  • Or let Sequelize auto-create on boot

Foreign Key Constraint Violations:

  • Check referenced records exist

  • Verify constraint definitions in schema

Discord Debugging

OAuth2 Issues

Error: Invalid Redirect URI

  1. Verify DISCORD_CALLBACK_URL matches exactly in Discord Developer Portal

  2. Check for trailing slashes

  3. Verify protocol (http vs https)

Error: Not in Guild

  1. Verify DISCORD_GUILD_ID is correct

  2. Check user is actually in the Discord server

  3. Verify bot has permissions to read members

Error: OAuth2 Application Not Found

  1. Verify DISCORD_CLIENT_ID and DISCORD_CLIENT_SECRET are correct

  2. Check Discord application still exists

  3. Verify application hasn't been deleted

Bot Issues

Bot Not Responding:

  1. Check bot is running: npm run bot

  2. Verify DISCORD_BOT_TOKEN is correct

  3. Check bot has required intents:

    • Guilds

    • Guild Members

    • Guild Messages

    • Message Content

Commands Not Appearing:

  1. Wait 1 hour for global commands to propagate

  2. Or set DISCORD_BOT_PUBLIC_COMMANDS=false for instant guild commands

  3. Redeploy commands: npm run bot:deploy

Rate Limiting:

  • Check logs for rate limit warnings

  • Bot automatically handles rate limits with retries

  • Consider reducing command frequency

Discord API Testing

Test Discord API manually:

Session Debugging

Check Session Store

Clear All Sessions

Session Issues

Sessions Not Persisting:

  • Verify session table exists

  • Check SESSION_SECRET is set

  • Verify database connection

Session Expired Too Quickly:

  • Check session expiration settings (default: 7 days)

  • Verify server time is correct (NTP sync)

CSRF Token Errors:

  • Clear browser cookies

  • Check TRUST_PROXY is set correctly if behind proxy

  • Verify session is working

Permission Debugging

Check User Permissions

Check Department Access

Permission Cache

Permissions are cached. To refresh:

  • User: Dashboard → "Refresh roles" button

  • Admin: Admin → "Refresh roles for all users" (background job)

FiveM Integration Debugging

API Token Issues

Error: Invalid Token

  1. Verify LEO_API_TOKEN matches between web panel and FiveM resource

  2. Check token is sent in Authorization header: Bearer <token>

  3. Verify token hasn't expired or been changed

Error: Unauthorized

  1. Check API endpoint is protected with LEO_API_TOKEN

  2. Verify token format is correct

  3. Check request includes Authorization header

FiveM Resource Issues

Resource Not Starting:

  1. Check convars are set correctly:

  2. Verify API endpoint is accessible from FiveM server

  3. Check resource console for errors

API Calls Failing:

  1. Test API endpoint manually:

  2. Check FiveM server can reach your web panel

  3. Verify SSL certificate is valid (if using HTTPS)

Discord Identifier Issues

Error: No Discord Identifier

  1. Verify player has discord: identifier in FiveM

  2. Check player identifiers: GetPlayerIdentifiers(source)

  3. Ensure Discord identifier is in format: discord:123456789012345678

File Upload Debugging

Upload Directory Issues

Error: Cannot Write to Upload Directory

  1. Check UPLOAD_DIR exists: ls -la ./uploads

  2. Verify write permissions: chmod 755 ./uploads

  3. Check disk space: df -h

Error: File Too Large

  1. Check MAX_FILE_SIZE in .env (default: 100MB)

  2. Verify proxy allows upload size (Nginx: client_max_body_size)

  3. Check Cloudflare upload limits

Upload Processing Issues

Uploads Not Saving:

  1. Check file system permissions

  2. Verify UPLOAD_DIR path is correct (absolute vs relative)

  3. Check disk space availability

Performance Debugging

Slow Queries

Enable query logging in MySQL:

View slow queries:

Memory Issues

Monitor Node.js memory:

Database Connection Pool

Check active connections:

Network Debugging

Check Port Availability

Test HTTP Endpoints

Proxy Issues

Error: Trust Proxy Not Working

  1. Set TRUST_PROXY=true in .env

  2. Verify proxy sends X-Forwarded-Proto header

  3. Check X-Forwarded-For header format

Error: HTTPS Redirect Loop

  1. Verify TRUST_PROXY=true is set

  2. Check proxy sends X-Forwarded-Proto: https

  3. Verify FORCE_HTTPS=true only in production

Common Error Messages

Database Errors

Error: Connection refused

  • MySQL is not running

  • Wrong host/port

  • Firewall blocking connection

Error: Access denied

  • Wrong username/password

  • User doesn't have permissions

Error: Unknown database

  • Database doesn't exist

  • Wrong database name in .env

Discord Errors

Error: Invalid OAuth2 redirect_uri

  • Callback URL mismatch

  • URL not registered in Discord portal

Error: Invalid client secret

  • Wrong client secret

  • Application deleted or regenerated

Error: Missing Permissions

  • Bot doesn't have required permissions

  • Bot not in server

Application Errors

Error: EBADCSRFTOKEN

  • CSRF token mismatch

  • Session expired

  • Cookie issues

Error: EADDRINUSE

  • Port already in use

  • Another instance running

Debug Tools

Health Endpoints

  • /healthz - Always 200 (process alive)

  • /readyz - 200 only if database connected

  • /metrics - Performance metrics (if enabled)

Admin Diagnostics

Navigate to /admin/diagnostics for:

  • System health check

  • Database connection status

  • Discord connection status

  • Configuration validation

Getting Help

If you're still experiencing issues:

  1. Check application logs

  2. Review database logs

  3. Test with minimal configuration

  4. Contact support with:

    • Error message

    • Relevant log excerpts

    • Configuration (sanitized)

    • Steps to reproduce

Last updated