Troubleshooting
Common issues and solutions for the Rugplay Logger.
Table of contents
- Connection Issues
- Performance Issues
- Export Issues
- TypeScript Issues
- Environment Issues
- Debugging
- Getting Help
Connection Issues
WebSocket Connection Failed
Problem: Cannot connect to the Rugplay WebSocket server.
Symptoms:
โ WebSocket error: Connection failed
๐ Attempting reconnection...
Solutions:
- Check Internet Connection:
# Test basic connectivity ping google.com # Test WebSocket endpoint (if available) curl -v "wss://ws.rugplay.com/" - Verify WebSocket URL:
// Check your configuration const webSocketConfig: WebSocketConfig = { url: 'wss://ws.rugplay.com/', // Ensure this is correct reconnectAttempts: 5, reconnectDelay: 1000 }; - Firewall/Proxy Issues:
- Check if your firewall blocks WebSocket connections
- If behind a corporate proxy, configure proxy settings
- Try from a different network
- Server Status:
- Check if Rugplayโs WebSocket service is operational
- Look for maintenance announcements
Frequent Disconnections
Problem: Connection drops frequently and reconnects.
Symptoms:
โ
Connected successfully
๐ Disconnected from server
๐ Attempting reconnection in 1000ms
Solutions:
- Increase Reconnection Settings:
const webSocketConfig: WebSocketConfig = { url: 'wss://ws.rugplay.com/', reconnectAttempts: 10, // Increase attempts reconnectDelay: 2000 // Increase delay }; - Implement Exponential Backoff:
class RobustClient { private reconnectCount = 0; private getReconnectDelay(): number { return Math.min(1000 * Math.pow(2, this.reconnectCount), 30000); } } - Network Stability:
- Use a stable internet connection
- Consider running on a VPS for better stability
Performance Issues
High Memory Usage
Problem: Application memory usage grows over time.
Symptoms:
- Slow performance after running for hours
- System running out of memory
Solutions:
- Implement Data Cleanup:
class MemoryManager { private trades: any[] = []; private maxEntries = 10000; addTrade(trade: any): void { this.trades.push(trade); // Cleanup old entries if (this.trades.length > this.maxEntries) { this.trades = this.trades.slice(-this.maxEntries / 2); } } } - Use Event Filtering:
// Only process high-value trades client.on('trade', (data) => { if (data.totalValue > 100) { // Filter threshold this.processTrade(data); } }); - Monitor Memory Usage:
setInterval(() => { const usage = process.memoryUsage(); console.log(`Memory: ${Math.round(usage.heapUsed / 1024 / 1024)}MB`); }, 60000); // Log every minute
Slow Event Processing
Problem: Events are processed slowly, causing backlog.
Solutions:
- Optimize Event Handlers:
// Avoid heavy processing in event handlers client.on('trade', (data) => { // Queue for background processing instead this.eventQueue.push(data); }); // Process queue in batches setInterval(() => { this.processEventBatch(); }, 1000); - Use Worker Threads:
import { Worker, isMainThread, parentPort } from 'worker_threads'; if (isMainThread) { // Main thread handles WebSocket const worker = new Worker(__filename); client.on('trade', (data) => { worker.postMessage(data); }); } else { // Worker thread processes data parentPort?.on('message', (data) => { // Heavy processing here }); }
Export Issues
File Export Not Working
Problem: Events are not being saved to files.
Solutions:
- Check Export Configuration:
const exportConfig: ExportConfig = { file: { enabled: true, // Ensure this is true outputPath: './exports/data.json', format: 'json' }, // ... }; - Verify Directory Permissions:
# On Windows mkdir exports # Check if directory is writable echo "test" > exports/test.txt - Check File Path:
import path from 'path'; import fs from 'fs'; const outputDir = path.dirname(exportConfig.file.outputPath); if (!fs.existsSync(outputDir)) { fs.mkdirSync(outputDir, { recursive: true }); }
Discord Export Failing
Problem: Events are not being sent to Discord.
Symptoms:
โ Discord export failed: 401 Unauthorized
โ Discord export failed: Invalid webhook URL
Solutions:
- Verify Webhook URL:
// Test webhook manually const testWebhook = async () => { const response = await fetch(webhookUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ content: 'Test message from Rugplay Logger' }) }); console.log('Webhook test:', response.status); }; - Check Discord Permissions:
- Ensure the webhook URL is correct
- Verify the webhook hasnโt been deleted
- Check if the channel still exists
- Rate Limiting:
class DiscordRateLimiter { private lastSent = 0; private minInterval = 2000; // 2 seconds between messages canSend(): boolean { const now = Date.now(); if (now - this.lastSent >= this.minInterval) { this.lastSent = now; return true; } return false; } }
TypeScript Issues
Build Errors
Problem: TypeScript compilation fails.
Common Errors and Solutions:
- Module Resolution:
// Error: Cannot find module './types/config' // Solution: Check file paths and extensions import { WebSocketConfig } from '../types/config'; // Correct path - Type Errors:
// Error: Property 'coinSymbol' does not exist on type 'any' // Solution: Define proper interfaces interface TradeEvent { coinSymbol: string; username: string; amount: number; // ... other properties } - Missing Dependencies:
# Install missing type definitions npm install --save-dev @types/node @types/ws
Runtime Type Issues
Problem: Runtime errors due to unexpected data types.
Solutions:
- Add Runtime Validation:
function validateTradeEvent(data: any): data is TradeEvent { return ( typeof data.coinSymbol === 'string' && typeof data.username === 'string' && typeof data.amount === 'number' ); } client.on('trade', (data) => { if (validateTradeEvent(data)) { // Safe to use typed data console.log(data.coinSymbol); } else { console.error('Invalid trade data:', data); } }); - Use Type Guards:
function isValidPrice(value: any): value is number { return typeof value === 'number' && !isNaN(value) && value > 0; }
Environment Issues
Node.js Version Problems
Problem: Compatibility issues with Node.js version.
Solutions:
- Check Node.js Version:
node --version # Should be 18.0 or higher - Use Node Version Manager:
# Install nvm (Node Version Manager) # Windows: Download from github.com/coreybutler/nvm-windows # Install and use Node 18 nvm install 18 nvm use 18
Package Installation Issues
Problem: npm install fails or packages are missing.
Solutions:
- Clear npm Cache:
npm cache clean --force rm -rf node_modules package-lock.json npm install - Use Different Registry:
# If default registry is slow/blocked npm install --registry https://registry.npmjs.org/ - Check for Permission Issues:
# On Windows, run as administrator if needed # On Unix systems, avoid using sudo with npm
Debugging
Enable Debug Mode
const client = new RugplayClient({
config: webSocketConfig,
exportConfig: exportConfig,
autoConnect: true,
debug: true // Enable debug logging
});
Add Custom Logging
class Logger {
static debug(message: string, data?: any): void {
if (process.env.DEBUG_MODE === 'true') {
console.log(`[DEBUG] ${new Date().toISOString()} - ${message}`, data || '');
}
}
static error(message: string, error?: any): void {
console.error(`[ERROR] ${new Date().toISOString()} - ${message}`, error || '');
}
}
// Usage
Logger.debug('Processing trade event', tradeData);
Logger.error('Failed to export data', error);
Monitor WebSocket Messages
client.on('message', (rawData) => {
console.log('Raw WebSocket message:', rawData);
});
Performance Monitoring
class PerformanceMonitor {
private eventCounts = new Map<string, number>();
private startTime = Date.now();
track(eventType: string): void {
const count = this.eventCounts.get(eventType) || 0;
this.eventCounts.set(eventType, count + 1);
}
report(): void {
const uptime = Date.now() - this.startTime;
console.log(`Uptime: ${Math.round(uptime / 1000)}s`);
this.eventCounts.forEach((count, event) => {
const rate = (count / uptime) * 1000;
console.log(`${event}: ${count} events (${rate.toFixed(2)}/s)`);
});
}
}
Getting Help
If you canโt resolve your issue:
- Check GitHub Issues: Search for similar problems and solutions
- Enable Debug Mode: Gather detailed logs before reporting
- Provide Environment Info: Include Node.js version, OS, and error messages
- Create Minimal Reproduction: Simplify your code to isolate the issue
Issue Template
When reporting bugs, include:
**Environment:**
- OS: Windows 11 / macOS / Linux
- Node.js version: 18.17.0
- Package version: 1.0.0
**Configuration:**
```yaml
# Your configuration here
Error Message:
Paste full error message and stack trace
Steps to Reproduce:
- Step one
- Step two
- โฆ
Expected Behavior: What you expected to happen
Actual Behavior: What actually happened ```