You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix "Cannot set properties of undefined" error in validated() method when credentials are missing (#170)
This PR fixes a critical issue where the plugin would crash with `Cannot
set properties of undefined (setting 'installId')` when the homebridge
config file didn't have a properly initialized `credentials` object for
the August platform.
## Problem
The error occurred in the `validated()` method when trying to set
properties on `pluginConfig.credentials`:
```typescript
pluginConfig.credentials.installId = this.config.credentials?.installId
```
This happened because:
1. When `credentials` was completely missing from the config file, it
would be `undefined`
2. When `credentials` was explicitly set to `null`, the existing check
`typeof pluginConfig.credentials !== 'object'` would pass (since `typeof
null === 'object'` in JavaScript), but then trying to set properties on
`null` would fail
## Solution
Updated the `pluginConfig()` method to properly handle both `null` and
`undefined` credentials:
```typescript
// Before: Only checked for non-object types
if (typeof pluginConfig.credentials !== 'object') {
throw new TypeError('pluginConfig.credentials is not an object')
}
// After: Explicitly check for null and undefined, then initialize
if (typeof pluginConfig.credentials !== 'object' || pluginConfig.credentials === null) {
pluginConfig.credentials = {}
}
```
Now when the `validated()` method runs, it can safely set properties on
`pluginConfig.credentials` because the object is guaranteed to exist.
## Testing
Added comprehensive tests to verify:
- Undefined credentials in config file are handled gracefully
- Null credentials in config file are handled gracefully
- The credentials object is properly initialized and the installId is
saved
All existing tests continue to pass, ensuring no regressions.
Fixes#169.
<!-- START COPILOT CODING AGENT TIPS -->
---
✨ Let Copilot coding agent [set things up for
you](https://github.com/homebridge-plugins/homebridge-august/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot)
— coding agent works faster and does higher quality work when set up for
your repo.
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Donavan Becker <[email protected]>
Co-authored-by: donavanbecker <[email protected]>
0 commit comments