-
Notifications
You must be signed in to change notification settings - Fork 17
fix: prevent endless loop with invalid device configurations #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
When all configured devices had invalid/unknown device types, the system would enter an endless loop because getPollingInterval() attempted to reduce an empty array, resulting in undefined being passed to setInterval(). Changes: - Add validation in DeviceManager constructor to fail fast when no valid devices are configured - Add safety check in getPollingInterval() to throw clear error - Add error handling in setupPeriodicPolling() to gracefully handle the failure case - Improve error logging to display actual error messages instead of [object Object] - Add tests for invalid device type scenarios This ensures the application exits immediately with a helpful error message rather than consuming CPU resources in an endless loop.
WalkthroughThis PR adds validation to DeviceManager to detect when no configured devices have recognized device types and implements graceful error handling. The application now throws an error during initialization if all devices are invalid, and error logging is improved across multiple files. Changes
Sequence Diagram(s)sequenceDiagram
participant App as Application
participant DM as DeviceManager
participant MC as MqttClient
rect rgb(240, 248, 255)
note over App,MC: New Validation Flow
App->>DM: constructor(devices)
activate DM
DM->>DM: Count valid devices
alt No valid devices
DM-->>App: throw Error
App->>App: Catch & log error
App->>App: Exit with code 1
else At least one valid device
DM-->>App: Success
end
deactivate DM
App->>MC: setupPeriodicPolling()
activate MC
MC->>DM: getPollingInterval()
activate DM
alt No valid polling interval
DM-->>MC: throw Error
MC->>MC: Catch error & log
MC-->>App: Early exit
else Valid interval found
DM-->>MC: Return interval
MC->>MC: Configure polling
end
deactivate DM
deactivate MC
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (5)
🧰 Additional context used🧬 Code graph analysis (2)src/deviceManager.test.ts (3)
src/deviceManager.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (7)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
When all configured devices had invalid/unknown device types, the system would enter an endless loop because getPollingInterval() attempted to reduce an empty array, resulting in undefined being passed to setInterval().
Changes:
This ensures the application exits immediately with a helpful error message rather than consuming CPU resources in an endless loop.
Summary by CodeRabbit
Bug Fixes
Tests