Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 3, 2025

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:

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:

// 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.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@donavanbecker donavanbecker changed the base branch from latest to beta-3.0.3 September 3, 2025 15:33
@donavanbecker donavanbecker marked this pull request as ready for review September 3, 2025 15:34
@Copilot Copilot AI changed the title [WIP] Validate: Cannot set properties of undefined (setting 'installId') Fix "Cannot set properties of undefined" error in validated() method when credentials are missing Sep 3, 2025
@Copilot Copilot AI requested a review from donavanbecker September 3, 2025 15:41
Copilot finished work on behalf of donavanbecker September 3, 2025 15:41
@github-actions github-actions bot added enhancement New feature or request beta labels Sep 3, 2025
@donavanbecker donavanbecker merged commit 9e47ae6 into beta-3.0.3 Sep 3, 2025
14 checks passed
@donavanbecker donavanbecker deleted the copilot/fix-169 branch September 3, 2025 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validate: Cannot set properties of undefined (setting 'installId')
2 participants